Selaa lähdekoodia

站管理 站规则 权限修改

ajun 4 vuotta sitten
vanhempi
commit
1108124bc7

+ 5 - 1
app/Http/Controllers/StationRuleBatchController.php

@@ -5,12 +5,12 @@ namespace App\Http\Controllers;
 use App\Components\AsyncResponse;
 use App\Http\Requests\Station\StationRuleBatchRequest;
 use App\Services\OwnerService;
-use App\Station;
 use App\StationRuleBatch;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Contracts\View\Factory;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
+use Illuminate\Support\Facades\Gate;
 use Illuminate\View\View;
 
 
@@ -27,6 +27,7 @@ class StationRuleBatchController extends Controller
      */
     public function index(Request $request,OwnerService $ownerService)
     {
+        if(!Gate::allows('站管理-站规则')){ return redirect(url('/'));  }
         $stationRuleBatches = StationRuleBatch::query()->with('stationType','owner')->orderByDesc('id')->paginate($request['paginate'] ?? 50);
         $owners = $ownerService->getAuthorizedOwners();
         return view('station.rule.index',compact('stationRuleBatches','owners'));
@@ -38,6 +39,7 @@ class StationRuleBatchController extends Controller
      */
     public function storeApi(StationRuleBatchRequest $request)
     {
+        $this->gate('站管理-站规则-编辑');
         $stationRuleBatch = StationRuleBatch::query()->create($request->only(['name','owner_id']));
         $stationRuleBatch->load('stationType','owner');
         $this->success($stationRuleBatch);
@@ -49,6 +51,7 @@ class StationRuleBatchController extends Controller
      */
     public function updateApi(StationRuleBatchRequest $request)
     {
+        $this->gate('站管理-站规则-编辑');
         $stationRuleBatch = StationRuleBatch::query()->whereKey($request['id'])->first();
         $stationRuleBatch->update($request->all());
         $stationRuleBatch->load('stationType','owner');
@@ -57,6 +60,7 @@ class StationRuleBatchController extends Controller
 
     public function destroyApi(Request $request)
     {
+        $this->gate('站管理-站规则-删除');
         StationRuleBatch::query()->whereKey($request['id'])->delete();
         $this->success();
     }

+ 4 - 4
database/migrations/2021_05_19_171047_add_station_rule_batch_author.php

@@ -7,10 +7,10 @@ use Illuminate\Support\Facades\Schema;
 class AddStationRuleBatchAuthor extends Migration
 {
     public $names = [
-        '站管理-规则',
-        '站管理-编辑',
-        '站管理-创建',
-        '站管理-删除',
+        '站管理-规则',
+        '站管理-站规则-编辑',
+        '站管理-站规则-创建',
+        '站管理-站规则-删除',
     ];
     /**
      * Run the migrations.

+ 2 - 2
resources/views/station/menu.blade.php

@@ -10,9 +10,9 @@
                 <li class="nav-item">
                     <a target="station/cachingShelf/index" class="nav-link" href="{{url('station/cachingShelf/index')}}" :class="{active:isActive('cachingShelf',2)}">缓存架</a>
                 </li> @endcan
-            @can('站管理-规则')
+            @can('站管理-规则')
                 <li class="nav-item">
-                    <a target="station/rule/index" class="nav-link" href="{{url('station/rule/index')}}" :class="{active:isActive('rule','2')}">规则</a>
+                    <a target="station/rule/index" class="nav-link" href="{{url('station/rule/index')}}" :class="{active:isActive('rule','2')}">规则</a>
                 </li>
             @endcan
         </ul>

+ 2 - 2
resources/views/station/rule/_table.blade.php

@@ -38,8 +38,8 @@
                 @{{ stationRuleBatch.batch_type ? stationRuleBatch.batch_type :'无'}}
             </td>
             <td>
-                @can('站管理-编辑')<button class="btn btn-sm btn-outline-primary" @click="editStationRuleBatch(stationRuleBatch,i)">编辑</button>@endcan
-                @can('站管理-删除')<button class="btn btn-sm btn-outline-danger" @click="deleteStationRuleBatch(stationRuleBatch,i)">删除</button>@endcan
+                @can('站管理-站规则-编辑')<button class="btn btn-sm btn-outline-primary" @click="editStationRuleBatch(stationRuleBatch,i)">编辑</button>@endcan
+                @can('站管理-站规则-删除')<button class="btn btn-sm btn-outline-danger" @click="deleteStationRuleBatch(stationRuleBatch,i)">删除</button>@endcan
             </td>
         </tr>
     </template>

+ 2 - 2
resources/views/station/rule/index.blade.php

@@ -1,6 +1,6 @@
 @extends('layouts.app')
 
-@section('title','规则')
+@section('title','规则')
 
 @section('content')
     <span id="nav2">
@@ -8,7 +8,7 @@
         @component('station.rule.menu')@endcomponent
     </span>
     <div class="container-fluid d-none" id="list">
-        @can('站管理-创建')
+        @can('站管理-站规则-创建')
             <button class="btn btn-md btn-outline-primary ml-1" @click="createStationRuleBatch">创建</button>
         @endcan
         @include('station.rule._table')