public function allowUpdateRole()
 {
     if (Acl::isGuard()) {
         $authUser = AclUser::find(Auth::id());
         if (!in_array($this->role_type, $authUser->user_types)) {
             return false;
         }
     }
     return true;
 }
 public function getPermission($resource, array $ids = [])
 {
     $result = new AclPermission($resource);
     if ($ids) {
         $result = $result->newSubPermission($ids);
     }
     $authUser = AclUser::find(Auth::id());
     $roles = $this->getRoles($authUser->roles, [], [$resource]);
     foreach ($roles as $role) {
         $permissions = $role->permissions->keyBy('resource');
         if (isset($permissions[$resource])) {
             $result = $result->mergePermission($permissions[$resource]->newSubPermission($ids));
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 public function getAuthUser()
 {
     $auth_user = NULL;
     if (!Auth::id()) {
         return $auth_user;
     }
     if ($this->use_cache) {
         $auth_user_cached_time = Cache::get($this->cache_prefix . '_mt_authUser_' . Auth::id(), null);
         $role_mt = Cache::get($this->cache_prefix . '_last_role_update', null);
         if ($auth_user_cached_time && $role_mt && $role_mt->compare($auth_user_cached_time)) {
             $auth_user = Cache::get($this->cache_prefix . '_authUser_' . Auth::id());
         }
     }
     if (!$auth_user) {
         $auth_user = AclUser::findWithPermissions(Auth::id());
         if ($this->use_cache) {
             Cache::forever($this->cache_prefix . '_authUser_' . Auth::id(), $auth_user);
             Cache::forever($this->cache_prefix . '_mt_authUser_' . Auth::id(), new MicrotimeDate());
         }
     }
     return $auth_user;
 }