From e079856a7dc7d5ba52f6474b3f82330f27990097 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 4 Dec 2017 18:13:41 +0100 Subject: [runmode] Properly block simple editor if requested; add customized delete URL --- modules-available/runmode/page.inc.php | 45 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'modules-available/runmode/page.inc.php') diff --git a/modules-available/runmode/page.inc.php b/modules-available/runmode/page.inc.php index ef42e7be..e26950d0 100644 --- a/modules-available/runmode/page.inc.php +++ b/modules-available/runmode/page.inc.php @@ -28,16 +28,16 @@ class Page_RunMode extends Page $modeId = Request::post('modeid', false, 'string'); $modConfig = RunMode::getModuleConfig($module); if ($modConfig === false) { - Message::addError('module-hasnt-runmode', $module); + Message::addError('runmode.module-hasnt-runmode', $module); return; } if (!$modConfig->allowGenericEditor) { - Message::addError('cannot-edit-module', $module); + Message::addError('runmode.cannot-edit-module', $module); return; } $test = RunMode::getModeName($module, $modeId); if ($test === false) { - Message::addError('invalid-modeid', $module, $modeId); + Message::addError('runmode.invalid-modeid', $module, $modeId); return; } $active = 0; @@ -53,21 +53,31 @@ class Page_RunMode extends Page WHERE module = :module AND modeid = :modeId AND machineuuid NOT IN (:machines)', compact('module', 'modeId', 'machines')); Message::addSuccess('runmode.enabled-removed-save', $active, $deleted); - $redirect = Request::post('redirect', false, 'string'); - if ($redirect !== false) { - Util::redirect($redirect); - } - Util::redirect('?do=runmode&module=' . $module . '&modeid=' . $modeId); + Util::redirect('?do=runmode&module=' . $module . '&modeid=' . $modeId, true); } elseif ($action === 'delete-machine') { $machineuuid = Request::post('machineuuid', false, 'string'); if ($machineuuid === false) { - Message::addError('machine-not-found', $machineuuid); + Message::addError('main.parameter-missing', 'machineuuid'); + return; + } + $mode = RunMode::getRunMode($machineuuid); + if ($mode === false) { + Message::addError('runmode.machine-not-found', $machineuuid); + return; + } + $modConfig = RunMode::getModuleConfig($mode['module']); + if ($modConfig === false) { + Message::addError('module-hasnt-runmode', $mode['moduleName']); + return; + } + if (!$modConfig->allowGenericEditor) { + Message::addError('runmode.cannot-edit-module', $mode['moduleName']); + return; + } + if (RunMode::setRunMode($machineuuid, null, null)) { + Message::addSuccess('machine-removed', $machineuuid); } else { - if (RunMode::setRunMode($machineuuid, null, null)) { - Message::addSuccess('machine-removed', $machineuuid); - } else { - Message::addWarning('machine-not-runmode', $machineuuid); - } + Message::addWarning('machine-not-runmode', $machineuuid); } } } @@ -95,6 +105,10 @@ class Page_RunMode extends Page Message::addError('module-hasnt-runmode', $moduleId); Util::redirect('?do=runmode'); } + if (!$config->allowGenericEditor) { + Message::addError('runmode.cannot-edit-module', $moduleId); + return; + } // Given modeId? $modeId = Request::get('modeid', false, 'string'); if ($modeId !== false) { @@ -137,10 +151,13 @@ class Page_RunMode extends Page $module = Module::get($moduleId); if ($module === false) continue; + $config = RunMode::getModuleConfig($moduleId); Render::addTemplate('module-machine-list', array( 'list' => $rows['list'], 'modulename' => $module->getDisplayName(), 'module' => $moduleId, + 'canedit' => $config !== false && $config->allowGenericEditor && $config->deleteUrlSnippet === false, + 'deleteUrl' => $config->deleteUrlSnippet )); } } -- cgit v1.2.3-55-g7522