Skip to content

Commit

Permalink
MDL-64528 core_completion: prevent toggling completion in frozen context
Browse files Browse the repository at this point in the history
  • Loading branch information
mackensen committed Jan 12, 2019
1 parent 38a1b4f commit 7868aab
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions completion/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function update_activity_completion_status_manually($cmid, $compl

$context = context_module::instance($cmid);
self::validate_context($context);
require_capability('moodle/course:togglecompletion', $context);

list($course, $cm) = get_course_and_cm_from_cmid($cmid);

Expand Down
2 changes: 1 addition & 1 deletion course/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public function course_section_cm_completion($course, &$completioninfo, cm_info
$imgalt = get_string('completion-alt-' . $completionicon, 'completion', $formattedname);
}

if ($this->page->user_is_editing()) {
if ($this->page->user_is_editing() || !has_capability('moodle/course:togglecompletion', $mod->context)) {
// When editing, the icon is just an image.
$completionpixicon = new pix_icon('i/completion-'.$completionicon, $imgalt, '',
array('title' => $imgalt, 'class' => 'iconsmall'));
Expand Down
1 change: 1 addition & 0 deletions course/togglecompletion.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

// Check user is logged in
require_login($course, false, $cm);
require_capability('moodle/course:togglecompletion', context_module::instance($cmid));

if (isguestuser() or !confirm_sesskey()) {
print_error('error');
Expand Down
1 change: 1 addition & 0 deletions lang/en/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,4 @@
$string['privacy:metadata:role_capabilities:tableexplanation'] = 'The capabilities and override capabilities for a particular role in a particular context';
$string['privacy:metadata:role_capabilities:timemodified'] = 'The date when the capability was created or modified.';
$string['privacy:metadata:role_cohortroles'] = 'Roles to cohort';
$string['course:togglecompletion'] = 'Allow users to manually complete activities';
9 changes: 9 additions & 0 deletions lib/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -2439,4 +2439,13 @@
'archetypes' => [
],
],

// Manual completion toggling.
'moodle/course:togglecompletion' => [
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'user' => CAP_ALLOW,
],
],
);

0 comments on commit 7868aab

Please sign in to comment.