Backend\Core\Engine\Authentication::isAllowedAction PHP Method

isAllowedAction() public static method

Is the given action allowed for the current user
public static isAllowedAction ( string $action = null, string $module = null ) : boolean
$action string The action to check for.
$module string The module wherein the action is located.
return boolean
    public static function isAllowedAction($action = null, $module = null)
    {
        $alwaysAllowed = self::getAlwaysAllowed();
        // The url should only be taken from the container if the action and or module isn't set
        // This way we can use the command also in the a console command
        $action = $action !== null ? (string) $action : BackendModel::get('url')->getAction();
        $module = \SpoonFilter::toCamelCase($module !== null ? (string) $module : BackendModel::get('url')->getModule());
        // is this action an action that doesn't require authentication?
        if (isset($alwaysAllowed[$module][$action])) {
            return true;
        }
        // users that aren't logged in can only access always allowed items
        if (!self::isLoggedIn()) {
            return false;
        }
        // get modules
        $modules = BackendModel::getModules();
        // module exists and God user is enough to be allowed
        if (in_array($module, $modules) && self::getUser()->isGod()) {
            return true;
        }
        $allowedActions = self::getAllowedActions();
        // do we know a level for this action
        if (isset($allowedActions[$module][$action])) {
            // is the level greater than zero? aka: do we have access?
            if ((int) $allowedActions[$module][$action] > 0) {
                return true;
            }
        }
        // fallback
        return false;
    }

Usage Example

Example #1
0
 /**
  * Loads the dataGrids
  */
 private function loadDatagrids()
 {
     // load all categories
     $categories = BackendFaqModel::getCategories(true);
     // loop categories and create a dataGrid for each one
     foreach ($categories as $categoryId => $categoryTitle) {
         $dataGrid = new BackendDataGridDB(BackendFaqModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $categoryId));
         $dataGrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop'));
         $dataGrid->setColumnsHidden(array('category_id', 'sequence'));
         $dataGrid->addColumn('dragAndDropHandle', null, '<span>' . BL::lbl('Move') . '</span>');
         $dataGrid->setColumnsSequence('dragAndDropHandle');
         $dataGrid->setColumnAttributes('question', array('class' => 'title'));
         $dataGrid->setColumnAttributes('dragAndDropHandle', array('class' => 'dragAndDropHandle'));
         $dataGrid->setRowAttributes(array('id' => '[id]'));
         // check if this action is allowed
         if (BackendAuthentication::isAllowedAction('Edit')) {
             $dataGrid->setColumnURL('question', BackendModel::createURLForAction('Edit') . '&amp;id=[id]');
             $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('Edit') . '&amp;id=[id]', BL::lbl('Edit'));
         }
         // add dataGrid to list
         $this->dataGrids[] = array('id' => $categoryId, 'title' => $categoryTitle, 'content' => $dataGrid->getContent());
     }
     // set empty datagrid
     $this->emptyDatagrid = new BackendDataGridArray(array(array('dragAndDropHandle' => '', 'question' => BL::msg('NoQuestionInCategory'), 'edit' => '')));
     $this->emptyDatagrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop emptyGrid'));
     $this->emptyDatagrid->setHeaderLabels(array('edit' => null, 'dragAndDropHandle' => null));
 }
All Usage Examples Of Backend\Core\Engine\Authentication::isAllowedAction