Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit ef21ef9

Browse files
author
Michael Grauer
committed
BUG: refs #0399. Replaced checks for admin and server side login checks.
Used the requireAdminPrivileges method as a replacement, and checked that the pattern if(!logged){ $this->haveToBeLogged(); return false; } is used consistently as a check if the user is logged in.
1 parent e35044c commit ef21ef9

File tree

22 files changed

+46
-124
lines changed

22 files changed

+46
-124
lines changed

core/controllers/AdminController.php

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,9 @@ function taskAction()
6060
if(!$this->logged)
6161
{
6262
$this->haveToBeLogged();
63-
return;
64-
}
65-
if(!$this->userSession->Dao->getAdmin() == 1)
66-
{
67-
throw new Zend_Exception("You should be an administrator");
63+
return false;
6864
}
65+
$this->requireAdminPrivileges();
6966

7067
$task = $this->_getParam("task");
7168
$params = $this->_getParam("params");
@@ -87,12 +84,9 @@ function indexAction()
8784
if(!$this->logged)
8885
{
8986
$this->haveToBeLogged();
90-
return;
91-
}
92-
if(!$this->userSession->Dao->getAdmin() == 1)
93-
{
94-
throw new Zend_Exception("You should be an administrator");
87+
return false;
9588
}
89+
$this->requireAdminPrivileges();
9690
$this->view->header = "Administration";
9791
$configForm = $this->Form->Admin->createConfigForm();
9892

