Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
34 additions
and
0 deletions.
-
+7
−0
lib/classes/user.php
-
+27
−0
user/lib.php
|
@@ -82,6 +82,13 @@ class core_user { |
|
|
'alternatename' |
|
|
]; |
|
|
|
|
|
/** @var int Indicates that user profile view should be prevented */ |
|
|
const VIEWPROFILE_PREVENT = -1; |
|
|
/** @var int Indicates that user profile view should not be prevented */ |
|
|
const VIEWPROFILE_DO_NOT_PREVENT = 0; |
|
|
/** @var int Indicates that user profile view should be allowed even if Moodle would prevent it */ |
|
|
const VIEWPROFILE_FORCE_ALLOW = 1; |
|
|
|
|
|
/** @var stdClass keep record of noreply user */ |
|
|
public static $noreplyuser = false; |
|
|
|
|
|
|
@@ -1154,6 +1154,33 @@ function user_can_view_profile($user, $course = null, $usercontext = null) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
// Use callbacks so that (primarily) local plugins can prevent or allow profile access. |
|
|
$forceallow = false; |
|
|
$plugintypes = get_plugins_with_function('control_view_profile'); |
|
|
foreach ($plugintypes as $plugins) { |
|
|
foreach ($plugins as $pluginfunction) { |
|
|
$result = $pluginfunction($user, $course, $usercontext); |
|
|
switch ($result) { |
|
|
case core_user::VIEWPROFILE_DO_NOT_PREVENT: |
|
|
// If the plugin doesn't stop access, just continue to next plugin or use |
|
|
// default behaviour. |
|
|
break; |
|
|
case core_user::VIEWPROFILE_FORCE_ALLOW: |
|
|
// Record that we are definitely going to allow it (unless another plugin |
|
|
// returns _PREVENT). |
|
|
$forceallow = true; |
|
|
break; |
|
|
case core_user::VIEWPROFILE_PREVENT: |
|
|
// If any plugin returns PREVENT then we return false, regardless of what |
|
|
// other plugins said. |
|
|
return false; |
|
|
} |
|
|
} |
|
|
} |
|
|
if ($forceallow) { |
|
|
return true; |
|
|
} |
|
|
|
|
|
// Course contacts have visible profiles always. |
|
|
if (has_coursecontact_role($user->id)) { |
|
|
return true; |
|
|