Ejemplo n.º 1
0
 public static function validateRoute()
 {
     $route = Route::current();
     $route_name = $route->getName();
     if (!$route_name) {
         $route_name = $route->getActionName();
     }
     $params = $route->parametersWithoutNulls();
     $ids = [];
     if ($params) {
         $param = current($params);
         if (is_numeric($param)) {
             $ids[] = $param;
         }
     }
     $result = AclFacade::check($route_name, $ids);
     if (!$result) {
         $error_message = "No Permission for {$route_name}";
         if ($ids) {
             $error_message .= " for id: {$ids[0]}";
         }
         throw new NoPermissionsException($error_message);
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function allowUpdateRole()
 {
     if (Acl::isGuard()) {
         $authUser = AclUser::find(Auth::id());
         if (!in_array($this->role_type, $authUser->user_types)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 public function getPermission($resource, array $ids = [])
 {
     if (in_array($resource, Config::get('acl::allways_allow_resources'))) {
         return new AclPermission($resource, $ids, true);
     }
     $groupResource = GroupResources::getResourceGroup($resource);
     if ($groupResource) {
         $resource = $groupResource;
     }
     $result = new AclPermission($resource);
     if ($ids) {
         $result = $result->newSubPermission($ids);
     }
     $result = AclFacade::applyHook($result, $ids, $this);
     $aclUser = $this;
     if (!isset($this->permissions)) {
         $aclUser = self::findWithPermissions($this->getKey());
     }
     if (isset($aclUser->permissions[$resource])) {
         $result = $aclUser->permissions[$resource];
         if ($ids) {
             $result = $result->newSubPermission($ids);
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 private static function _registerDeletingPermissions()
 {
     static::deleting(function ($model) {
         if (Acl::isGuard()) {
             $class = get_class($model);
             $id = $model[$model->getAclKey()];
             $result = Acl::check($class . '.delete', [$id]);
             if (!$result) {
                 throw new NoPermissionsException("No Permission to delete {$class} id:" . $id);
             }
             return $result;
         }
     });
     static::deleting(function ($model) {
         if (Acl::isGuard()) {
             $result = $this->checkDeletingPermissions($model);
             if (!$result) {
                 $id = $model[$model->getAclKey()];
                 throw new NoPermissionsException("No Permission to delete {$class} id:" . $id);
             }
             return $result;
         }
     });
 }
Ejemplo n.º 5
0
 public function remove()
 {
     if ($this->attributes['default']) {
         throw new NoPermissionsException("You cannot remove default role.");
     }
     if (!isset($this->attributes['role_id']) || !$this->attributes['role_id']) {
         throw new NoPermissionsException("missing role_id");
     }
     /* @var $role_provider  RoleProviders\AclRoleProvider */
     $role_provider = AclFacade::getRoleProvider($this->attributes['type']);
     $result = $role_provider->removeRole($this->attributes['role_id']);
     if ($result) {
         Event::fire('acl_role_removed', array($result));
     }
     return $result;
 }