MDL-70441 assign: Freeze workflow states not available to user.

Prior to this, a custom grader role that has mod/assign:grade but not
mod/assign:releasegrades or mod/assign:managegrades would see a select
with only the states available to them - not the current state, and
could reset a grade from released to Not marked/In marking/Marking
completed.
This commit is contained in:
David Balch 2021-03-30 10:02:51 +01:00 committed by Kevin Percy
parent 462d5f04a8
commit 726de6ab68
2 changed files with 46 additions and 9 deletions

View File

@ -650,15 +650,20 @@ class assign_grading_table extends table_sql implements renderable {
if ($this->quickgrading && !$gradingdisabled) { if ($this->quickgrading && !$gradingdisabled) {
$notmarked = get_string('markingworkflowstatenotmarked', 'assign'); $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
$name = 'quickgrade_' . $row->id . '_workflowstate'; $name = 'quickgrade_' . $row->id . '_workflowstate';
$o .= html_writer::select($workflowstates, $name, $workflowstate, array('' => $notmarked)); if ($workflowstate !== ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED && !array_key_exists($workflowstate, $workflowstates)) {
// Check if this user is a marker that can't manage allocations and doesn't have the marker column added. $allworkflowstates = $this->assignment->get_all_marking_workflow_states();
if ($this->assignment->get_instance()->markingworkflow && $o .= html_writer::div($allworkflowstates[$workflowstate]);
$this->assignment->get_instance()->markingallocation && } else {
!has_capability('mod/assign:manageallocations', $this->assignment->get_context())) { $o .= html_writer::select($workflowstates, $name, $workflowstate, ['' => $notmarked]);
// Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
if ($this->assignment->get_instance()->markingworkflow &&
$this->assignment->get_instance()->markingallocation &&
!has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker'; $name = 'quickgrade_' . $row->id . '_allocatedmarker';
$o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name, $o .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $name,
'value' => $row->allocatedmarker)); 'value' => $row->allocatedmarker]);
}
} }
} else { } else {
$o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate); $o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);

View File

@ -165,6 +165,9 @@ class assign {
/** @var array of marking workflow states for the current user */ /** @var array of marking workflow states for the current user */
private $markingworkflowstates = null; private $markingworkflowstates = null;
/** @var array of all marking workflow states */
private $allmarkingworkflowstates = null;
/** @var bool whether to exclude users with inactive enrolment */ /** @var bool whether to exclude users with inactive enrolment */
private $showonlyactiveenrol = null; private $showonlyactiveenrol = null;
@ -7891,8 +7894,15 @@ class assign {
if ($this->get_instance()->markingworkflow) { if ($this->get_instance()->markingworkflow) {
$states = $this->get_marking_workflow_states_for_current_user(); $states = $this->get_marking_workflow_states_for_current_user();
$options = array('' => get_string('markingworkflowstatenotmarked', 'assign')) + $states; $options = array('' => get_string('markingworkflowstatenotmarked', 'assign')) + $states;
$mform->addElement('select', 'workflowstate', get_string('markingworkflowstate', 'assign'), $options); $select = $mform->addElement('select', 'workflowstate', get_string('markingworkflowstate', 'assign'), $options);
$mform->addHelpButton('workflowstate', 'markingworkflowstate', 'assign'); $mform->addHelpButton('workflowstate', 'markingworkflowstate', 'assign');
if (isset($data->workflowstate) && !array_key_exists($data->workflowstate, $states)) {
// In a workflow state that user should not be able to change, so freeze workflow selector.
// Have to add the state so it shows in the frozen selector.
$allworkflowstates = $this->get_all_marking_workflow_states();
$select->addOption($allworkflowstates[$data->workflowstate], $data->workflowstate);
$mform->freeze('workflowstate');
}
$gradingstatus = $this->get_grading_status($userid); $gradingstatus = $this->get_grading_status($userid);
if ($gradingstatus != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { if ($gradingstatus != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
if ($grade->grade && $grade->grade != -1) { if ($grade->grade && $grade->grade != -1) {
@ -9204,6 +9214,28 @@ class assign {
return $this->markingworkflowstates; return $this->markingworkflowstates;
} }
/**
* Get the list of marking_workflow states.
*
* @return array Array of multiple state => description.
*/
public function get_all_marking_workflow_states(): array {
if (!empty($this->allmarkingworkflowstates)) {
return $this->allmarkingworkflowstates;
}
$this->allmarkingworkflowstates = [
ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED => get_string('markingworkflowstatenotmarked', 'assign'),
ASSIGN_MARKING_WORKFLOW_STATE_INMARKING => get_string('markingworkflowstateinmarking', 'assign'),
ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW => get_string('markingworkflowstatereadyforreview', 'assign'),
ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW => get_string('markingworkflowstateinreview', 'assign'),
ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE => get_string('markingworkflowstatereadyforrelease', 'assign'),
ASSIGN_MARKING_WORKFLOW_STATE_RELEASED => get_string('markingworkflowstatereleased', 'assign'),
];
return $this->allmarkingworkflowstates;
}
/** /**
* Check is only active users in course should be shown. * Check is only active users in course should be shown.
* *