From 499dfcb731e70f6160b9156b33fcf01683361e94 Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Thu, 12 Sep 2024 14:17:47 +0200 Subject: [PATCH] Fix most CodeSniffer and PHPDoc checker issues --- auth.php | 22 +++++--- classes/condition.php | 51 ++++++++++++++++--- classes/event/user_2fa_loggedin.php | 24 +++++++-- classes/exception_current_user_selector.php | 25 ++++++--- classes/exception_potential_user_selector.php | 22 ++++++-- classes/frontend.php | 17 +++++-- classes/privacy/provider.php | 49 ++++++++++++++---- db/access.php | 2 + db/events.php | 2 + index.php | 24 ++++++--- lang/de/availability_shibboleth2fa.php | 28 +++++----- lang/en/availability_shibboleth2fa.php | 28 +++++----- manage.php | 10 ++-- settings.php | 2 + version.php | 4 +- 15 files changed, 232 insertions(+), 78 deletions(-) diff --git a/auth.php b/auth.php index 4160860..fa96fb5 100644 --- a/auth.php +++ b/auth.php @@ -15,17 +15,19 @@ // along with Moodle. If not, see . /** + * Calls Shibboleth authentication. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @noinspection PhpUnhandledExceptionInspection + * + * {@noinspection PhpUnhandledExceptionInspection} */ use availability_shibboleth2fa\condition; require(__DIR__ . '/../../../config.php'); -/** @var core_renderer $OUTPUT because the type is not correctly annotated in Moodle */ global $OUTPUT, $PAGE, $USER; $courseid = required_param('id', PARAM_INT); @@ -35,8 +37,12 @@ $course = get_course($courseid); $url = new moodle_url('/availability/condition/shibboleth2fa/auth.php', ['id' => $courseid]); -if ($cmid) $url->param('cmid', $cmid); -if ($sectionid) $url->param('sectionid', $sectionid); +if ($cmid) { + $url->param('cmid', $cmid); +} +if ($sectionid) { + $url->param('sectionid', $sectionid); +} $PAGE->set_url($url); require_login($course, false); @@ -77,8 +83,12 @@ } $redirecturl = new moodle_url('/availability/condition/shibboleth2fa/index.php', ['id' => $courseid]); -if ($cmid) $redirecturl->param('cmid', $cmid); -if ($sectionid) $redirecturl->param('sectionid', $sectionid); +if ($cmid) { + $redirecturl->param('cmid', $cmid); +} +if ($sectionid) { + $redirecturl->param('sectionid', $sectionid); +} if ($errormsg) { // Display error before redirecting. diff --git a/classes/condition.php b/classes/condition.php index 99ad6b2..3f1899c 100644 --- a/classes/condition.php +++ b/classes/condition.php @@ -15,6 +15,10 @@ // along with Moodle. If not, see . /** + * Part of the required availability condition subsystem implementation. + * + * @see https://moodledev.io/docs/4.4/apis/plugintypes/availability#classesconditionphp + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -38,8 +42,15 @@ use moodle_url; use stdClass; -defined('MOODLE_INTERNAL') || die(); - +/** + * Availability condition class. + * + * @see https://moodledev.io/docs/4.4/apis/plugintypes/availability#classesconditionphp + * + * @package availability_shibboleth2fa + * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class condition extends abstract_condition { /** @var int|null cached ID of user with an exception */ @@ -49,18 +60,30 @@ class condition extends abstract_condition { private static array $exceptioncache = []; /** - * @inheritDoc + * {@inheritDoc} + * + * @param bool $not Set true if we are inverting the condition + * @param info $info Item we're checking + * @param bool $grabthelot Performance hint: if true, caches information required for all course-modules, to make the front page + * and similar pages work more quickly (works only for current user) + * @param int $userid User ID to check availability for * @throws dml_exception */ public function is_available($not, info $info, $grabthelot, $userid): bool { - if ($grabthelot) self::preload_exceptions($userid); + if ($grabthelot) { + self::preload_exceptions($userid); + } $course = $info->get_course(); $ret = self::is_course_available($course->id, $userid); return ($not xor $ret); } /** - * @inheritDoc + * {@inheritDoc} + * + * @param bool $full Set true if this is the 'full information' view + * @param bool $not Set true if we are inverting the condition + * @param info $info Item we're checking * @throws moodle_exception */ public function get_description($full, $not, info $info): string { @@ -91,12 +114,16 @@ public function get_description($full, $not, info $info): string { return $str; } - /** @inheritDoc */ + /** + * {@inheritDoc} + */ protected function get_debug_string(): string { return ''; } - /** @inheritDoc */ + /** + * {@inheritDoc} + */ public function save(): stdClass { return (object) ['type' => 'shibboleth2fa']; } @@ -123,7 +150,6 @@ public static function set_authenticated(): void { private static function preload_exceptions(int $userid): void { global $DB; self::$exceptioncacheuser = $userid; - // Fetch exception records. self::$exceptioncache = $DB->get_fieldset_select( table: 'availability_shibboleth2fa_e', return: 'courseid', @@ -204,6 +230,9 @@ public static function is_course_available(int $courseid, int $userid): bool { } /** + * Callback for the {@see user_enrolment_deleted} event to remove a possible exception made for the user in that course. + * + * @param user_enrolment_deleted $event The event instance in question referencing a course and a user that unenrolled from it. * @throws dml_exception */ public static function user_enrolment_deleted(user_enrolment_deleted $event): void { @@ -212,6 +241,9 @@ public static function user_enrolment_deleted(user_enrolment_deleted $event): vo } /** + * Callback for the {@see course_deleted} event to remove all exceptions made for users in that course. + * + * @param course_deleted $event The event instance in question referencing the course that was deleted. * @throws dml_exception */ public static function course_deleted(course_deleted $event): void { @@ -220,6 +252,9 @@ public static function course_deleted(course_deleted $event): void { } /** + * Callback for the {@see user_deleted} event to remove all exceptions made for that user in any course. + * + * @param user_deleted $event The event instance in question referencing the user that was deleted. * @throws dml_exception */ public static function user_deleted(user_deleted $event): void { diff --git a/classes/event/user_2fa_loggedin.php b/classes/event/user_2fa_loggedin.php index 3bfadc8..8b44e27 100644 --- a/classes/event/user_2fa_loggedin.php +++ b/classes/event/user_2fa_loggedin.php @@ -15,6 +15,10 @@ // along with Moodle. If not, see . /** + * Definition of a custom event for when a user authenticates with this plugin. + * + * @see https://docs.moodle.org/dev/Events_API + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -27,8 +31,16 @@ use core\event\base as base_event; use dml_exception; -defined('MOODLE_INTERNAL') || die(); +/** + * Event class for when a user authenticates with this plugin. + * + * @see https://docs.moodle.org/dev/Events_API + * + * @package availability_shibboleth2fa + * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class user_2fa_loggedin extends base_event { /** @@ -62,6 +74,9 @@ public function get_description(): string { return "The user with id '$this->userid' authenticated using a second factor."; } + /** + * {@inheritDoc} + */ public static function get_objectid_mapping(): int { return base_event::NOT_MAPPED; } @@ -76,8 +91,11 @@ public static function get_objectid_mapping(): int { */ public static function create_and_trigger(int|null $userid = null): static { global $USER; - if (is_null($userid)) $userid = $USER->id; - /** @var static $event because the return type of the parent {@see create} method is not correctly annotated */ + if (is_null($userid)) { + $userid = $USER->id; + } + // Because the return type of the parent `create` method is not correctly annotated, we do this here. + /** @var static $event */ $event = static::create(['userid' => $userid, 'objectid' => $userid]); $event->trigger(); return $event; diff --git a/classes/exception_current_user_selector.php b/classes/exception_current_user_selector.php index 3de7d09..42eec40 100644 --- a/classes/exception_current_user_selector.php +++ b/classes/exception_current_user_selector.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Definition of the {@see exception_current_user_selector} class. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -22,14 +24,12 @@ namespace availability_shibboleth2fa; -global $CFG; - use coding_exception; use dml_exception; use user_selector_base; defined('MOODLE_INTERNAL') || die(); - +global $CFG; require_once("$CFG->dirroot/user/selector/lib.php"); @@ -37,17 +37,25 @@ * TODO: Reduce code duplication with {@see exception_potential_user_selector} */ class exception_current_user_selector extends user_selector_base { + /** @var int ID of the course that the exceptions apply to */ protected int $courseid; + /** + * {@inheritDoc} + * + * @param string $name The control name/id for use in the HTML. + * @param array $options Other options needed to construct this selector. Must contain the `courseid`. + */ public function __construct($name, $options) { - $this->courseid = $options['courseid']; + $this->courseid = $options['courseid']; parent::__construct($name, $options); } /** - * Selected users + * Returns users for whom exceptions were defined in the associated course. + * {@inheritDoc} * - * @inheritDoc + * @param string $search the search string. * @throws coding_exception * @throws dml_exception */ @@ -85,10 +93,13 @@ public function find_users($search): array { return [$groupname => $availableusers]; } + /** + * {@inheritDoc} + */ protected function get_options(): array { $options = parent::get_options(); $options['courseid'] = $this->courseid; $options['file'] = '/availability/condition/shibboleth2fa/classes/exception_current_user_selector.php'; return $options; } -} \ No newline at end of file +} diff --git a/classes/exception_potential_user_selector.php b/classes/exception_potential_user_selector.php index 64e3f76..64566f5 100644 --- a/classes/exception_potential_user_selector.php +++ b/classes/exception_potential_user_selector.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Definition of the {@see exception_potential_user_selector} class. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -22,14 +24,13 @@ namespace availability_shibboleth2fa; -global $CFG; use coding_exception; use dml_exception; use user_selector_base; defined('MOODLE_INTERNAL') || die(); - +global $CFG; require_once("$CFG->dirroot/user/selector/lib.php"); @@ -37,17 +38,25 @@ * TODO: Reduce code duplication with {@see exception_current_user_selector} */ class exception_potential_user_selector extends user_selector_base { + /** @var int ID of the course that the exceptions apply to */ protected int $courseid; + /** + * {@inheritDoc} + * + * @param string $name The control name/id for use in the HTML. + * @param array $options Other options needed to construct this selector. Must contain the `courseid`. + */ public function __construct($name, $options) { - $this->courseid = $options['courseid']; + $this->courseid = $options['courseid']; parent::__construct($name, $options); } /** - * Candidate users + * Returns candidate users for whom exceptions can be set in the associated course. + * {@inheritDoc} * - * @inheritDoc + * @param string $search the search string. * @throws coding_exception * @throws dml_exception */ @@ -86,6 +95,9 @@ public function find_users($search): array { return [$groupname => $availableusers]; } + /** + * {@inheritDoc} + */ protected function get_options(): array { $options = parent::get_options(); $options['courseid'] = $this->courseid; diff --git a/classes/frontend.php b/classes/frontend.php index d7e299f..a9d0a37 100644 --- a/classes/frontend.php +++ b/classes/frontend.php @@ -15,6 +15,10 @@ // along with Moodle. If not, see . /** + * Part of the required availability condition subsystem implementation. + * + * @see https://moodledev.io/docs/4.4/apis/plugintypes/availability#classesfrontendphp + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -29,8 +33,15 @@ use section_info; use stdClass; -defined('MOODLE_INTERNAL') || die(); - +/** + * Class for front-end (editing form) functionality. + * + * @see https://moodledev.io/docs/4.4/apis/plugintypes/availability#classesfrontendphp + * + * @package availability_shibboleth2fa + * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class frontend extends abstract_frontend { /** @@ -52,7 +63,7 @@ protected function get_javascript_strings(): array { * @return bool * @throws coding_exception */ - protected function allow_add($course, cm_info $cm = null, section_info $section = null): bool { + protected function allow_add($course, cm_info|null $cm = null, section_info|null $section = null): bool { $context = $cm ? $cm->context : context_course::instance($course->id); return has_capability('availability/shibboleth2fa:addinstance', $context); } diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index b55f926..7b7341e 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -15,6 +15,10 @@ // along with Moodle. If not, see . /** + * Privacy subsystem implementation. + * + * @see https://moodledev.io/docs/4.4/apis/subsystems/privacy + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -36,11 +40,22 @@ use core_privacy\local\request\writer; use dml_exception; -defined('MOODLE_INTERNAL') || die(); - +/** + * Privacy provider class. + * + * @see https://moodledev.io/docs/4.4/apis/subsystems/privacy + * + * @package availability_shibboleth2fa + * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class provider implements core_userlist_provider, metadata_provider, request_plugin_provider { - /** @inheritDoc */ + /** + * {@inheritDoc} + * + * @param metadata_collection $collection The initialised collection to add items to. + */ public static function get_metadata(metadata_collection $collection): metadata_collection { $collection->add_database_table( 'availability_shibboleth2fa_e', @@ -54,7 +69,11 @@ public static function get_metadata(metadata_collection $collection): metadata_c return $collection; } - /** @inheritDoc */ + /** + * {@inheritDoc} + * + * @param int $userid The user to search. + */ public static function get_contexts_for_userid(int $userid): contextlist { $contextlist = new contextlist(); $sql = "SELECT ctx.id @@ -70,7 +89,9 @@ public static function get_contexts_for_userid(int $userid): contextlist { } /** - * @inheritDoc + * {@inheritDoc} + * + * @param approved_contextlist $contextlist The approved contexts to export information for. * @throws coding_exception * @throws dml_exception */ @@ -95,7 +116,9 @@ public static function export_user_data(approved_contextlist $contextlist): void } /** - * @inheritDoc + * {@inheritDoc} + * + * @param context $context The specific context to delete data for. * @throws dml_exception */ public static function delete_data_for_all_users_in_context(context $context): void { @@ -106,7 +129,9 @@ public static function delete_data_for_all_users_in_context(context $context): v } /** - * @inheritDoc + * {@inheritDoc} + * + * @param approved_contextlist $contextlist The approved contexts and user information to delete information for. * @throws dml_exception */ public static function delete_data_for_user(approved_contextlist $contextlist): void { @@ -122,7 +147,11 @@ public static function delete_data_for_user(approved_contextlist $contextlist): } } - /** @inheritDoc */ + /** + * {@inheritDoc} + * + * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. + */ public static function get_users_in_context(userlist $userlist): void { $context = $userlist->get_context(); if (!is_a($context, context_course::class)) { @@ -140,7 +169,9 @@ public static function get_users_in_context(userlist $userlist): void { } /** - * @inheritDoc + * {@inheritDoc} + * + * @param approved_userlist $userlist The approved context and user information to delete information for. * @throws coding_exception * @throws dml_exception */ diff --git a/db/access.php b/db/access.php index 676eecd..026ffc1 100644 --- a/db/access.php +++ b/db/access.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Definitions of custom capabilities associated with the plugin. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/db/events.php b/db/events.php index c4ab6c0..d7f0f84 100644 --- a/db/events.php +++ b/db/events.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Event observer definitions. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/index.php b/index.php index b34742d..782dce8 100644 --- a/index.php +++ b/index.php @@ -15,17 +15,21 @@ // along with Moodle. If not, see . /** + * Confirmation page for a user to authenticate with a second factor. + * + * If the user presses the button to continue, the `auth.php` page is requested next. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @noinspection PhpUnhandledExceptionInspection + * + * {@noinspection PhpUnhandledExceptionInspection} */ use availability_shibboleth2fa\condition; require(__DIR__ . '/../../../config.php'); -/** @var core_renderer $OUTPUT because the type is not correctly annotated in Moodle */ global $OUTPUT, $PAGE, $USER; $courseid = required_param('id', PARAM_INT); @@ -35,8 +39,12 @@ [$course, $cm] = $cmid ? get_course_and_cm_from_cmid($cmid) : [get_course($courseid), null]; $url = new moodle_url('/availability/condition/shibboleth2fa/index.php', ['id' => $course->id]); -if ($cmid) $url->param('cmid', $cmid); -if ($sectionid) $url->param('sectionid', $sectionid); +if ($cmid) { + $url->param('cmid', $cmid); +} +if ($sectionid) { + $url->param('sectionid', $sectionid); +} $PAGE->set_url($url); require_login($course, false); @@ -59,8 +67,12 @@ } else { // Continue to 2FA auth page. $continueurl = new moodle_url('/availability/condition/shibboleth2fa/auth.php', ['id' => $course->id]); - if ($cmid) $continueurl->param('cmid', $cmid); - if ($sectionid) $continueurl->param('sectionid', $sectionid); + if ($cmid) { + $continueurl->param('cmid', $cmid); + } + if ($sectionid) { + $continueurl->param('sectionid', $sectionid); + } $continuetext = get_string('login_required', 'availability_shibboleth2fa'); } diff --git a/lang/de/availability_shibboleth2fa.php b/lang/de/availability_shibboleth2fa.php index 549fecc..740fed8 100644 --- a/lang/de/availability_shibboleth2fa.php +++ b/lang/de/availability_shibboleth2fa.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * German language strings for the plugin. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -22,27 +24,27 @@ defined('MOODLE_INTERNAL') || die(); -$string['title'] = '2FA'; +$string['description'] = 'Erfordere eine Zwei-Faktor-Authentifizierung.'; +$string['eventuser2faloggedin'] = 'Nutzer/in hat sich mit einem zweiten Faktor authentifiziert'; $string['fulltitle'] = 'Zwei-Faktor-Authentifizierung'; +$string['login_failed'] = 'Der Authentifizierungs-Vorgang ist fehlgeschlagen. Bitte kontaktieren Sie Ihren Server-Administrator oder versuchen Sie es später erneut.'; +$string['login_failed_wrong_user'] = 'Sie haben sich mit dem falschen Benutzername authentifiziert. Bitte melden Sie sich ab und versuchen Sie es erneut.'; +$string['login_required'] = 'Sie müssen sich mit einem zweiten Faktor authentifizieren, um auf diesen Inhalt zugreifen zu können. Wenn Sie fortfahren, werden Sie zur Anmeldeseite weitergeleitet.'; +$string['login_successful'] = 'Sie haben sich erfolgreich mit einem zweiten Faktor authentifiziert. Sie können nun auf den geschützten Inhalt zugreifen.'; +$string['manage_exceptions'] = 'Ausnahmen verwalten'; $string['pluginname'] = 'Voraussetzung: Zwei-Faktor-Authentifizierung'; -$string['description'] = 'Erfordere eine Zwei-Faktor-Authentifizierung.'; -$string['shibboleth2fa:addinstance'] = 'Zwei-Faktor-Authentifizierung als Voraussetzung für Aktivitäten hinzufügen'; -$string['shibboleth2fa:manageexceptions'] = 'Nutzerspezifische Ausnahmen für die Zwei-Faktor-Authentifizierung verwalten'; $string['privacy:metadata:availability_shibboleth2fa_e'] = 'Informationen über alle nutzerspezifischen Ausnahmen zur Zwei-Faktor-Authentifizierung.'; $string['privacy:metadata:availability_shibboleth2fa_e:courseid'] = 'ID des Kurses, in dem die Ausnahme gilt.'; -$string['privacy:metadata:availability_shibboleth2fa_e:userid'] = 'Nutzer-ID der Person, für die die Ausnahme gilt.'; $string['privacy:metadata:availability_shibboleth2fa_e:skipauth'] = 'Legt fest, ob eine Ausnahme für diese Person existiert.'; +$string['privacy:metadata:availability_shibboleth2fa_e:userid'] = 'Nutzer-ID der Person, für die die Ausnahme gilt.'; $string['requires_2fa'] = 'Sie authentifizieren sich mit einem zweiten Faktor'; $string['requires_no2fa'] = 'Sie haben sich nicht mit einem zweiten Faktor authentifiziert'; -$string['login_required'] = 'Sie müssen sich mit einem zweiten Faktor authentifizieren, um auf diesen Inhalt zugreifen zu können. Wenn Sie fortfahren, werden Sie zur Anmeldeseite weitergeleitet.'; -$string['login_successful'] = 'Sie haben sich erfolgreich mit einem zweiten Faktor authentifiziert. Sie können nun auf den geschützten Inhalt zugreifen.'; +$string['shibboleth2fa:addinstance'] = 'Zwei-Faktor-Authentifizierung als Voraussetzung für Aktivitäten hinzufügen'; +$string['shibboleth2fa:manageexceptions'] = 'Nutzerspezifische Ausnahmen für die Zwei-Faktor-Authentifizierung verwalten'; +$string['title'] = '2FA'; $string['user_exceptions'] = 'Nutzerspezifische kursweite Ausnahmen'; -$string['manage_exceptions'] = 'Ausnahmen verwalten'; +$string['username_override_description'] = 'Überschreibt den Namen der Shibboleth Webserver-Umgebungsvariable, die mit dem Moodle-Benutzername verglichen werden soll. Verwendet standardmäßig den in auth_shibboleth festgelegten Wert, falls nicht gesetzt.'; $string['users_with_exception'] = 'Nutzer/innen mit Ausnahme'; -$string['users_without_exception'] = 'Nutzer/innen ohne Ausnahme'; $string['users_with_exception_matching'] = 'Passende Nutzer/innen mit Ausnahme'; +$string['users_without_exception'] = 'Nutzer/innen ohne Ausnahme'; $string['users_without_exception_matching'] = 'Passende Nutzer/innen ohne Ausnahme'; -$string['eventuser2faloggedin'] = 'Nutzer/in hat sich mit einem zweiten Faktor authentifiziert'; -$string['username_override_description'] = 'Überschreibt den Namen der Shibboleth Webserver-Umgebungsvariable, die mit dem Moodle-Benutzername verglichen werden soll. Verwendet standardmäßig den in auth_shibboleth festgelegten Wert, falls nicht gesetzt.'; -$string['login_failed'] = 'Der Authentifizierungs-Vorgang ist fehlgeschlagen. Bitte kontaktieren Sie Ihren Server-Administrator oder versuchen Sie es später erneut.'; -$string['login_failed_wrong_user'] = 'Sie haben sich mit dem falschen Benutzername authentifiziert. Bitte melden Sie sich ab und versuchen Sie es erneut.'; \ No newline at end of file diff --git a/lang/en/availability_shibboleth2fa.php b/lang/en/availability_shibboleth2fa.php index 68ca424..8d8f45d 100644 --- a/lang/en/availability_shibboleth2fa.php +++ b/lang/en/availability_shibboleth2fa.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * English language strings for the plugin. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -22,27 +24,27 @@ defined('MOODLE_INTERNAL') || die(); -$string['title'] = '2FA'; +$string['description'] = 'Require students to authenticate using a second factor.'; +$string['eventuser2faloggedin'] = 'User authenticated using second factor'; $string['fulltitle'] = 'Two-factor authentication'; +$string['login_failed'] = 'Something went wrong with the authentication process. Please contact your server administrator or try again later.'; +$string['login_failed_wrong_user'] = 'You authenticated using the wrong username. Please log out of your account and try again.'; +$string['login_required'] = 'You need to authenticate using a second factor to access this content. If you continue, you will be taken to the login prompt.'; +$string['login_successful'] = 'You have successfully authenticated using a second factor. You can now proceed to the requested content.'; +$string['manage_exceptions'] = 'manage exceptions'; $string['pluginname'] = 'Restriction by two-factor authentication'; -$string['description'] = 'Require students to authenticate using a second factor.'; -$string['shibboleth2fa:addinstance'] = 'Add two-factor authentication conditions to activities'; -$string['shibboleth2fa:manageexceptions'] = 'Add and remove per-user exceptions for two-factor authentication conditions'; $string['privacy:metadata:availability_shibboleth2fa_e'] = 'Information about all user-specific exceptions to the two-factor authentication.'; $string['privacy:metadata:availability_shibboleth2fa_e:courseid'] = 'The ID of the course where the exception was created.'; -$string['privacy:metadata:availability_shibboleth2fa_e:userid'] = 'The ID of the user who the exception is for.'; $string['privacy:metadata:availability_shibboleth2fa_e:skipauth'] = 'Whether there is an exception for this user.'; +$string['privacy:metadata:availability_shibboleth2fa_e:userid'] = 'The ID of the user who the exception is for.'; $string['requires_2fa'] = 'You authenticate using a second factor'; $string['requires_no2fa'] = 'You have not authenticated using a second factor'; -$string['login_required'] = 'You need to authenticate using a second factor to access this content. If you continue, you will be taken to the login prompt.'; -$string['login_successful'] = 'You have successfully authenticated using a second factor. You can now proceed to the requested content.'; +$string['shibboleth2fa:addinstance'] = 'Add two-factor authentication conditions to activities'; +$string['shibboleth2fa:manageexceptions'] = 'Add and remove per-user exceptions for two-factor authentication conditions'; +$string['title'] = '2FA'; $string['user_exceptions'] = 'Per-user course-wide exceptions'; -$string['manage_exceptions'] = 'manage exceptions'; +$string['username_override_description'] = 'Overrides the name of the webserver Shibboleth environment variable that shall be compared to the Moodle username. Defaults to the value set by auth_shibboleth if empty.'; $string['users_with_exception'] = 'Users with exception'; -$string['users_without_exception'] = 'Users without exception'; $string['users_with_exception_matching'] = 'Users with exception matching'; +$string['users_without_exception'] = 'Users without exception'; $string['users_without_exception_matching'] = 'Users without exception matching'; -$string['eventuser2faloggedin'] = 'User authenticated using second factor'; -$string['username_override_description'] = 'Overrides the name of the webserver Shibboleth environment variable that shall be compared to the Moodle username. Defaults to the value set by auth_shibboleth if empty.'; -$string['login_failed'] = 'Something went wrong with the authentication process. Please contact your server administrator or try again later.'; -$string['login_failed_wrong_user'] = 'You authenticated using the wrong username. Please log out of your account and try again.'; \ No newline at end of file diff --git a/manage.php b/manage.php index 9a4bf0c..7ca683d 100644 --- a/manage.php +++ b/manage.php @@ -15,10 +15,13 @@ // along with Moodle. If not, see . /** + * Page for managing user exceptions from the 2FA requirement in a course. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - * @noinspection PhpUnhandledExceptionInspection + * 4 + * {@noinspection PhpUnhandledExceptionInspection} */ use availability_shibboleth2fa\condition; @@ -27,7 +30,6 @@ require(__DIR__ . '/../../../config.php'); -/** @var core_renderer $OUTPUT because the type is not correctly annotated in Moodle */ global $OUTPUT, $PAGE; $courseid = required_param('id', PARAM_INT); @@ -56,7 +58,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoassign = $potentialuserselector->get_selected_users(); if (!empty($userstoassign)) { - foreach($userstoassign as $adduser) { + foreach ($userstoassign as $adduser) { condition::set_exception( courseid: $course->id, userid: $adduser->id, @@ -72,7 +74,7 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { $userstounassign = $currentuserselector->get_selected_users(); if (!empty($userstounassign)) { - foreach($userstounassign as $removeuser) { + foreach ($userstounassign as $removeuser) { condition::set_exception( courseid: $course->id, userid: $removeuser->id, diff --git a/settings.php b/settings.php index 5924ee7..726f9d4 100644 --- a/settings.php +++ b/settings.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Definition of plugin-specific admin settings. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/version.php b/version.php index 7e24179..7eb4d87 100644 --- a/version.php +++ b/version.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Version and requirements information for the plugin. + * * @package availability_shibboleth2fa * @copyright 2021 Lars Bonczek, innoCampus, TU Berlin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -24,6 +26,6 @@ $plugin->component = 'availability_shibboleth2fa'; $plugin->version = 2024090500; -$plugin->requires = 2024042200; // Moodle 4.4.0+ +$plugin->requires = 2024042200; // Moodle 4.4.0+. $plugin->maturity = MATURITY_ALPHA; $plugin->release = '0.2';