Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to manage their first/last name from Account Settings #2526

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/defaults.config
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ $authen{admin_module} = ['WeBWorK::Authen::Basic_TheLastOption'];
use_two_factor_auth => "student",
report_bugs => "ta",
submit_feedback => "student",
change_name => "student",
change_password => "student",
change_email_address => "student",
change_pg_display_settings => "student",
Expand Down
25 changes: 20 additions & 5 deletions lib/WeBWorK/ConfigValues.pm
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,19 @@ sub getConfigValues ($ce) {
),
type => 'permission'
},
{
var => 'permissionLevels{change_name}',
doc => x('Allowed to change their name'),
doc2 => x(
'Users at this level and higher are allowed to change their first and last name. '
. 'Note that if WeBWorK is used with an LMS, it may be configured to allow the LMS to '
. 'manage user data such as user names. Then if a user changes their name in WeBWorK, '
. 'the LMS might override that later. This course might be configured to allow you to '
. 'control whether or not the LMS is allowed to manage user date in the LTI tab of the '
. 'Course Configuration page.'
),
type => 'permission'
},
{
var => 'permissionLevels{change_email_address}',
doc => x('Allowed to change their email address'),
Expand Down Expand Up @@ -922,11 +935,13 @@ sub getConfigValues ($ce) {
var => 'LMSManageUserData',
doc => x('Allow the LMS to update user account data'),
doc2 => x(
'WeBWorK will automatically create users when logging in via the LMS for the first time. If '
. 'this flag is enabled then it will also keep the user account data (first name, last '
. 'name, section, recitation) up to date with the LMS. If a user\'s information changes '
. 'in the LMS then it will change in WeBWorK. However, any changes to the user data via '
. 'WeBWorK will be overwritten the next time the user logs in.'
'If this is set to true, then when a user enters WeBWorK using LTI from an LMS, their user account '
. 'data in WeBWorK will be updated to match the data from the LMS. This applies to first name, '
. 'last name, section, recitation, and email address. If a user\'s information changes in the LMS '
. 'then it will change in WeBWorK the next time the user enters WeBWorK from the LMS. Any changes '
. 'to the user data that are made in WeBWorK will be overwritten. So if this is set to true, you '
. 'may want to review the settings in the Permissions tab for who is allowed to change their own '
. 'name and email address.'
),
type => 'boolean'
},
Expand Down
36 changes: 36 additions & 0 deletions lib/WeBWorK/ContentGenerator/Options.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ WeBWorK::ContentGenerator::Options - Change user options.
use WeBWorK::Utils qw(cryptPassword);
use WeBWorK::Localize;

sub page_title ($c) {
return $c->maketext("Account settings for [_1]", $c->param('effectiveUser'));
}

sub initialize ($c) {
my $db = $c->db;
my $authz = $c->authz;
Expand Down Expand Up @@ -105,6 +109,38 @@ sub initialize ($c) {
$c->{has_password} = defined $password;
}

my $newFN = $c->param('newFirstName');
if ($changeOptions && $authz->hasPermissions($userID, 'change_name') && $newFN) {
my $oldFN = $c->{effectiveUser}->first_name;
$c->{effectiveUser}->first_name($newFN);
eval { $db->putUser($c->{effectiveUser}) };
if ($@) {
$c->{effectiveUser}->first_name($oldFN);
$c->log->error("Unable to save new first name for $userID: $@");
$c->addbadmessage($c->maketext('Your first name has not been changed due to an internal error.'));
} else {
$c->param('currFirstName', $c->param('newFirstName'));
$c->param('newFirstName', undef);
$c->addgoodmessage($c->maketext('Your first name has been changed.'));
}
}

my $newLN = $c->param('newLastName');
if ($changeOptions && $authz->hasPermissions($userID, 'change_name') && $newLN) {
my $oldLN = $c->{effectiveUser}->last_name;
$c->{effectiveUser}->last_name($newLN);
eval { $db->putUser($c->{effectiveUser}) };
if ($@) {
$c->{effectiveUser}->last_name($oldLN);
$c->log->error("Unable to save new last name for $userID: $@");
$c->addbadmessage($c->maketext('Your last name has not been changed due to an internal error.'));
} else {
$c->param('currLastName', $c->param('newLastName'));
$c->param('newLastName', undef);
$c->addgoodmessage($c->maketext('Your last name has been changed.'));
}
}

my $newA = $c->param('newAddress');
if ($changeOptions && $authz->hasPermissions($userID, 'change_email_address') && $newA) {
my $oldA = $c->{effectiveUser}->email_address;
Expand Down
1 change: 1 addition & 0 deletions templates/ContentGenerator/Base/links.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
% }
%
% if ($authz->hasPermissions($userID, 'change_password')
% || $authz->hasPermissions($userID, 'change_name')
% || $authz->hasPermissions($userID, 'change_email_address')
% || $authz->hasPermissions($userID, 'change_pg_display_settings'))
% {
Expand Down
61 changes: 50 additions & 11 deletions templates/ContentGenerator/Options.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,56 @@
%= form_for current_route, method => 'POST', begin
<%= $c->hidden_authen_fields =%>
%
% if ($authz->hasPermissions($userID, 'change_name')) {
<h2><%= maketext('Name') %></h2>
<div class="row mb-2">
<div class="col-lg-8 col-md-10">
<div class="row mb-2">
<%= label_for currFirstName => maketext("Current First Name"),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= text_field currFirstName => $c->{effectiveUser}->first_name, readonly => undef,
id => 'currFirstName', class => 'form-control bg-light', dir => 'ltr' =%>
</div>
</div>
<div class="row mb-2">
<%= label_for currLastName => maketext("Current Last Name"),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= text_field currLastName => $c->{effectiveUser}->last_name, readonly => undef,
id => 'currLastName', class => 'form-control bg-light', dir => 'ltr' =%>
</div>
</div>
<div class="row mb-2">
<%= label_for newFirstName => maketext("New First Name"),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= text_field newFirstName => '', id => 'newFirstName', class => 'form-control', dir => 'ltr' =%>
</div>
</div>
<div class="row mb-2">
<%= label_for newLastName => maketext("New Last Name"),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= text_field newLastName => '', id => 'newLastName', class => 'form-control', dir => 'ltr' =%>
</div>
</div>
</div>
</div>
% }
%
% if ($authz->hasPermissions($userID, 'change_password')) {
<h2><%= maketext('Change Password') %></h2>
<h2><%= maketext('Password') %></h2>
<div class="row mb-2">
<div class="col-lg-8 col-md-10">
<div class="row mb-2">
<%= label_for 'currPassword', class => 'col-form-label col-sm-6', begin =%>
<%= maketext(
q{[_1]'s Current Password},
$c->{user}->first_name . ' ' . $c->{user}->last_name
q{[_1]'s Current Password}, $eUserName
) =%>
<% end =%>
<div class="col-sm-6">
Alex-Jordan marked this conversation as resolved.
Show resolved Hide resolved
<%= text_field dummyUsername => '', class => 'd-none' =%>
<%= password_field 'currPassword', id => 'currPassword', class => 'form-control', dir => 'ltr',
$c->{has_password} ? () : (disabled => 1) =%>
</div>
Expand All @@ -38,31 +76,32 @@
<%= label_for newPassword => maketext("[_1]'s New Password", $eUserName),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= password_field 'newPassword', id => 'newPassword', class => 'form-control', dir => 'ltr' =%>
<%= password_field 'newPassword', id => 'newPassword', class => 'form-control',
dir => 'ltr', autocomplete => 'new-password' =%>
</div>
</div>
<div class="row mb-2">
<%= label_for confirmPassword => maketext("Confirm [_1]'s New Password", $eUserName),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= password_field 'confirmPassword', id => 'confirmPassword',
class => 'form-control', dir => 'ltr' =%>
<%= password_field 'confirmPassword', id => 'confirmPassword', class => 'form-control',
dir => 'ltr', autocomplete => 'new-password' =%>
</div>
</div>
</div>
</div>
% }
%
% if ($authz->hasPermissions($userID, 'change_email_address')) {
<h2><%= maketext('Change Email Address') %></h2>
<h2><%= maketext('Email Address') %></h2>
<div class="row mb-2">
<div class="col-lg-8 col-md-10">
<div class="row mb-2">
<%= label_for currAddress => maketext("[_1]'s Current Address", $eUserName),
class => 'col-form-label col-sm-6' =%>
<div class="col-sm-6">
<%= text_field currAddress => $c->{effectiveUser}->email_address,
readonly => undef, id => 'currAddress', class => 'form-control', dir => 'ltr' =%>
<%= text_field currAddress => $c->{effectiveUser}->email_address, readonly => undef,
id => 'currAddress', class => 'form-control bg-light', dir => 'ltr' =%>
</div>
</div>
<div class="row mb-2">
Expand All @@ -77,7 +116,7 @@
% }
%
% if ($authz->hasPermissions($userID, 'change_pg_display_settings')) {
<h2><%= maketext('Change Display Settings') %></h2>
<h2><%= maketext('Display Settings') %></h2>
%
% my $display_settings_block = begin
% my $curr_displayMode = $c->{effectiveUser}->displayMode || $ce->{pg}{options}{displayMode};
Expand Down Expand Up @@ -170,5 +209,5 @@
% }
% }
%
<%= submit_button maketext('Change Account Settings'), name => 'changeOptions', class => 'btn btn-primary' =%>
<%= submit_button maketext('Save Account Settings'), name => 'changeOptions', class => 'btn btn-primary' =%>
% end
8 changes: 8 additions & 0 deletions templates/HelpFiles/Options.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
. 'login_proctor or higher for the permissions to change password, change email address, and change display '
. 'settings used in pg problems.') =%>
</p>
<h2><%= maketext('Name') %></h2>
<p>
<%= maketext('The first and last name can be any combination of letters, numbers and special symbols. Name changes '
. 'and preferences can be respected here. Students should use a name that will not confuse their instructor. '
. 'If WeBWorK is used with an LMS (Canvas, Moodle, D2L, Blackboard, etc) the LMS might periodically override '
. 'a name setting here if WeBWorK is configured to allow that. Name settings will only appear here if a user '
. 'has permission to change their name.') =%>
</p>
<h2><%= maketext('Password') %></h2>
<p>
<%= maketext('The password can be any combination of letters, numbers and special symbols. Students are encouraged '
Expand Down