diff --git a/grade/report/singleview/classes/local/screen/screen.php b/grade/report/singleview/classes/local/screen/screen.php index 8a43bd5af0f..9e7ba7ca841 100644 --- a/grade/report/singleview/classes/local/screen/screen.php +++ b/grade/report/singleview/classes/local/screen/screen.php @@ -329,6 +329,13 @@ abstract class screen { continue; } + // If the user submits Exclude grade elements without the proper + // permissions then we should refuse to update. + if ($matches[1] === 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ + $warnings[] = get_string('nopermissions', 'error', get_string('grade:manage', 'role')); + continue; + } + $msg = $element->set($posted); // Optional type. diff --git a/grade/report/singleview/classes/local/screen/tablelike.php b/grade/report/singleview/classes/local/screen/tablelike.php index ecb6f905418..2d7835d24af 100644 --- a/grade/report/singleview/classes/local/screen/tablelike.php +++ b/grade/report/singleview/classes/local/screen/tablelike.php @@ -141,6 +141,12 @@ abstract class tablelike extends screen { $html .= $this->structure->get_grade_analysis_icon($grade); } + // Singleview users without proper permissions should be presented + // disabled checkboxes for the Exclude grade attribute. + if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ + $html->locked=TRUE; + } + $line[] = $html; } return $line; diff --git a/grade/report/singleview/classes/local/ui/exclude.php b/grade/report/singleview/classes/local/ui/exclude.php index caddb1e6bd2..73440b55d16 100644 --- a/grade/report/singleview/classes/local/ui/exclude.php +++ b/grade/report/singleview/classes/local/ui/exclude.php @@ -40,6 +40,9 @@ class exclude extends grade_attribute_format implements be_checked { /** @var string $name The name of the input */ public $name = 'exclude'; + /** @var bool $locked Is the input locked? */ + public $locked = FALSE; + /** * Is it checked? * @@ -49,6 +52,15 @@ class exclude extends grade_attribute_format implements be_checked { return $this->grade->is_excluded(); } + /** + * Is it locked? + * + * @return bool + */ + public function is_locked() { + return $this->locked; + } + /** * Generate the element used to render the UI * @@ -58,7 +70,9 @@ class exclude extends grade_attribute_format implements be_checked { return new checkbox_attribute( $this->get_name(), $this->get_label(), - $this->is_checked() + $this->is_checked(), + // Call checkbox constructor with locked attribute, expects integer. + $this->is_locked() ? 1 : 0 ); }