diff --git a/user/index.php b/user/index.php
index e07d8e763f3..01310616d0c 100644
--- a/user/index.php
+++ b/user/index.php
@@ -668,7 +668,7 @@
$usercontext = $user->context;
}
- if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) ||has_capability('moodle/user:viewdetails', $context))) {
+ if ($piclink = ($USER->id == $user->id || has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext))) {
$profilelink = ''.fullname($user).'';
} else {
$profilelink = ''.fullname($user).'';