Skip to content

Commit

Permalink
Merge branch 'MDL-81525-main' of https://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Apr 17, 2024
2 parents 9e2a8c6 + 40e9fa2 commit 9966241
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 204 deletions.
25 changes: 4 additions & 21 deletions admin/tool/mfa/classes/hook/after_user_passed_mfa.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace tool_mfa\hook;

use core\hook\described_hook;
use core\hook\stoppable_trait;

/**
Expand All @@ -26,26 +25,10 @@
* @copyright 2024 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\core\attribute\label('Allow plugins to callback as soon possible after user has passed MFA.')]
#[\core\attribute\tags('user', 'login')]
class after_user_passed_mfa implements
described_hook,
\Psr\EventDispatcher\StoppableEventInterface {
\Psr\EventDispatcher\StoppableEventInterface
{
use stoppable_trait;

/**
* Describes the hook purpose.
*
* @return string
*/
public static function get_hook_description(): string {
return 'Allow plugins to callback as soon possible after user has passed MFA.';
}

/**
* List of tags that describe this hook.
*
* @return string[]
*/
public static function get_hook_tags(): array {
return ['login'];
}
}
28 changes: 28 additions & 0 deletions admin/tool/mobile/classes/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace tool_mobile;

use core\session\utility\cookie_helper;
use html_writer;

