Skip to content

Commit

Permalink
MDL-56565 forum: Make sure userfullname is not disclosed
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal authored and Mr. Jenkins (CiBoT) committed Jul 4, 2017
1 parent 540a38d commit 5176a91
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions mod/forum/user.php
Expand Up @@ -26,6 +26,7 @@
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/mod/forum/lib.php');
require_once($CFG->dirroot.'/rating/lib.php');
require_once($CFG->dirroot.'/user/lib.php');

$courseid = optional_param('course', null, PARAM_INT); // Limit the posts to just this course
$userid = optional_param('id', $USER->id, PARAM_INT); // User id whose posts we want to view
Expand Down Expand Up @@ -134,29 +135,8 @@
// In either case we need to decide whether we can show personal information
// about the requested user to the current user so we will execute some checks

// First check the obvious, its the current user, a specific course has been
// provided (require_login has been called), or they have a course contact role.
// True to any of those and the current user can see the details of the
// requested user.
$canviewuser = ($iscurrentuser || $isspecificcourse || empty($CFG->forceloginforprofiles) || has_coursecontact_role($userid));
// Next we'll check the caps, if the current user has the view details and a
// specific course has been requested, or if they have the view all details
$canviewuser = ($canviewuser || ($isspecificcourse && has_capability('moodle/user:viewdetails', $coursecontext) || has_capability('moodle/user:viewalldetails', $usercontext)));

// If none of the above was true the next step is to check a shared relation
// through some course
if (!$canviewuser) {
// Get all of the courses that the users have in common
$sharedcourses = enrol_get_shared_courses($USER->id, $user->id, true);
foreach ($sharedcourses as $sharedcourse) {
// Check the view cap within the course context
if (has_capability('moodle/user:viewdetails', context_course::instance($sharedcourse->id))) {
$canviewuser = true;
break;
}
}
unset($sharedcourses);
}
// TODO - Remove extra cap check once MDL-59172 is resolved.
$canviewuser = user_can_view_profile($user, null, $usercontext) || has_capability('moodle/user:viewalldetails', $usercontext);

// Prepare the page title
$pagetitle = get_string('noposts', 'mod_forum');
Expand Down Expand Up @@ -237,7 +217,7 @@
$PAGE->set_title($pagetitle);
if ($isspecificcourse) {
$PAGE->set_heading($pageheading);
} else {
} else if ($canviewuser) {
$PAGE->set_heading(fullname($user));
}
echo $OUTPUT->header();
Expand Down

0 comments on commit 5176a91

Please sign in to comment.