From 42197ab592ab3297946146c346cd04caa9f526b4 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sun, 4 Jan 2015 01:41:26 +0200 Subject: [PATCH] move ensureUserIsStaff to controller --- ipf/admin/app.php | 9 --------- ipf/admin/controllers/base.php | 9 +++++++++ ipf/admin/controllers/components.php | 4 ++-- ipf/admin/controllers/file_browser.php | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/ipf/admin/app.php b/ipf/admin/app.php index 69a8b87..9c3730a 100644 --- a/ipf/admin/app.php +++ b/ipf/admin/app.php @@ -97,15 +97,6 @@ class IPF_Admin_App extends IPF_Application return self::$appComponents[$app->slug()]; } - public static function ensureUserIsStaff($request) - { - if ($request->user->isAnonymous()) - throw new IPF_Admin_LoginRequired; - - if (!$request->user->is_staff && !$request->user->is_superuser) - throw new IPF_Admin_LoginRequired; - } - public static function getApplicationBySlug($slug) { foreach (IPF_Project::getInstance()->appList() as $app) diff --git a/ipf/admin/controllers/base.php b/ipf/admin/controllers/base.php index 46328f4..8654821 100644 --- a/ipf/admin/controllers/base.php +++ b/ipf/admin/controllers/base.php @@ -2,6 +2,15 @@ abstract class IPF_Admin_Base_Controller extends IPF_Controller { + protected function ensureUserIsStaff() + { + if ($this->request->user->isAnonymous()) + throw new IPF_Admin_LoginRequired; + + if (!$this->request->user->is_staff && !$this->request->user->is_superuser) + throw new IPF_Admin_LoginRequired; + } + protected function render($template, $params) { $context = IPF_Project_Template::context($params, $this->request); diff --git a/ipf/admin/controllers/components.php b/ipf/admin/controllers/components.php index 4d80bfb..b4a49a9 100644 --- a/ipf/admin/controllers/components.php +++ b/ipf/admin/controllers/components.php @@ -4,7 +4,7 @@ class IPF_Admin_Controller extends IPF_Admin_Base_Controller { function index() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $admin_log = \PFF\Container::databaseQuery() ->from('admin_log') @@ -63,7 +63,7 @@ class IPF_Admin_Controller extends IPF_Admin_Base_Controller protected function getComponent($requiredPermissions) { - IPF_Admin_App::ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $component = IPF_Admin_App::getComponentBySlugs($this->request->params[1], $this->request->params[2]); if (!$component) diff --git a/ipf/admin/controllers/file_browser.php b/ipf/admin/controllers/file_browser.php index 0855e9d..06e31b1 100644 --- a/ipf/admin/controllers/file_browser.php +++ b/ipf/admin/controllers/file_browser.php @@ -62,7 +62,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function index() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $request = $this->request; @@ -129,7 +129,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function rename() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $old_name = $this->validateName($this->request->POST['old_name']); @@ -141,7 +141,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function move() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $destination = $this->validatePath(IPF::getUploadPath() . DIRECTORY_SEPARATOR . \PFF\Arr::get($this->request->POST, 'destination', '')); @@ -153,7 +153,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function mkdir() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $name = $this->validateName($this->request->POST['name']); @@ -164,7 +164,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function delete() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $name = $this->validateName($this->request->POST['name']); @@ -175,7 +175,7 @@ class IPF_Admin_FileBrowser_Controller extends IPF_Admin_Base_Controller function upload() { - \PFF\Container::admin()->ensureUserIsStaff($this->request); + $this->ensureUserIsStaff(); $this->setCurrentDir(); $count = count($this->request->FILES['files']['name']); -- 2.49.0