Skip to content

Commit

Permalink
MDL-33466: Group restriction should hide activity even with 'show ava…
Browse files Browse the repository at this point in the history
…ilability' option

This is a modified version of fix by Luke Tucker at NetSpot - thanks.
  • Loading branch information
sammarshallou authored and Sam Hemelryk committed Jul 3, 2012
1 parent afb6a8a commit 547695f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/modinfolib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -994,18 +994,24 @@ private function update_user_visible() {
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id); $modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
$userid = $this->modinfo->get_user_id(); $userid = $this->modinfo->get_user_id();
$this->uservisible = true; $this->uservisible = true;
// Check visibility/availability conditions.
if ((!$this->visible or !$this->available) and if ((!$this->visible or !$this->available) and
!has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) { !has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
// If the activity is hidden or unavailable, and you don't have viewhiddenactivities, // 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; $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)) { and !has_capability('moodle/site:accessallgroups', $modcontext, $userid)) {
// If the activity has 'group members only' and you don't have accessallgroups... // If the activity has 'group members only' and you don't have accessallgroups...
$groups = $this->modinfo->get_groups($this->groupingid); $groups = $this->modinfo->get_groups($this->groupingid);
if (empty($groups)) { if (empty($groups)) {
// ...and you don't belong to a group, then set it so you can't see/access it // ...and you don't belong to a group, then set it so you can't see/access it
$this->uservisible = false; $this->uservisible = false;
// Ensure activity is completely hidden from user.
$this->showavailability = 0;
} }
} }
} }
Expand Down

0 comments on commit 547695f

Please sign in to comment.