/**
Expand Down Expand Up @@ -78,4 +79,31 @@ public static function before_standard_footer_html_generation(
html_writer::link($url, get_string('getmoodleonyourmobile', 'tool_mobile'), ['class' => 'mobilelink']),
);
}

/**
* Callback to recover $SESSION->wantsurl.
*
* @param \core_user\hook\after_login_completed $hook
*/
public static function after_login_completed(
\core_user\hook\after_login_completed $hook,
): void {
global $SESSION, $CFG;

// Check if the user is doing a mobile app launch, if that's the case, ensure $SESSION->wantsurl is correctly set.
if (!NO_MOODLE_COOKIES && !empty($_COOKIE['tool_mobile_launch'])) {
if (empty($SESSION->wantsurl) || strpos($SESSION->wantsurl, '/tool/mobile/launch.php') === false) {
$params = json_decode($_COOKIE['tool_mobile_launch'], true);
$SESSION->wantsurl = (new \moodle_url("/$CFG->admin/tool/mobile/launch.php", $params))->out(false);
}
}

// Set Partitioned and Secure attributes to the MoodleSession cookie if the user is using the Moodle app.
if (\core_useragent::is_moodle_app()) {
cookie_helper::add_attributes_to_cookie_response_header(
'MoodleSession' . $CFG->sessioncookie,
['Secure', 'Partitioned'],
);
}
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions admin/tool/mobile/db/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
'priority' => 0,
],
[
'hook' => core\hook\user\after_complete_login::class,
'callback' => 'tool_mobile\local\hooks\user\after_complete_login::callback',
'hook' => \core_user\hook\after_login_completed::class,
'callback' => [\tool_mobile\hook_callbacks::class, 'after_login_completed'],
'priority' => 500,
],
[
Expand Down
30 changes: 15 additions & 15 deletions communication/classes/hook_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
use context_course;
use core\hook\access\after_role_assigned;
use core\hook\access\after_role_unassigned;
use core_enrol\hook\before_enrol_instance_delete;
use core_enrol\hook\before_enrol_instance_deleted;
use core_enrol\hook\after_enrol_instance_status_updated;
use core_enrol\hook\after_user_enrolled;
use core_enrol\hook\before_user_enrolment_update;
use core_enrol\hook\before_user_enrolment_remove;
use core_enrol\hook\before_user_enrolment_updated;
use core_enrol\hook\before_user_enrolment_removed;
use core_course\hook\after_course_created;
use core_course\hook\before_course_delete;
use core_course\hook\before_course_deleted;
use core_course\hook\after_course_updated;
use core_group\hook\after_group_created;
use core_group\hook\after_group_deleted;
use core_group\hook\after_group_membership_added;
use core_group\hook\after_group_membership_removed;
use core_group\hook\after_group_updated;
use core_user\hook\before_user_deleted;
use core_user\hook\before_user_update;
use core_user\hook\before_user_updated;

/**
* Hook listener for communication api.
Expand Down Expand Up @@ -345,10 +345,10 @@ public static function update_course_communication(
* Course can have communication data if it is a group or a course.
* This action is important to perform even if the experimental feature is disabled.
*
* @param before_course_delete $hook The course deleted hook.
* @param before_course_deleted $hook The course deleted hook.
*/
public static function delete_course_communication(
before_course_delete $hook,
before_course_deleted $hook,
): void {
// If the communication subsystem is not enabled then just ignore.
if (!api::is_available()) {
Expand Down Expand Up @@ -382,10 +382,10 @@ public static function delete_course_communication(
/**
* Update the room membership for the user updates.
*
* @param before_user_update $hook The user updated hook.
* @param before_user_updated $hook The user updated hook.
*/
public static function update_user_room_memberships(
before_user_update $hook,
before_user_updated $hook,
): void {
// If the communication subsystem is not enabled then just ignore.
if (!api::is_available()) {
Expand Down Expand Up @@ -533,10 +533,10 @@ public static function update_communication_memberships_for_enrol_status_change(
/**
* Remove the communication instance memberships when an enrolment instance is deleted.
*
* @param before_enrol_instance_delete $hook The enrol instance deleted hook.
* @param before_enrol_instance_deleted $hook The enrol instance deleted hook.
*/
public static function remove_communication_memberships_for_enrol_instance_deletion(
before_enrol_instance_delete $hook,
before_enrol_instance_deleted $hook,
): void {
// If the communication subsystem is not enabled then just ignore.
if (!api::is_available()) {
Expand Down Expand Up @@ -591,10 +591,10 @@ public static function add_communication_membership_for_enrolled_user(
/**
* Update the communication instance membership for the user enrolment updates.
*
* @param before_user_enrolment_update $hook The user enrolment updated hook.
* @param before_user_enrolment_updated $hook The user enrolment updated hook.
*/
public static function update_communication_membership_for_updated_user_enrolment(
before_user_enrolment_update $hook,
before_user_enrolment_updated $hook,
): void {
// If the communication subsystem is not enabled then just ignore.
if (!api::is_available()) {
Expand Down Expand Up @@ -630,10 +630,10 @@ public static function update_communication_membership_for_updated_user_enrolmen
/**
* Remove communication instance membership for an enrolled user.
*
* @param before_user_enrolment_remove $hook The user unenrolled hook.
* @param before_user_enrolment_removed $hook The user unenrolled hook.
*/
public static function remove_communication_membership_for_unenrolled_user(
before_user_enrolment_remove $hook,
before_user_enrolment_removed $hook,
): void {
// If the communication subsystem is not enabled then just ignore.
if (!api::is_available()) {
Expand Down
2 changes: 1 addition & 1 deletion course/classes/hook/after_course_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
#[\core\attribute\label('Allows plugins or features to perform actions after a course is created.')]
#[\core\attribute\tags('course')]
class after_course_created {

/**
* Constructor for the hook.
*
* @param stdClass $course The course instance.
*/
public function __construct(
/** @var stdClass The course instance */
public readonly stdClass $course,
) {
}
Expand Down
4 changes: 3 additions & 1 deletion course/classes/hook/after_course_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#[\core\attribute\label('Allows plugins or features to perform actions after a course is updated.')]
#[\core\attribute\tags('course')]
class after_course_updated {

/**
* Constructor for the hook.
*
Expand All @@ -37,8 +36,11 @@ class after_course_updated {
* @param bool $changeincoursecat Whether the course category has changed.
*/
public function __construct(
/** @var stdClass The course instance */
public readonly stdClass $course,
/** @var stdClass The old course instance */
public readonly stdClass $oldcourse,
/** @var bool Whether the course category has changed */
public readonly bool $changeincoursecat = false,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,19 @@
*/
#[\core\attribute\label('Allows plugins or features to perform actions before a course is deleted.')]
#[\core\attribute\tags('course')]
class before_course_delete implements
StoppableEventInterface {

/**
* @var bool Whether the propagation of this event has been stopped.
*/
protected bool $stopped = false;
class before_course_deleted implements
StoppableEventInterface
{
use \core\hook\stoppable_trait;

/**
* Constructor for the hook.
*
* @param stdClass $course The course instance.
*/
public function __construct(
/** @var stdClass The course instance */
public readonly stdClass $course,
) {
}

public function isPropagationStopped(): bool {
return $this->stopped;
}

/**
* Stop the propagation of this event.
*/
public function stop(): void {
$this->stopped = true;
}
}
2 changes: 2 additions & 0 deletions course/format/classes/hook/after_cm_name_edited.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class after_cm_name_edited implements described_hook {
* @param string $newname the new name
*/
public function __construct(
/** @var cm_info the course module */
protected cm_info $cm,
/** @var string the new name */
protected string $newname,
) {
}
Expand Down
3 changes: 2 additions & 1 deletion enrol/classes/hook/after_enrol_instance_status_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
#[\core\attribute\label('Allows plugins or features to perform actions after the enrolment instance status is changed.')]
#[\core\attribute\tags('enrol')]
class after_enrol_instance_status_updated {

/**
* Constructor for the hook.
*
* @param stdClass $enrolinstance The enrol instance.
* @param int $newstatus The new status.
*/
public function __construct(
/** @var stdClass The enrol instance */
public readonly stdClass $enrolinstance,
/** @var int The new status */
public readonly int $newstatus,
) {
}
Expand Down
3 changes: 2 additions & 1 deletion enrol/classes/hook/after_user_enrolled.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
#[\core\attribute\label('Allows plugins or features to perform actions after a user is enrolled in a course.')]
#[\core\attribute\tags('enrol', 'user')]
class after_user_enrolled {

/**
* Constructor for the hook.
*
* @param stdClass $enrolinstance The enrol instance.
* @param stdClass $userenrolmentinstance The user enrolment instance.
*/
public function __construct(
/** @var stdClass The enrol instance */
public readonly stdClass $enrolinstance,
/** @var stdClass The user enrolment instance */
public readonly stdClass $userenrolmentinstance,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
#[\core\attribute\label('Allows plugins or features to perform actions before the enrolment instance is deleted.')]
#[\core\attribute\tags('enrol')]
class before_enrol_instance_delete implements
StoppableEventInterface {

/**
* @var bool Whether the propagation of this event has been stopped.
*/
protected bool $stopped = false;
#[\core\attribute\tags('enrol', 'user')]
class before_enrol_instance_deleted implements
StoppableEventInterface
{
use \core\hook\stoppable_trait;

/**
* Constructor for the hook.
*
* @param stdClass $enrolinstance The enrol instance.
*/
public function __construct(
/** @var stdClass The enrol instance */
public readonly stdClass $enrolinstance,
) {
}

public function isPropagationStopped(): bool {
return $this->stopped;
}

/**
* Stop the propagation of this event.
*/
public function stop(): void {
$this->stopped = true;
}
}
Loading

0 comments on commit 9966241

Please sign in to comment.