Commit 71beedee authored by Travis Noll's avatar Travis Noll Committed by Eloy Lafuente (stronk7)
Browse files

MDL-52378 Singleview: Exclude Grade Attribute Permissions

Singleview users must have Manage Grade permission to modify the
Exclude grade attribute.
parent d63ac148
......@@ -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.
......
......@@ -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;
......
......@@ -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
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment