Skip to content

Commit

Permalink
Replace two almost identical classes with user_exception_selector
Browse files Browse the repository at this point in the history
- Use a custom constructor for convenience and type safety
- Require `skipauth` argument in the constructor to differentiate
- Generalize `find_users` algorithm
- Remove unneeded `file` key from `get_options` return array (since it
  is not necessary to `require` the source file explicitly)
- Add `set_exceptions_for_selected_users` convenience method
- Drastically simplify `manage.php` as a result
  • Loading branch information
daniil-berg committed Oct 29, 2024
1 parent 65bee9b commit f416ced
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 277 deletions.
12 changes: 4 additions & 8 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,11 @@ public static function get_exception(int $courseid, int $userid): bool {
public static function set_exception(int $courseid, int $userid, bool $skipauth): void {
global $DB;
// Insert or update exception record.
$data = new stdClass();
$data->courseid = $courseid;
$data->userid = $userid;
$data->skipauth = $skipauth;
if ($id = $DB->get_field('availability_shibboleth2fa_e', 'id', ['courseid' => $courseid, 'userid' => $userid])) {
$data->id = $id;
$DB->update_record('availability_shibboleth2fa_e', $data);
$data = ['courseid' => $courseid, 'userid' => $userid];
if ($id = $DB->get_field('availability_shibboleth2fa_e', 'id', $data)) {
$DB->update_record('availability_shibboleth2fa_e', $data + ['skipauth' => $skipauth, 'id' => $id]);
} else {
$DB->insert_record('availability_shibboleth2fa_e', $data);
$DB->insert_record('availability_shibboleth2fa_e', $data + ['skipauth' => $skipauth]);
}
// Invalidate exception cache.
if ($userid == self::$exceptioncacheuser) {
Expand Down
109 changes: 0 additions & 109 deletions classes/exception_current_user_selector.php

This file was deleted.

111 changes: 0 additions & 111 deletions classes/exception_potential_user_selector.php

This file was deleted.

Loading

0 comments on commit f416ced

Please sign in to comment.