From 3cc217193a7d1d07e207feaa7271c7a228d2c7aa Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 25 Jan 2022 16:00:10 +0100 Subject: [PATCH] MDL-73684 core_user: check edit capability only when user exists --- user/profile/lib.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/user/profile/lib.php b/user/profile/lib.php index 0b040720684..cd450d5d6f1 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -506,9 +506,11 @@ class profile_field_base { } // Checking for mentors have capability to edit user's profile. - $usercontext = context_user::instance($this->userid); - if ($this->userid != $USER->id && has_capability('moodle/user:editprofile', $usercontext, $USER->id)) { - return true; + if ($this->userid > 0) { + $usercontext = context_user::instance($this->userid); + if ($this->userid != $USER->id && has_capability('moodle/user:editprofile', $usercontext, $USER->id)) { + return true; + } } return false;