MDL-72325 user: Introduce new core_user::awaiting_action() method
The method allows to check if the user is fully ready to use the site or whether there is an action (such as filling the missing profile field, changing password or agreeing to the site policy) needed.
This commit is contained in:
@@ -1134,4 +1134,39 @@ class core_user {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the user expected to perform an action to start using Moodle properly?
|
||||
*
|
||||
* This covers cases such as filling the profile, changing password or agreeing to the site policy.
|
||||
*
|
||||
* @param stdClass $user User object, defaults to the current user.
|
||||
* @return bool
|
||||
*/
|
||||
public static function awaiting_action(stdClass $user = null): bool {
|
||||
global $USER;
|
||||
|
||||
if ($user === null) {
|
||||
$user = $USER;
|
||||
}
|
||||
|
||||
if (user_not_fully_set_up($user)) {
|
||||
// Awaiting the user to fill all fields in the profile.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (get_user_preferences('auth_forcepasswordchange', false, $user)) {
|
||||
// Awaiting the user to change their password.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($user->policyagreed) && !is_siteadmin($user)) {
|
||||
$manager = new \core_privacy\local\sitepolicy\manager();
|
||||
|
||||
if ($manager->is_defined(isguestuser($user))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user