Skip to content

Commit

Permalink
MDL-35762 core_grade: altered the code that determines whether an act…
Browse files Browse the repository at this point in the history
…ivity is visible on the user report
  • Loading branch information
andyjdavis authored and stronk7 committed Nov 6, 2012
1 parent 3a8714c commit 84fad57
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 23 deletions.
12 changes: 8 additions & 4 deletions grade/report/user/lib.php
Expand Up @@ -348,13 +348,17 @@ private function fill_table_recursive(&$element) {
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
$hide = true;
} else if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
// The grade object can be marked visible but still be hidden if "enablegroupmembersonly"
// is on and it's an activity assigned to a grouping the user is not in.
// The grade object can be marked visible but still be hidden if...
// 1) "enablegroupmembersonly" is on and the activity is assigned to a grouping the user is not in.
// 2) the student cannot see the activity due to conditional access and its set to be hidden entirely.
$instances = $this->gtree->modinfo->get_instances_of($grade_object->itemmodule);
if (!empty($instances[$grade_object->iteminstance])) {
$cm = $instances[$grade_object->iteminstance];
if ($cm->is_user_access_restricted_by_group()) {
$hide = true;
if (!$cm->uservisible) {
// Further checks are required to determine whether the activity is entirely hidden or just greyed out.
if ($cm->is_user_access_restricted_by_group() || $cm->is_user_access_restricted_by_conditional_access()) {
$hide = true;
}
}
}
}
Expand Down
79 changes: 60 additions & 19 deletions lib/modinfolib.php
Expand Up @@ -1077,48 +1077,89 @@ public function obtain_dynamic_data() {
}

/**
* Works out whether activity is visible *for current user* - if this is false, they
* aren't allowed to access it.
* Works out whether activity is available to the current user
*
* If the activity is unavailable, additional checks are required to determine if its hidden or greyed out
*
* @see is_user_access_restricted_by_group()
* @see is_user_access_restricted_by_conditional_access()
* @return void
*/
private function update_user_visible() {
global $CFG;
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
$userid = $this->modinfo->get_user_id();
$this->uservisible = true;
// Check visibility/availability conditions.

// If the user cannot access the activity set the uservisible flag to false.
// Additional checks are required to determine whether the activity is entirely hidden or just greyed out.
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.

$this->uservisible = false;
}
// Check group membership. The grouping option makes the activity
// completely invisible as it does not apply to the user at all.

// Check group membership.
if ($this->is_user_access_restricted_by_group()) {
$this->uservisible = false;
// Ensure activity is completely hidden from user.

$this->uservisible = false;
// Ensure activity is completely hidden from the user.
$this->showavailability = 0;
}
}

/**
* Checks whether the module group settings restrict the user access.
* @return bool true if the user access is restricted
* Checks whether the module's group settings restrict the current user's access
*
* @return bool True if the user access is restricted
*/
public function is_user_access_restricted_by_group() {
global $CFG;

if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly)) {
$modcontext = context_module::instance($this->id);
$userid = $this->modinfo->get_user_id();
if (!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
return true;
}
}
}
return false;
}

/**
* Checks whether the module's conditional access settings mean that the user cannot see the activity at all
*
* @return bool True if the user cannot see the module. False if the activity is either available or should be greyed out.
*/
public function is_user_access_restricted_by_conditional_access() {
global $CFG, $USER;

if (empty($CFG->enableavailability)) {
return false;
}

// If module will always be visible anyway (but greyed out), don't bother checking anything else
if ($this->showavailability == CONDITION_STUDENTVIEW_SHOW) {
return false;
}

// Can the user see hidden modules?
$modcontext = context_module::instance($this->id);
$userid = $this->modinfo->get_user_id();
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
return true;
}
if (has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
return false;
}

// Is the module hidden due to unmet conditions?
if (!$this->available) {
return true;
}

return false;
}

Expand Down

0 comments on commit 84fad57

Please sign in to comment.