From a098f340fe2864d91ac056fc90250564883e62a9 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Sun, 27 May 2012 12:49:10 +0800 Subject: [PATCH] MDL-33466: Group restriction should hide activity even with 'show availability' option This is a modified version of fix by Luke Tucker at NetSpot - thanks. --- lib/modinfolib.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/modinfolib.php b/lib/modinfolib.php index bcbb7ecff22ab..b6a6e985cd57b 100644 --- a/lib/modinfolib.php +++ b/lib/modinfolib.php @@ -1078,18 +1078,24 @@ private function update_user_visible() { $modcontext = get_context_instance(CONTEXT_MODULE, $this->id); $userid = $this->modinfo->get_user_id(); $this->uservisible = true; + // Check visibility/availability conditions. if ((!$this->visible or !$this->available) and !has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) { // If the activity is hidden or unavailable, and you don't have viewhiddenactivities, - // set it so that user can't see or access it + // set it so that user can't see or access it. $this->uservisible = false; - } else if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly) + } + // Check group membership. The grouping option makes the activity + // completely invisible as it does not apply to the user at all. + if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly) and !has_capability('moodle/site:accessallgroups', $modcontext, $userid)) { // If the activity has 'group members only' and you don't have accessallgroups... $groups = $this->modinfo->get_groups($this->groupingid); if (empty($groups)) { // ...and you don't belong to a group, then set it so you can't see/access it $this->uservisible = false; + // Ensure activity is completely hidden from user. + $this->showavailability = 0; } } }