-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2618 from somiaj/manage-otp-secrets
Add course admin tool to manage OTP secrets.
- Loading branch information
Showing
8 changed files
with
618 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(() => { | ||
// Save user menus to be updated. | ||
const sourceSingleUserMenu = document.getElementById('sourceSingleUserID'); | ||
const destSingleUserMenu = document.getElementById('destSingleUserID'); | ||
const sourceMultipleUserMenu = document.getElementById('sourceMultipleUserID'); | ||
const destResetUserMenu = document.getElementById('destResetUserID'); | ||
|
||
const updateUserMenu = (e, menu, selectFirst) => { | ||
const userList = e.target.options[e.target.selectedIndex].dataset.users.split(':'); | ||
while (menu.length > 1) menu.lastChild.remove(); | ||
if (selectFirst) { | ||
menu.selectedIndex = 0; | ||
} | ||
userList.forEach((user) => { | ||
const userOption = document.createElement('option'); | ||
userOption.value = userOption.text = user; | ||
menu.append(userOption); | ||
}); | ||
}; | ||
|
||
// Update user menu when course ID is selected/changed. | ||
document.getElementById('sourceSingleCourseID')?.addEventListener('change', (e) => { | ||
updateUserMenu(e, sourceSingleUserMenu, true); | ||
}); | ||
document.getElementById('destSingleCourseID')?.addEventListener('change', (e) => { | ||
updateUserMenu(e, destSingleUserMenu, true); | ||
}); | ||
document.getElementById('sourceMultipleCourseID')?.addEventListener('change', (e) => { | ||
updateUserMenu(e, sourceMultipleUserMenu, false); | ||
}); | ||
document.getElementById('sourceResetCourseID')?.addEventListener('change', (e) => { | ||
updateUserMenu(e, destResetUserMenu, false); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
templates/ContentGenerator/CourseAdmin/copy_otp_secrets_confirm.html.ep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
% my $total = 0; | ||
% my $overwrite_warning = 0; | ||
<h2><%= maketext('Copy OTP Secrets') %></h2> | ||
<%= form_for current_route, method => 'POST', begin %> | ||
<div class="table-responsive"> | ||
<table class="table table-sm table-bordered font-sm"> | ||
<thead class="table-group-divider"> | ||
<tr> | ||
<th scope="col"><%= maketext('Copy from (Course ID / User ID)') %></th> | ||
<th scope="col"><%= maketext('Copy to (Course ID / User ID)') %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
% for my $row (@$action_rows) { | ||
% unless ($row->{skip}) { | ||
% $total++; | ||
% $overwrite_warning = 1 if $row->{error} && $row->{error} eq 'danger'; | ||
% content_for 'hidden-rows' => begin | ||
<%= hidden_field otp_copy_row => $row->{source_course} . ':' . $row->{source_user} | ||
. ':' . $row->{dest_course} . ':' . $row->{dest_user} =%> | ||
% end | ||
% } | ||
<tr class="<%= $row->{error} ? 'table-' . $row->{error} : '' %>"> | ||
<td> | ||
<%= $row->{source_course} %> / <%= $row->{source_user} %> | ||
% if ($row->{source_message}) { | ||
<br/>(<%= $row->{source_message} %>) | ||
% } | ||
</td> | ||
<td> | ||
% unless ($row->{source_message}) { | ||
<%= $row->{dest_course} %> / <%= $row->{dest_user} %> | ||
% if ($row->{dest_message}) { | ||
<br/>(<%= $row->{dest_message} %>) | ||
% } | ||
% } | ||
</td> | ||
</tr> | ||
% } | ||
</tbody> | ||
</table> | ||
</div> | ||
<%= $c->hidden_fields('subDisplay', 'show_all_courses') =%> | ||
% if ($total > 0) { | ||
% my $skipped = @$action_rows - $total; | ||
<%= content 'hidden-rows' %> | ||
% if ($skipped > 0) { | ||
<p><%= maketext('Confirm copying the above [_1] OTP secrets ([_2] skipped).', $total, $skipped) %></p> | ||
% } else { | ||
<p><%= maketext('Confirm copying the above [_1] OTP secrets.', $total) %></p> | ||
% } | ||
% if ($overwrite_warning) { | ||
<div class="alert alert-danger p-1"> | ||
<%= maketext('Warning! Overwriting OTP secrets cannot be undone.') %> | ||
</div> | ||
% } | ||
<%= submit_button maketext('Confirm Copy'), name => 'otp_confirm_copy', class => 'btn btn-primary' %> | ||
% } else { | ||
<p><%= maketext('No valid OTP secrets to copy. Skipping all.') %></p> | ||
% } | ||
<%= submit_button maketext('Cancel Copy'), name => 'otp_cancel_copy', class => 'btn btn-primary' %> | ||
<%= end %> |
Oops, something went wrong.