Skip to content
Snippets Groups Projects
Commit 12e92143 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Made active workflows read only.

parent a44f7a64
No related branches found
No related tags found
No related merge requests found
......@@ -366,7 +366,7 @@ class workflow_settings {
* This is the entry point for this controller class.
*/
public function execute($action, $subplugin) {
global $PAGE;
global $PAGE, $OUTPUT;
$this->check_permissions();
if ($action === ACTION_TRIGGER_INSTANCE_FORM) {
......@@ -382,6 +382,12 @@ class workflow_settings {
if ($form->is_cancelled()) {
// Skip this part and continue with requiring a trigger if still null.
} else if ($form->is_submitted() && $form->is_validated() && $data = $form->get_submitted_data()) {
// In case the workflow is active, we do not allow changes to the steps or trigger.
if (workflow_manager::is_active($this->workflowid)) {
echo $OUTPUT->notification(
get_string('active_workflow_not_changeable', 'tool_cleanupcourses'),
'warning');
} else {
if (!empty($data->id)) {
$trigger = trigger_manager::get_instance($data->id);
$trigger->instancename = $data->instancename;
......@@ -391,6 +397,7 @@ class workflow_settings {
trigger_manager::insert_or_update($trigger);
// Save local subplugin settings.
settings_manager::save_settings($trigger->id, SETTINGS_TYPE_TRIGGER, $data->subpluginname, $data);
}
$this->view_plugins_table();
return;
} else {
......@@ -437,7 +444,13 @@ class workflow_settings {
if ($form->is_cancelled()) {
$this->view_plugins_table();
return;
} else if ($form->is_submitted() && $data = $form->get_submitted_data()) {
} else if ($form->is_submitted() && $form->is_validated() && $data = $form->get_submitted_data()) {
// In case the workflow is active, we do not allow changes to the steps or trigger.
if (workflow_manager::is_active($this->workflowid)) {
echo $OUTPUT->notification(
get_string('active_workflow_not_changeable', 'tool_cleanupcourses'),
'warning');
} else {
if (!empty($data->id)) {
$step = step_manager::get_step_instance($data->id);
$step->instancename = $data->instancename;
......@@ -447,6 +460,7 @@ class workflow_settings {
step_manager::insert_or_update($step);
// Save local subplugin settings.
settings_manager::save_settings($step->id, SETTINGS_TYPE_STEP, $form->subpluginname, $data);
}
$this->view_plugins_table();
return;
} else {
......
......@@ -26,6 +26,7 @@ namespace tool_cleanupcourses\form;
use tool_cleanupcourses\entity\step_subplugin;
use tool_cleanupcourses\manager\step_manager;
use tool_cleanupcourses\manager\lib_manager;
use tool_cleanupcourses\manager\workflow_manager;
use tool_cleanupcourses\step\libbase;
defined('MOODLE_INTERNAL') || die();
......@@ -122,8 +123,25 @@ class form_step_instance extends \moodleform {
$this->lib->extend_add_instance_form_definition($mform);
}
// For active workflows, we do not want the form to be editable.
if ($this->workflowid && workflow_manager::is_active($this->workflowid)) {
$this->add_cancel_button();
} else {
$this->add_action_buttons();
}
}
/**
* In case of read only mode only the cancel button is rendered.
*/
private function add_cancel_button() {
$mform =& $this->_form;
//when two elements we need a group
$buttonarray=array();
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
/**
* Defines forms elements
......@@ -154,6 +172,12 @@ class form_step_instance extends \moodleform {
// Insert the subplugin specific settings.
$this->lib->extend_add_instance_form_definition_after_data($mform, $this->stepsettings);
// For active workflows, we do not want the form to be editable.
if ($this->workflowid && workflow_manager::is_active($this->workflowid)) {
// buttonar is the button array of submit buttons. For inactive workflows this is only a cancel button.
$mform->hardFreezeAllVisibleExcept(array('buttonar'));
}
}
}
......@@ -26,6 +26,7 @@ namespace tool_cleanupcourses\form;
use tool_cleanupcourses\entity\trigger_subplugin;
use tool_cleanupcourses\manager\lib_manager;
use tool_cleanupcourses\manager\trigger_manager;
use tool_cleanupcourses\manager\workflow_manager;
use tool_cleanupcourses\trigger\base;
defined('MOODLE_INTERNAL') || die();
......@@ -129,8 +130,25 @@ class form_trigger_instance extends \moodleform {
$mform->addElement('submit', 'reload', 'reload');
$mform->registerNoSubmitButton('reload');
// For active workflows, we do not want the form to be editable.
if ($this->workflowid && workflow_manager::is_active($this->workflowid)) {
$this->add_cancel_button();
} else {
$this->add_action_buttons();
}
}
/**
* In case of read only mode only the cancel button is rendered.
*/
private function add_cancel_button() {
$mform =& $this->_form;
//when two elements we need a group
$buttonarray=array();
$buttonarray[] = &$mform->createElement('cancel');
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
/**
* Defines forms elements
......@@ -158,6 +176,12 @@ class form_trigger_instance extends \moodleform {
if (isset($this->lib) && !empty($this->lib->instance_settings())) {
$this->lib->extend_add_instance_form_definition_after_data($mform, $this->settings);
}
// For active workflows, we do not want the form to be editable.
if ($this->workflowid && workflow_manager::is_active($this->workflowid)) {
// buttonar is the button array of submit buttons. For inactive workflows this is only a cancel button.
$mform->hardFreezeAllVisibleExcept(array('buttonar'));
}
}
public function validation($data, $files) {
......
......@@ -164,4 +164,14 @@ class workflow_manager {
return true;
}
/**
* Checks if the workflow is active.
* @param $workflowid int id of the workflow.
* @return bool true, if the workflow is active.
*/
public static function is_active($workflowid) {
$workflow = self::get_workflow($workflowid);
return $workflow->active;
}
}
......@@ -45,6 +45,7 @@ $string['general_settings_header'] = 'General Settings';
$string['followedby_none'] = 'None';
$string['invalid_workflow'] = 'Invalid workflow configuration';
$string['invalid_workflow_details'] = 'Go to details view, to create a trigger for this workflow';
$string['active_workflow_not_changeable'] = 'The workflow instance is active. It is not possible to change any of its steps.';
$string['process_cleanup'] = 'Run the cleanup courses processes';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment