Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wenn deployed, dann manche Pages schützen (#23)
- Loading branch information
Showing
5 changed files
with
320 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
class rex_api_ydeploy_protected_page extends rex_api_function | ||
{ | ||
public function execute() | ||
{ | ||
if (!rex::getUser()->isAdmin()) { | ||
throw new rex_api_exception('Protected pages can be (un)locked only by admins.'); | ||
} | ||
|
||
$action = rex_get('action', 'string'); | ||
|
||
if (!in_array($action, ['lock', 'unlock'], true)) { | ||
throw new rex_api_exception('Supported protected page actions are "lock" and "unlock", but "'.$action.'" given.'); | ||
} | ||
|
||
$protectedPage = rex_get('protected_page', 'string'); | ||
|
||
$foundPage = null; | ||
foreach (rex_ydeploy_handler::getProtectedPages() as $page => $subpages) { | ||
// `yform/manager/table_edit` must not match `yform/man` | ||
// so we add slashes to avoid this | ||
if (0 === strpos($protectedPage.'/', $page.'/')) { | ||
$foundPage = $page; | ||
|
||
break; | ||
} | ||
} | ||
|
||
if (!$foundPage) { | ||
throw new rex_api_exception('The page "'.$protectedPage.'" is not protected.'); | ||
} | ||
|
||
if ('unlock' === $action) { | ||
rex_ydeploy_handler::unlockPage($foundPage); | ||
} else { | ||
rex_ydeploy_handler::lockPage($foundPage); | ||
} | ||
|
||
if ($redirect = rex_get('redirect', 'string')) { | ||
rex_response::sendRedirect($redirect); | ||
} | ||
|
||
$result = new rex_api_result(true); | ||
$result->setRequiresReboot(true); | ||
|
||
return $result; | ||
} | ||
|
||
protected function requiresCsrfProtection() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters