protected static function validate_preferences_permissions($userid) {
        global $USER;

        if (empty($userid)) {
            $user = $USER;
        } else {
            $user = core_user::get_user($userid, '*', MUST_EXIST);
            core_user::require_active_user($user);
        }

        $systemcontext = context_system::instance();
        self::validate_context($systemcontext);

        // Check access control.
        if ($user->id == $USER->id) {
            // Editing own message profile.
            require_capability('moodle/user:editownmessageprofile', $systemcontext);
        } else {
            // Teachers, parents, etc.
            $personalcontext = context_user::instance($user->id);
            require_capability('moodle/user:editmessageprofile', $personalcontext);
        }
        return $user;
    }
protected static function validate_preferences_permissions($userid) {
        global $USER;

        if (empty($userid)) {
            $user = $USER;
        } else {
            $user = core_user::get_user($userid, '*', MUST_EXIST);
            core_user::require_active_user($user);
        }

        $systemcontext = context_system::instance();
        self::validate_context($systemcontext);

        // Check access control.
        if ($user->id == $USER->id) {
            // Editing own message profile.
            require_capability('moodle/user:editownmessageprofile', $systemcontext);
        } else {
            // Teachers, parents, etc.
            $personalcontext = context_user::instance($user->id);
            require_capability('moodle/user:editmessageprofile', $personalcontext);
        }
        return $user;
    }
protected static function validate_preferences_permissions ( $ userid ) { global $ USER ; if ( empty ( $ userid ) ) { $ user = $ USER ; } else { $ user = core_user :: get_user ( $ userid , '*' , MUST_EXIST ) ; core_user :: require_active_user ( $ user ) ; } $ systemcontext = context_system :: instance ( ) ; self :: validate_context ( $ systemcontext ) ; // Check access control. if ( $ user -> id == $ USER -> id ) { // Editing own message profile. require_capability ( 'moodle/user:editownmessageprofile' , $ systemcontext ) ; } else { // Teachers, parents, etc. $ personalcontext = context_user :: instance ( $ user -> id ) ; require_capability ( 'moodle/user:editmessageprofile' , $ personalcontext ) ; } return $ user ; }
Check that the user has enough permission to retrieve message or notifications preferences.

@param  int $userid the user id requesting the preferences
@return stdClass full user object
@throws moodle_exception
@since  Moodle 3.2
Check that the user has enough permission to retrieve message or notifications preferences .