rbac/AuthHelper.php
public static function canUserRunAction($actionUid, $user = null)
    {
        if (empty($user)) $user = Yii::$app->user;

        $parts = explode('/', $actionUid);
        if ($parts === false || count($parts) < 3) {
            throw new Exception("Illegal action uniqueId format: '{$actionUid}'");
        } else {
            $actionId = array_pop($parts);
            $controllerId = array_pop($parts);
            $moduleUid = implode ('/', $parts);

            $module = Yii::$app->getModule($moduleUid);
            if (empty($module)) {
                //throw new Exception("Can't get module '{$moduleUid}'");
                return false;
            } else {
                $controller = $module->createControllerByID($controllerId);
                if ($controller instanceof YiiBaseController) {
                    //static::$_modulesControllers[$moduleUid][$controllerId] = $controller::className();
                    $behaviors = $controller->behaviors();
                    if (empty($behaviors['access']['rules'])) {
                        $rules = [];
                    } else {
                        $rules = $behaviors['access']['rules'];
                    }
                    //static::$_accessRules[$moduleUid][$controllerId] = $rules;
                } else {
                    throw new Exception("Illegal controller '{$controllerId}' in module '{$moduleUid}'");
                }
            }

            if (empty($rules)) {
                $result = true; // no rules - action allow
            } else {
                $ac = Yii::createObject(['class' => AccessControl::className(), 'user' => $user, 'rules' => $rules]);
                $action = $controller->createAction($actionId);
                $request = Yii::$app->getRequest();
                $result = false; // if rule(s) exists - deny by default
                foreach ($ac->rules as $rule) {
                    if ($rule->allows($action, $user, $request)) {
                        $result = true; // found allow rule
                        break;
                    }
                }
            }

            return $result;
        }
    }
public static function canUserRunAction($actionUid, $user = null)
    {
        if (empty($user)) $user = Yii::$app->user;

        $parts = explode('/', $actionUid);
        if ($parts === false || count($parts) < 3) {
            throw new Exception("Illegal action uniqueId format: '{$actionUid}'");
        } else {
            $actionId = array_pop($parts);
            $controllerId = array_pop($parts);
            $moduleUid = implode ('/', $parts);

            $module = Yii::$app->getModule($moduleUid);
            if (empty($module)) {
                //throw new Exception("Can't get module '{$moduleUid}'");
                return false;
            } else {
                $controller = $module->createControllerByID($controllerId);
                if ($controller instanceof YiiBaseController) {
                    //static::$_modulesControllers[$moduleUid][$controllerId] = $controller::className();
                    $behaviors = $controller->behaviors();
                    if (empty($behaviors['access']['rules'])) {
                        $rules = [];
                    } else {
                        $rules = $behaviors['access']['rules'];
                    }
                    //static::$_accessRules[$moduleUid][$controllerId] = $rules;
                } else {
                    throw new Exception("Illegal controller '{$controllerId}' in module '{$moduleUid}'");
                }
            }

            if (empty($rules)) {
                $result = true; // no rules - action allow
            } else {
                $ac = Yii::createObject(['class' => AccessControl::className(), 'user' => $user, 'rules' => $rules]);
                $action = $controller->createAction($actionId);
                $request = Yii::$app->getRequest();
                $result = false; // if rule(s) exists - deny by default
                foreach ($ac->rules as $rule) {
                    if ($rule->allows($action, $user, $request)) {
                        $result = true; // found allow rule
                        break;
                    }
                }
            }

            return $result;
        }
    }
public static function canUserRunAction ( $ actionUid , $ user = null ) { if ( empty ( $ user ) ) $ user = Yii :: $ app -> user ; $ parts = explode ( '/' , $ actionUid ) ; if ( $ parts === false || count ( $ parts ) < 3 ) { throw new Exception ( "Illegal action uniqueId format: '{$actionUid}'" ) ; } else { $ actionId = array_pop ( $ parts ) ; $ controllerId = array_pop ( $ parts ) ; $ moduleUid = implode ( '/' , $ parts ) ; $ module = Yii :: $ app -> getModule ( $ moduleUid ) ; if ( empty ( $ module ) ) { //throw new Exception("Can't get module '{$moduleUid}'"); return false ; } else { $ controller = $ module -> createControllerByID ( $ controllerId ) ; if ( $ controller instanceof YiiBaseController ) { //static::$_modulesControllers[$moduleUid][$controllerId] = $controller::className(); $ behaviors = $ controller -> behaviors ( ) ; if ( empty ( $ behaviors [ 'access' ] [ 'rules' ] ) ) { $ rules = [ ] ; } else { $ rules = $ behaviors [ 'access' ] [ 'rules' ] ; } //static::$_accessRules[$moduleUid][$controllerId] = $rules; } else { throw new Exception ( "Illegal controller '{$controllerId}' in module '{$moduleUid}'" ) ; } } if ( empty ( $ rules ) ) { $ result = true ; // no rules - action allow } else { $ ac = Yii :: createObject ( [ 'class' => AccessControl :: className ( ) , 'user' => $ user , 'rules' => $ rules ] ) ; $ action = $ controller -> createAction ( $ actionId ) ; $ request = Yii :: $ app -> getRequest ( ) ; $ result = false ; // if rule(s) exists - deny by default foreach ( $ ac -> rules as $ rule ) { if ( $ rule -> allows ( $ action , $ user , $ request ) ) { $ result = true ; // found allow rule break ; } } } return $ result ; } }
Check if user can run action.
@param string $actionUid action uniqueId
@param yii\web\User $user application user
@return boolean
Check if user can run action .