Example #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;
 }
Example #2
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;
         }
     });
 }