浏览代码

fix: authorization

父节点
当前提交
89a4580db4

+ 0
- 1
app/Http/Controllers/CustomerController.php 查看文件

2
 
2
 
3
 namespace App\Http\Controllers;
3
 namespace App\Http\Controllers;
4
 
4
 
5
-use App\Models\Sale;
6
 use App\Models\Customer;
5
 use App\Models\Customer;
7
 use App\Http\Requests\Customer\StoreCustomerRequest;
6
 use App\Http\Requests\Customer\StoreCustomerRequest;
8
 use App\Http\Requests\Customer\UpdateCustomerRequest;
7
 use App\Http\Requests\Customer\UpdateCustomerRequest;

+ 10
- 0
app/Http/Controllers/PurchaseController.php 查看文件

16
 use App\Http\Requests\Purchase\StorePurchaseRequest;
16
 use App\Http\Requests\Purchase\StorePurchaseRequest;
17
 use App\Http\Requests\Purchase\UpdatePurchaseRequest;
17
 use App\Http\Requests\Purchase\UpdatePurchaseRequest;
18
 use App\Models\Company;
18
 use App\Models\Company;
19
+use App\Models\User;
20
+use App\Policies\PurchasePolicy;
19
 use App\Services\FunctionService;
21
 use App\Services\FunctionService;
20
 use App\Services\PurchaseService;
22
 use App\Services\PurchaseService;
21
 
23
 
330
 
332
 
331
     public function invoice(Purchase $purchase)
333
     public function invoice(Purchase $purchase)
