Skip to content

Commit

Permalink
messaging MDL-23223 Fixed navigation link being added when messaging …
Browse files Browse the repository at this point in the history
…disabled
  • Loading branch information
Sam Hemelryk committed Jul 13, 2010
1 parent 315f6d8 commit 5ac851f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
28 changes: 17 additions & 11 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1479,10 +1479,10 @@ protected function load_for_user($user=null, $forceforcontext=false) {
}
// Add a branch for the current user
$usernode = $usersnode->add(fullname($user, true), null, self::TYPE_USER, null, $user->id);
}

if ($this->page->context->contextlevel == CONTEXT_USER && $user->id == $this->page->context->instanceid) {
$usernode->force_open();
if ($this->page->context->contextlevel == CONTEXT_USER && $user->id == $this->page->context->instanceid) {
$usernode->make_active();
}
}

// If the user is the current user or has permission to view the details of the requested
Expand Down Expand Up @@ -1521,12 +1521,14 @@ protected function load_for_user($user=null, $forceforcontext=false) {
}
}

$messageargs = null;
if ($USER->id!=$user->id) {
$messageargs = array('id'=>$user->id);
if (!empty($CFG->messaging)) {
$messageargs = null;
if ($USER->id!=$user->id) {
$messageargs = array('id'=>$user->id);
}
$url = new moodle_url('/message/index.php',$messageargs);
$usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');
}
$url = new moodle_url('/message/index.php',$messageargs);
$usernode->add(get_string('messages', 'message'), $url, self::TYPE_SETTING, null, 'messages');

// TODO: Private file capability check
if ($iscurrentuser) {
Expand Down Expand Up @@ -3051,6 +3053,10 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
// Add a user setting branch
$usersetting = $this->add(get_string($gstitle, 'moodle', $fullname), null, self::TYPE_CONTAINER, null, $key);
$usersetting->id = 'usersettings';
if ($this->page->context->contextlevel == CONTEXT_USER && $this->page->context->instanceid == $user->id) {
// Automatically start by making it active
$usersetting->make_active();
}

// Check if the user has been deleted
if ($user->deleted) {
Expand Down Expand Up @@ -3184,10 +3190,10 @@ protected function generate_user_settings($courseid, $userid, $gstitle='usercurr
}

// Messaging
// TODO this is adding itself to the messaging settings for other people based on one's own setting
if (has_capability('moodle/user:editownmessageprofile', $systemcontext)) {
if (($currentuser && has_capability('moodle/user:editownmessageprofile', $systemcontext)) || (!isguestuser($user) && has_capability('moodle/user:editmessageprofile', $usercontext) && !is_primary_admin($user->id))) {
$url = new moodle_url('/message/edit.php', array('id'=>$user->id, 'course'=>$course->id));
$usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING);
// Hide the node if messaging disabled
$usersetting->add(get_string('editmymessage', 'message'), $url, self::TYPE_SETTING)->display = !empty($CFG->messaging);
}

// Blogs
Expand Down
19 changes: 6 additions & 13 deletions message/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@
$personalcontext = get_context_instance(CONTEXT_USER, $user->id);
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);

$PAGE->set_context(get_context_instance(CONTEXT_USER, $USER->id));
$PAGE->set_context($personalcontext);
$PAGE->set_pagelayout('course');

// check access control
if ($user->id == $USER->id) {
//editing own message profile
require_capability('moodle/user:editownmessageprofile', $systemcontext);

if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) {
$node->make_active();
$PAGE->navbar->includesettingsbase = true;
}
} else {
// teachers, parents, etc.
require_capability('moodle/user:editmessageprofile', $personalcontext);
Expand All @@ -85,6 +88,7 @@
if ($user->id == $mainadmin->id) {
print_error('adminprimarynoedit');
}
$PAGE->navigation->extend_for_user($user);
}

/// Save new preferences if data was submited
Expand Down Expand Up @@ -176,17 +180,6 @@
$strparticipants = get_string('participants');
$userfullname = fullname($user, true);

if ($user->id==$USER->id) {
$PAGE->navigation->extend_for_user($USER);
} else {
if (has_capability('moodle/course:viewparticipants', $coursecontext) ||
has_capability('moodle/site:viewparticipants', $systemcontext)) {
$PAGE->navbar->add($strparticipants, new moodle_url('/message/index.php', array('id'=>$course->id)));
}
$PAGE->navbar->add($userfullname, new moodle_url('/user/view.php', array('id'=>$user->id, 'course'=>$course->id)));
$PAGE->navbar->add($streditmymessage);
}

$PAGE->set_title("$course->shortname: $streditmymessage");
if ($course->id != SITEID) {
$PAGE->set_heading("$course->fullname: $streditmymessage");
Expand Down
9 changes: 8 additions & 1 deletion user/editadvanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@
require_capability('moodle/user:update', $systemcontext);
$user = $DB->get_record('user', array('id'=>$id), '*', MUST_EXIST);
$PAGE->set_context(get_context_instance(CONTEXT_USER, $user->id));
$PAGE->navigation->extend_for_user($user);
if ($user->id == $USER->id) {
if ($course->id != SITEID && $node = $PAGE->navigation->find($course->id, navigation_node::TYPE_COURSE)) {
$node->make_active();
$PAGE->navbar->includesettingsbase = true;
}
} else {
$PAGE->navigation->extend_for_user($user);
}
}

// remote users cannot be edited
Expand Down

0 comments on commit 5ac851f

Please sign in to comment.