Skip to content

Use the authen object user id and remove hidden input ids. - #3264

Open
drgrice1 wants to merge 3 commits into
openwebwork:developfrom
drgrice1:remove-hidden-field-ids
Open

drgrice1 wants to merge 3 commits into
openwebwork:developfrom
drgrice1:remove-hidden-field-ids

Conversation

@drgrice1

Copy link
Copy Markdown
Member

The user id is cached in $c->authen->{user_id} during authentication, so use that everywhere the user id was obtained from the user param after authentication. As a result the user hidden field is no longer needed in forms when session_management_via is "session_cookie", and so hidden_authen_fields now only adds it when session_management_via is "key".

Note that several places (the render rpc, hardcopy of rendered problems, and the course and set API actions) used $c->req->param or $c->req->params which only see the raw request parameters, and so those depended on the user hidden field being submitted.

The problem grader and library browser javascript that used the user input to construct local storage keys now get the user id from a data attribute or hidden input that is always present.

Remove the id attribute from inputs created by hidden_fields. Hidden inputs do not need an id, and no javascript looks these inputs up by id anymore (they are looked up by name). So the id attribute is no longer set, and the id_prefix option of hidden_fields and the corresponding argument of hidden_authen_fields that existed only to avoid duplicate ids were removed.

This fixes and removes the FIXME on line 984 of lib/WeBWorK/ContentGenerator.pm that I added a few years ago.

There was also a regular expression hack in the output_past_answer_button method of the WeBWorK::ContentGenerator::Problem package that renamed the ids for much the same purpose. That is also not needed anymore and was removed.

Remove the force_passwd_authen hidden input. This input is added in templates/ContentGenerator/Logout.html.ep, and is prevented from being carried forward on certain form submissions. However, it is never actually used for anything, and so is dead code.

Note that this also fixes the issue pointed out in #3174 among other things.

@drgrice1
drgrice1 force-pushed the remove-hidden-field-ids branch from c6a029f to d042ed8 Compare October 29, 2026 20:04
drgrice1 and others added 3 commits October 30, 2026 15:35
This input is added in `templates/ContentGenerator/Logout.html.ep`, and
is prevented from being carried forward on certain form submissions.
However, it is never actually used for anything, and so is dead code.
Hidden inputs do not need an id, and no javascript looks these inputs up
by id anymore (they are looked up by name). So the id attribute is no
longer set, and the `id_prefix` option of `hidden_fields` and the
corresponding argument of `hidden_authen_fields` that existed only to
avoid duplicate ids were removed.

This fixes and removes the FIXME on line 984 of `lib/WeBWorK/ContentGenerator.pm`
that I added a few years ago.

There was also a regular expression hack in the `output_past_answer_button`
method of the `WeBWorK::ContentGenerator::Problem` package that renamed
the ids for much the same purpose.  That is also not needed anymore and
was removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The user id is cached in `$c->authen->{user_id}` during authentication,
so use that everywhere the user id was obtained from the `user` param
after authentication. As a result the `user` hidden field is no longer
needed in forms when `session_management_via` is "session_cookie", and
so `hidden_authen_fields` now only adds it when `session_management_via`
is "key".

Note that several places (the render rpc, hardcopy of rendered
problems, and the course and set API actions) used `$c->req->param` or
`$c->req->params` which only see the raw request parameters, and so
those depended on the `user` hidden field being submitted.

The problem grader and library browser javascript that used the `user`
input to construct local storage keys now get the user id from a data
attribute or hidden input that is always present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@drgrice1
drgrice1 force-pushed the remove-hidden-field-ids branch from d042ed8 to 82bf8bc Compare October 30, 2026 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant