Skip to content

Commit 2da9613

Browse files
Alex-Jordanclaude
andcommitted
Control force password reset at Add Users page too.
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7d0296e commit 2da9613

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

htdocs/js/AddUsers/add-users.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,25 @@
1313

1414
passwordSelect.addEventListener('change', setPlaceholders);
1515
setPlaceholders();
16+
17+
// Each "force password reset" checkbox starts out unchecked. Automatically check it once a password is typed
18+
// into that row's password field, or once a fallback password source other than "None" is selected (since that
19+
// fallback value will be used as the password for any row left blank). If the instructor manually toggles a
20+
// checkbox, stop overriding that row's checkbox for the rest of the page's lifetime.
21+
const manuallySet = new Set();
22+
for (const autoCheckbox of document.querySelectorAll('input[data-auto-check="password"]')) {
23+
const passwordField = autoCheckbox.closest('tr')?.querySelector('.new_password');
24+
if (!passwordField) continue;
25+
26+
autoCheckbox.addEventListener('change', () => manuallySet.add(autoCheckbox));
27+
28+
const updateCheckbox = () => {
29+
if (!manuallySet.has(autoCheckbox))
30+
autoCheckbox.checked = passwordField.value !== '' || passwordSelect.value !== '';
31+
};
32+
33+
passwordField.addEventListener('input', updateCheckbox);
34+
passwordSelect.addEventListener('change', updateCheckbox);
35+
updateCheckbox();
36+
}
1637
})();

lib/WeBWorK/ContentGenerator/Instructor/AddUsers.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ sub initialize ($c) {
7878
my $newPassword = $db->newPassword;
7979
$newPassword->user_id($new_user_id);
8080
$newPassword->password(cryptPassword($password));
81-
$newPassword->must_reset_password(1);
81+
$newPassword->must_reset_password($c->param("must_reset_$i") ? 1 : 0);
8282
$db->addPassword($newPassword);
8383
}
8484

lib/WeBWorK/ContentGenerator/Instructor/UserList.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ use constant FIELD_PROPERTIES => {
133133
: 0;
134134
}
135135
},
136-
section => { name => x('Section'), type => 'text', attributes => { size => 3 } },
137-
recitation => { name => x('Recitation'), type => 'text', attributes => { size => 3 } },
138-
comment => { name => x('Comment'), type => 'text', attributes => { size => 20 } },
139-
permission => { name => x('Permission Level'), type => 'permission' },
140-
password => { name => x('Password'), type => 'password' },
136+
section => { name => x('Section'), type => 'text', attributes => { size => 3 } },
137+
recitation => { name => x('Recitation'), type => 'text', attributes => { size => 3 } },
138+
comment => { name => x('Comment'), type => 'text', attributes => { size => 20 } },
139+
permission => { name => x('Permission Level'), type => 'permission' },
140+
password => { name => x('Password (set/delete/enforce)'), type => 'password' },
141141
};
142142

143143
async sub pre_header_initialize ($c) {

templates/ContentGenerator/Instructor/AddUsers.html.ep

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<th id="comment_header"><%= maketext('Comment') %></th>
9292
<th id="permission_header"><%= maketext('Permission Level') %></th>
9393
<th id="password_header"><%= maketext('Password') %></th>
94+
<th id="must_reset_header"><%= maketext('Force Password Reset') %></th>
9495
</tr>
9596
</thead>
9697
<tbody class="table-group-divider">
@@ -154,6 +155,14 @@
154155
<%= text_field "password_$_" => '', size => '16', 'aria-labelledby' => 'password_header',
155156
class => 'form-control form-control-sm w-auto new_password' =%>
156157
</td>
158+
<td class="text-center">
159+
% # Unchecked by default. js/AddUsers/add-users.js automatically checks this once a
160+
% # password is typed into the password field above, or once a fallback password source
161+
% # other than "None" is selected (unless the instructor manually toggles it themselves).
162+
<%= check_box "must_reset_$_" => 1, class => 'form-check-input',
163+
'aria-label' => maketext('Force this user to reset their password at first login'),
164+
data => { auto_check => 'password' } =%>
165+
</td>
157166
</tr>
158167
% }
159168
</tbody>

0 commit comments

Comments
 (0)