Skip to content

Commit

Permalink
MDL-71917 core_message: Use $USER in WS delete_message_for_all_users
Browse files Browse the repository at this point in the history
  • Loading branch information
cescobedo authored and abgreeve committed Jul 6, 2021
1 parent 526f5ec commit 2f4647c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions message/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3577,13 +3577,13 @@ public static function delete_message_for_all_users_parameters() {
* Deletes a message for all users
*
* @param int $messageid the message id
* @param int $userid the user id of who we want to delete the message for all users
* @param int $userid the user id of who we want to delete the message for all users, is no longer used.
* @return external_description
* @throws moodle_exception
* @since 3.7
*/
public static function delete_message_for_all_users(int $messageid, int $userid) {
global $CFG;
global $CFG, $USER;

// Check if private messaging between users is allowed.
if (empty($CFG->messaging)) {
Expand All @@ -3601,11 +3601,10 @@ public static function delete_message_for_all_users(int $messageid, int $userid)
$context = context_system::instance();
self::validate_context($context);

$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
core_user::require_active_user($USER);

// Checks if a user can delete a message for all users.
if (core_message\api::can_delete_message_for_all_users($user->id, $params['messageid'])) {
if (core_message\api::can_delete_message_for_all_users($USER->id, $params['messageid'])) {
\core_message\api::delete_message_for_all_users($params['messageid']);
} else {
throw new moodle_exception('You do not have permission to delete this message for everyone.');
Expand Down

0 comments on commit 2f4647c

Please sign in to comment.