Pārlūkot izejas kodu

增加 Permission::registerErrorHandler 方法;
使用 admin_exist 代替 exit

jqh 4 gadi atpakaļ
vecāks
revīzija
9b19ef2cfb

+ 1 - 1
src/Grid/Exporters/ExcelExporter.php

@@ -36,6 +36,6 @@ class ExcelExporter extends AbstractExporter
 
         $exporter->headings($this->titles())->download($filename);
 
-        exit;
+        admin_exit();
     }
 }

+ 23 - 3
src/Http/Auth/Permission.php

@@ -6,10 +6,14 @@ use Dcat\Admin\Admin;
 use Dcat\Admin\Http\Middleware\Pjax;
 use Dcat\Admin\Layout\Content;
 use Dcat\Admin\Models\Role;
+use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Arrayable;
+use Symfony\Component\HttpFoundation\Response;
 
 class Permission
 {
+    protected static $errorHandler;
+
     /**
      * Check permission.
      *
@@ -84,15 +88,21 @@ class Permission
 
     /**
      * Send error response page.
+     *
+     * @throws \Dcat\Admin\Exception\RespondException
      */
     public static function error()
     {
-        if (! request()->pjax() && request()->ajax()) {
+        if ($error = static::$errorHandler) {
+            admin_exit($error());
+        }
+
+        if (Helper::isAjaxRequest()) {
             abort(403, trans('admin.deny'));
         }
 
-        Pjax::respond(
-            response((new Content())->withError(trans('admin.deny')))
+        admin_exit(
+            Content::make()->withError(trans('admin.deny'))
         );
     }
 
@@ -105,4 +115,14 @@ class Permission
     {
         return ! config('admin.permission.enable') || Admin::user()->isRole(Role::ADMINISTRATOR);
     }
+
+    /**
+     * @param \Closure $callback
+     *
+     * @return void
+     */
+    public static function registerErrorHandler(\Closure $callback)
+    {
+        static::$errorHandler = $callback;
+    }
 }

+ 0 - 16
src/Http/Middleware/Pjax.php

@@ -39,22 +39,6 @@ class Pjax
         return $response;
     }
 
-    /**
-     * Send a response through this middleware.
-     *
-     * @param Response $response
-     */
-    public static function respond(Response $response)
-    {
-        $next = function () use ($response) {
-            return $response;
-        };
-
-        (new static())->handle(Request::capture(), $next)->send();
-
-        exit;
-    }
-
     /**
      * Handle Response with exceptions.
      *