]> git.andy128k.dev Git - ipf.git/commitdiff
move ensureUserIsStaff to controller
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 3 Jan 2015 23:41:26 +0000 (01:41 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 3 Jan 2015 23:41:26 +0000 (01:41 +0200)
ipf/admin/app.php
ipf/admin/controllers/base.php
ipf/admin/controllers/components.php
ipf/admin/controllers/file_browser.php

index 69a8b87eb30fdca465203ffe90f56b1931bf4732..9c3730a81fc67229c5b8bb970ba656ba7c9f5ba8 100644 (file)
@@ -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)
index 46328f4675c5efbc3163e60f1a813edd228d3c92..8654821728880cbbca390d1ceb55b94f5b186569 100644 (file)
@@ -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);
index 4d80bfb46d5b2edca05c5a5ccede58ae2697ddb0..b4a49a942440bc8b1bb39fe774a89e5b158e3a71 100644 (file)
@@ -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)
index 0855e9dc454c3f661f95c6ffd76cf2c6ade51a40..06e31b147904b19700de564ed0b9766578dae274 100644 (file)
@@ -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']);