332
     {
334
     {
335
+        $this->authorize("viewAny", Purchase::class);
336
+
333
         $ppn = Ppn::first()->ppn;
337
         $ppn = Ppn::first()->ppn;
334
 
338
 
335
         $company = Company::first();
339
         $company = Company::first();
344
 
348
 
345
     public function deliveryOrder(Purchase $purchase)
349
     public function deliveryOrder(Purchase $purchase)
346
     {
350
     {
351
+        $this->authorize("viewAny", Purchase::class);
352
+
347
         $company = Company::first();
353
         $company = Company::first();
348
 
354
 
349
         $pdf = Pdf::loadView(
355
         $pdf = Pdf::loadView(
358
 
364
 
359
     public function report()
365
     public function report()
360
     {
366
     {
367
+        $this->authorize("viewAny", User::class);
368
+
361
         return inertia("Purchases/Report", [
369
         return inertia("Purchases/Report", [
362
             "initialFilters" => request()->only(
370
             "initialFilters" => request()->only(
363
                 "start_date",
371
                 "start_date",
385
 
393
 
386
     public function reportExcel()
394
     public function reportExcel()
387
     {
395
     {
396
+        $this->authorize("viewAny", User::class);
397
+
388
         return new PurchaseDetailsExport([
398
         return new PurchaseDetailsExport([
389
             "purchases" => PurchaseDetail::filter(
399
             "purchases" => PurchaseDetail::filter(
390
                 request()->only("start_date", "end_date", "status")
400
                 request()->only("start_date", "end_date", "status")

+ 8
- 0
app/Http/Controllers/SalesController.php 查看文件

206
 
206
 
207
     public function invoice(Sale $sale)
207
     public function invoice(Sale $sale)
208
     {
208
     {
209
+        $this->authorize("viewAny", Sale::class);
210
+
209
         $ppn = Ppn::first()->ppn;
211
         $ppn = Ppn::first()->ppn;
210
 
212
 
211
         $company = Company::first();
213
         $company = Company::first();
220
 
222
 
221
     public function deliveryOrder(Sale $sale)
223
     public function deliveryOrder(Sale $sale)
222
     {
224
     {
225
+        $this->authorize("viewAny", Sale::class);
226
+
223
         $company = Company::first();
227
         $company = Company::first();
224
 
228
 
225
         $pdf = Pdf::loadView("PDF.Sales.Do", compact("sale", "company"));
229
         $pdf = Pdf::loadView("PDF.Sales.Do", compact("sale", "company"));
231
 
235
 
232
     public function report()
236
     public function report()
233
     {
237
     {
238
+        $this->authorize("viewAny", User::class);
239
+
234
         return inertia("Sales/Report", [
240
         return inertia("Sales/Report", [
235
             "initialFilters" => request()->only("start_date", "end_date"),
241
             "initialFilters" => request()->only("start_date", "end_date"),
236
             "sales" => SaleDetail::filter(
242
             "sales" => SaleDetail::filter(
254
 
260
 
255
     public function reportExcel()
261
     public function reportExcel()
256
     {
262
     {
263
+        $this->authorize("viewAny", User::class);
264
+
257
         return new SaleDetailsExport([
265
         return new SaleDetailsExport([
258
             "sales" => SaleDetail::filter(
266
             "sales" => SaleDetail::filter(
259
                 request()->only("start_date", "end_date")
267
                 request()->only("start_date", "end_date")

+ 2
- 0
app/Http/Controllers/SettingController.php 查看文件

15
      */
15
      */
16
     public function index()
16
     public function index()
17
     {
17
     {
18
+        $this->authorize("viewAny", User::class);
19
+
18
         return inertia("Settings/Index", [
20
         return inertia("Settings/Index", [
19
             "ppn" => Ppn::first(),
21
             "ppn" => Ppn::first(),
20
             "company" => Company::first(),
22
             "company" => Company::first(),

+ 0
- 94
app/Policies/ReportPolicy.php 查看文件

1
-<?php
2
-
3
-namespace App\Policies;
4
-
5
-use App\Models\Report;
6
-use App\Models\User;
7
-use Illuminate\Auth\Access\HandlesAuthorization;
8
-
9
-class ReportPolicy
10
-{
11
-    use HandlesAuthorization;
12
-
13
-    /**
14
-     * Determine whether the user can view any models.
15
-     *
16
-     * @param  \App\Models\User  $user
17
-     * @return \Illuminate\Auth\Access\Response|bool
18
-     */
19
-    public function viewAny(User $user)
20
-    {
21
-        return $user->role_id === 1;
22
-    }
23
-
24
-    /**
25
-     * Determine whether the user can view the model.
26
-     *
27
-     * @param  \App\Models\User  $user
28
-     * @param  \App\Models\Report  $report
29
-     * @return \Illuminate\Auth\Access\Response|bool
30
-     */
31
-    public function view(User $user, Report $report)
32
-    {
33
-        return $user->role_id === 1;
34
-    }
35
-
36
-    /**
37
-     * Determine whether the user can create models.
38
-     *
39
-     * @param  \App\Models\User  $user
40
-     * @return \Illuminate\Auth\Access\Response|bool
41
-     */
42
-    public function create(User $user)
43
-    {
44
-        return $user->role_id === 1;
45
-    }
46
-
47
-    /**
48
-     * Determine whether the user can update the model.
49
-     *
50
-     * @param  \App\Models\User  $user
51
-     * @param  \App\Models\Report  $report
52
-     * @return \Illuminate\Auth\Access\Response|bool
53
-     */
54
-    public function update(User $user, Report $report)
55
-    {
56
-        return $user->role_id === 1;
57
-    }
58
-
59
-    /**
60
-     * Determine whether the user can delete the model.
61
-     *
62
-     * @param  \App\Models\User  $user
63
-     * @param  \App\Models\Report  $report
64
-     * @return \Illuminate\Auth\Access\Response|bool
65
-     */
66
-    public function delete(User $user, Report $report)
67
-    {
68
-        return $user->role_id === 1;
69
-    }
70
-
71
-    /**
72
-     * Determine whether the user can restore the model.
73
-     *
74
-     * @param  \App\Models\User  $user
75
-     * @param  \App\Models\Report  $report
76
-     * @return \Illuminate\Auth\Access\Response|bool
77
-     */
78
-    public function restore(User $user, Report $report)
79
-    {
80
-        //
81
-    }
82
-
83
-    /**
84
-     * Determine whether the user can permanently delete the model.
85
-     *
86
-     * @param  \App\Models\User  $user
87
-     * @param  \App\Models\Report  $report
88
-     * @return \Illuminate\Auth\Access\Response|bool
89
-     */
90
-    public function forceDelete(User $user, Report $report)
91
-    {
92
-        //
93
-    }
94
-}

+ 18
- 1
app/Providers/AuthServiceProvider.php 查看文件

2
 
2
 
3
 namespace App\Providers;
3
 namespace App\Providers;
4
 
4
 
5
+use App\Models\Customer;
6
+use App\Models\Product;
7
+use App\Models\Purchase;
8
+use App\Models\StockProduct;
9
+use App\Models\Supplier;
5
 use App\Models\User;
10
 use App\Models\User;
11
+use App\Policies\CustomerPolicy;
12
+use App\Policies\ProductPolicy;
13
+use App\Policies\PurchasePolicy;
14
+use App\Policies\SalePolicy;
15
+use App\Policies\StockProductPolicy;
16
+use App\Policies\SupplierPolicy;
6
 use App\Policies\UserPolicy;
17
 use App\Policies\UserPolicy;
7
 use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
18
 use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
8
 
19
 
15
      */
26
      */
16
     protected $policies = [
27
     protected $policies = [
17
         // Class::class => ClassPolicy::class,
28
         // Class::class => ClassPolicy::class,
18
-        User::class => UserPolicy::class
29
+        Customer::class => CustomerPolicy::class,
30
+        Product::class => ProductPolicy::class,
31
+        Purchase::class => PurchasePolicy::class,
32
+        Sale::class => SalePolicy::class,
33
+        StockProduct::class => StockProductPolicy::class,
34
+        Supplier::class => SupplierPolicy::class,
35
+        User::class => UserPolicy::class,
19
     ];
36
     ];
20
 
37
 
21
     /**
38
     /**