示例#1
0
 public function execute($user, $item, $params)
 {
     /**@var Users $current_user
      */
     $current_user = Yii::$app->user->identity;
     if (!Yii::$app->user->isGuest) {
         $role = $current_user->role;
         if (isset(RbacController::getRoleHierarchy()[$item->name]) || array_key_exists($item->name, RbacController::getRoleHierarchy())) {
             return RbacController::generateRoleCondition($item->name, $role);
         }
     }
     return false;
 }
示例#2
0
 public static function generateRoleCondition($role, $checking_role)
 {
     $parent_role = isset(RbacController::getRoleHierarchy()[$role]) || array_key_exists($role, RbacController::getRoleHierarchy()) ? RbacController::getRoleHierarchy()[$role] : null;
     if (!is_null($parent_role)) {
         if (is_array($parent_role)) {
             $condition = false;
             foreach ($parent_role as $c_parent_role) {
                 $condition = $condition || self::generateRoleCondition($c_parent_role, $checking_role);
                 $condition = $condition || $role == $checking_role;
             }
         } else {
             $condition = self::generateRoleCondition($parent_role, $checking_role);
             $condition = $condition || $role == $checking_role;
         }
     } else {
         $condition = $role == $checking_role;
     }
     return $condition;
 }