Skip to content

Commit

Permalink
feat: add readonly checks to all the forms
Browse files Browse the repository at this point in the history
- Dataflow form
- Step form
- Import form

Resolves #786
  • Loading branch information
keevan committed Jun 23, 2023
1 parent 3e4c330 commit 1259919
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
7 changes: 7 additions & 0 deletions classes/form/dataflow_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

namespace tool_dataflows\form;

use moodle_exception;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
use tool_dataflows\manager;

/**
* Dataflow Form
Expand Down Expand Up @@ -101,6 +103,11 @@ public function definition() {
* @return array of additional errors, or overridden errors.
*/
protected function extra_validation($data, $files, array &$errors) {
// Ensure no updates can be made for readonly mode.
if (manager::is_dataflows_readonly()) {
throw new moodle_exception('readonly_active', 'tool_dataflows');
}

$newerrors = [];

// Vars must be a valid YAML object.
Expand Down
10 changes: 9 additions & 1 deletion classes/import_form.php → classes/form/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows;
namespace tool_dataflows\form;

use moodle_exception;
use tool_dataflows\manager;

/**
* Import dataflow form class.
Expand Down Expand Up @@ -60,6 +63,11 @@ public function definition() {
public function validation($data, $files) {
global $USER;

// Ensure no updates can be made for readonly mode.
if (manager::is_dataflows_readonly()) {
throw new moodle_exception('readonly_active', 'tool_dataflows');
}

$validationerrors = [];

// Get the file from the filestystem. $files will always be empty.
Expand Down
7 changes: 7 additions & 0 deletions classes/form/step_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

namespace tool_dataflows\form;

use moodle_exception;
use Symfony\Component\Yaml\Yaml;
use tool_dataflows\dataflow;
use tool_dataflows\manager;
use tool_dataflows\parser;
use tool_dataflows\step;

Expand Down Expand Up @@ -390,6 +392,11 @@ protected function get_default_data() {
protected function extra_validation($data, $files, array &$errors) {
global $DB;

// Ensure no updates can be made for readonly mode.
if (manager::is_dataflows_readonly()) {
throw new moodle_exception('readonly_active', 'tool_dataflows');
}

$errors = [];

// Process and convert the received data back under the config field.
Expand Down
12 changes: 12 additions & 0 deletions dataflow-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use tool_dataflows\dataflow;
use tool_dataflows\manager;

require_once(dirname(__FILE__) . '/../../../config.php');

Expand All @@ -48,6 +49,17 @@
? new moodle_url('/admin/tool/dataflows/view.php', ['id' => $dataflow->id])
: new moodle_url('/admin/tool/dataflows/index.php');

// Ensure dataflows is not in readonly mode. If it is, display an error
if (manager::is_dataflows_readonly()) {
return redirect(
$returnurl,
get_string('readonly_active', 'tool_dataflows'),
0,
\core\output\notification::NOTIFY_ERROR,
);
}


$notifystring = null;
switch ($action) {
case 'remove':
Expand Down
2 changes: 1 addition & 1 deletion import.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

use tool_dataflows\dataflow;
use tool_dataflows\import_form;
use tool_dataflows\form\import_form;
use tool_dataflows\visualiser;

require_once(dirname(__FILE__) . '/../../../config.php');
Expand Down

0 comments on commit 1259919

Please sign in to comment.