@@ -306,10 +300,7 @@ function indexAction()
306300
/** Used to display and filter the list of log messages */
307301
function showlogAction()
308302
{
309-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
310-
{
311-
throw new Zend_Exception("You should be an administrator");
312-
}
303+
$this->requireAdminPrivileges();
313304
$this->requireAjaxRequest();
314305
$this->_helper->layout->disableLayout();
315306

@@ -387,10 +378,7 @@ function showlogAction()
387378
/** Used to delete a list of log entries */
388379
function deletelogAction()
389380
{
390-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
391-
{
392-
throw new Zend_Exception('You should be an administrator');
393-
}
381+
$this->requireAdminPrivileges();
394382
$this->requireAjaxRequest();
395383
$this->_helper->layout->disableLayout();
396384
$this->_helper->viewRenderer->setNoRender();
@@ -416,10 +404,7 @@ function deletelogAction()
416404
/** function dashboard*/
417405
function dashboardAction()
418406
{
419-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
420-
{
421-
throw new Zend_Exception("You should be an administrator");
422-
}
407+
$this->requireAdminPrivileges();
423408
$this->requireAjaxRequest();
424409

425410
$this->_helper->layout->disableLayout();
@@ -433,10 +418,7 @@ function dashboardAction()
433418
/** upgrade database*/
434419
function upgradeAction()
435420
{
436-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
437-
{
438-
throw new Zend_Exception("You should be an administrator");
439-
}
421+
$this->requireAdminPrivileges();
440422
$this->requireAjaxRequest();
441423
$this->_helper->layout->disableLayout();
442424

@@ -500,12 +482,10 @@ function serversidefilechooserAction()
500482
{
501483
if(!$this->logged)
502484
{
503-
throw new Zend_Exception("You should be logged in");
504-
}
505-
if(!$this->userSession->Dao->isAdmin())
506-
{
507-
throw new Zend_Exception("Administrative privileges required");
485+
$this->haveToBeLogged();
486+
return false;
508487
}
488+
$this->requireAdminPrivileges();
509489

510490
$this->_helper->layout->disableLayout();
511491
$this->_helper->viewRenderer->setNoRender();
@@ -571,12 +551,9 @@ function migratemidas2Action()
571551
if(!$this->logged)
572552
{
573553
$this->haveToBeLogged();
574-
return;
575-
}
576-
if(!$this->userSession->Dao->getAdmin() == 1)
577-
{
578-
throw new Zend_Exception("You should be an administrator");
554+
return false;
579555
}
556+
$this->requireAdminPrivileges();
580557

581558
$this->assetstores = $this->Assetstore->getAll();
582559
$this->view->migrateForm = $this->Form->Migrate->createMigrateForm($this->assetstores);

core/controllers/AssetstoreController.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ function indexAction()
5252
/** change default assetstore*/
5353
function defaultassetstoreAction()
5454
{
55-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
56-
{
57-
throw new Zend_Exception("You should be an administrator");
58-
}
55+
$this->requireAdminPrivileges();
5956
$this->requireAjaxRequest();
6057
$this->_helper->layout->disableLayout();
6158
$this->_helper->viewRenderer->setNoRender();
@@ -80,10 +77,7 @@ function defaultassetstoreAction()
8077
/** delete an assetstore assetstore*/
8178
function deleteAction()
8279
{
83-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
84-
{
85-
throw new Zend_Exception("You should be an administrator");
86-
}
80+
$this->requireAdminPrivileges();
8781
$this->requireAjaxRequest();
8882
$this->_helper->layout->disableLayout();
8983
$this->_helper->viewRenderer->setNoRender();
@@ -105,10 +99,7 @@ function deleteAction()
10599
/** edit an assetstore assetstore*/
106100
function editAction()
107101
{
108-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
109-
{
110-
throw new Zend_Exception("You should be an administrator");
111-
}
102+
$this->requireAdminPrivileges();
112103
$this->requireAjaxRequest();
113104
$this->_helper->layout->disableLayout();
114105
$this->_helper->viewRenderer->setNoRender();
@@ -136,6 +127,8 @@ function editAction()
136127
*/
137128
function addAction()
138129
{
130+
$this->requireAdminPrivileges();
131+
$this->requireAjaxRequest();
139132
$this->_helper->layout->disableLayout();
140133
$this->_helper->viewRenderer->setNoRender();
141134

core/controllers/BrowseController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public function movecopyAction()
141141
{
142142
throw new Zend_Exception("No element selected");
143143
}
144-
if(!$this->view->logged)
144+
if(!$this->logged)
145145
{
146-
throw new Zend_Exception("Should be logged");
146+
throw new Zend_Exception(MIDAS_LOGIN_REQUIRED);
147147
}
148148
$this->view->folders = $folders;
149149
$this->view->items = $items;
@@ -398,6 +398,7 @@ public function uploadedAction()
398398
*/
399399
public function deleteAction()
400400
{
401+
$this->requireAjaxRequest();
401402
if(!$this->logged)
402403
{
403404
throw new Zend_Exception('You must be logged in to delete resources.');

core/controllers/DownloadController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
=========================================================================*/
2020

2121
/**
22-
* AJAX request for the admin Controller
22+
* Controller for downloading elements.
2323
*/
2424
class DownloadController extends AppController
2525
{

core/controllers/FolderController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function removeitemAction()
258258
}
259259
elseif(!$this->Item->policyCheck($item, $this->userSession->Dao, MIDAS_POLICY_ADMIN))
260260
{
261-
throw new Zend_Exception('Admin permission on item required');
261+
throw new Zend_Exception(MIDAS_ADMIN_PRIVILEGES_REQUIRED);
262262
}
263263

264264
$this->Folder->removeItem($folder, $item);

core/controllers/ItemController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function editmetadataAction()
4444
$this->disableLayout();
4545
if(!$this->logged)
4646
{
47-
throw new Zend_Exception("You have to be logged in to do that");
47+
throw new Zend_Exception(MIDAS_LOGIN_REQUIRED);
4848
}
4949

5050
$itemId = $this->_getParam("itemId");

core/controllers/UserController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function settingsAction()
357357
$userId = $this->_getParam('userId');
358358
if(isset($userId) && $userId != $this->userSession->Dao->getKey() && !$this->userSession->Dao->isAdmin())
359359
{
360-
throw new Zend_Exception('You should be an admin');
360+
throw new Zend_Exception(MIDAS_ADMIN_PRIVILEGES_REQUIRED);
361361
}
362362
else if(isset($userId))
363363
{
@@ -656,7 +656,7 @@ public function userpageAction()
656656

657657
if(!isset($user_id) && !$this->logged)
658658
{
659-
$this->view->header = $this->t("You should be logged in.");
659+
$this->view->header = $this->t(MIDAS_LOGIN_REQUIRED);
660660
$this->_helper->viewRenderer->setNoRender();
661661
return false;
662662
}
@@ -722,7 +722,7 @@ public function manageAction()
722722

723723
if(!isset($user_id) && !$this->logged)
724724
{
725-
$this->view->header = $this->t("You should be logged in.");
725+
$this->view->header = $this->t(MIDAS_LOGIN_REQUIRED);
726726
$this->_helper->viewRenderer->setNoRender();
727727
return false;
728728
}

modules/api/controllers/ConfigController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ function usertabAction()
8484
/** index action*/
8585
function indexAction()
8686
{
87-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
88-
{
89-
throw new Zend_Exception("You should be an administrator");
90-
}
87+
$this->requireAdminPrivileges();
9188

9289
if(file_exists(BASE_PATH."/core/configs/api.local.ini"))
9390
{

modules/batchmake/controllers/ConfigController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ protected function createDefaultConfig($currentConfig)
105105
*/
106106
public function indexAction()
107107
{
108-
109-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
110-
{
111-
throw new Zend_Exception("You should be an administrator");
112-
}
108+
$this->requireAdminPrivileges();
113109

114110
// get all the properties, not just the batchmake config
115111
$fullConfig = $this->ModuleComponent->KWBatchmake->loadConfigProperties(null, false);

modules/cleanup/controllers/ConfigController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ class Cleanup_ConfigController extends Cleanup_AppController
99
/** index action*/
1010
function indexAction()
1111
{
12-
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
13-
{
14-
throw new Zend_Exception('You should be an administrator');
15-
}
12+
$this->requireAdminPrivileges();
1613

1714
if(file_exists(BASE_PATH.'/core/configs/'.$this->moduleName.'.local.ini'))
1815
{

0 commit comments

Comments
 (0)