diff --git a/Database/Seeders/CetakLabelDatabaseSeeder.php b/Database/Seeders/CetakLabelDatabaseSeeder.php index 8ae8092..35e8423 100644 --- a/Database/Seeders/CetakLabelDatabaseSeeder.php +++ b/Database/Seeders/CetakLabelDatabaseSeeder.php @@ -2,8 +2,11 @@ namespace Modules\Cetaklabel\Database\Seeders; - use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Seeder; + use Modules\Usermanager\Entities\PermissionGroup; + use Spatie\Permission\Models\Permission; + use Spatie\Permission\Models\Role; + use Spatie\Permission\PermissionRegistrar; class CetaklabelDatabaseSeeder extends Seeder { @@ -14,10 +17,55 @@ */ public function run() { - Model::unguard(); + app()[PermissionRegistrar::class]->forgetCachedPermissions(); + + $data = $this->data(); + foreach ($data as $value) { + $permission = Permission::updateOrCreate([ + 'name' => $value['name'], + 'guard_name' => 'web' + ], [ + 'permission_group_id' => $value['group'], + ]); + + $role = Role::find(1); + $role->givePermissionTo($permission); + } $this->call([ CetaklabelSeeder::class ]); } + + public function data() + { + $data = []; + // list of model permission + $model = ['master', 'document','setting']; + + foreach ($model as $value) { + $permissionGroup = PermissionGroup::updateOrCreate([ + 'name' => $value + ]); + + foreach ($this->crudActions($value) as $action) { + $data[] = ['name' => $action, 'group' => $permissionGroup->id]; + } + } + + return $data; + } + + public function crudActions($name) + { + $actions = []; + // list of permission actions + $crud = ['create', 'read', 'update', 'delete', 'authorize', 'report']; + + foreach ($crud as $value) { + $actions[] = $name . '.' . $value; + } + + return $actions; + } } diff --git a/Http/Controllers/DirectoratController.php b/Http/Controllers/DirectoratController.php index 5d24c54..d5edcb2 100644 --- a/Http/Controllers/DirectoratController.php +++ b/Http/Controllers/DirectoratController.php @@ -32,7 +32,7 @@ */ public function index(DirectoratDataTable $dataTable, Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -48,7 +48,7 @@ */ public function store(StoreDirectoratRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -74,7 +74,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -88,7 +88,7 @@ */ public function show(Directorat $directorat) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } } @@ -100,7 +100,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -118,7 +118,7 @@ */ public function update(UpdateDirectoratRequest $request, Directorat $directorat) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -150,7 +150,7 @@ */ public function destroy(Directorat $directorat) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/DocumentTypeController.php b/Http/Controllers/DocumentTypeController.php index 82d607c..3ae4562 100644 --- a/Http/Controllers/DocumentTypeController.php +++ b/Http/Controllers/DocumentTypeController.php @@ -28,7 +28,7 @@ */ public function index(DocumentTypeDataTable $dataTable) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -40,7 +40,7 @@ */ public function store(StoreDocumentTypeRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -68,7 +68,7 @@ */ public function create() { - /*if (is_null($this->user) || !$this->user->can('masters.create')) { + /*if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); }*/ @@ -80,7 +80,7 @@ */ public function show(DocumentType $document_type) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -92,7 +92,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -105,7 +105,7 @@ */ public function update(UpdateDocumentTypeRequest $request, DocumentType $document_type) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -133,7 +133,7 @@ */ public function destroy(DocumentType $document_type) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/JobController.php b/Http/Controllers/JobController.php index c2689c8..a3e4a13 100644 --- a/Http/Controllers/JobController.php +++ b/Http/Controllers/JobController.php @@ -34,7 +34,7 @@ */ public function index(JobDataTable $dataTable, Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -59,7 +59,7 @@ */ public function show(Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -86,7 +86,7 @@ */ public function store(StoreJobRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -112,7 +112,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -128,7 +128,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -146,7 +146,7 @@ */ public function update(UpdateJobRequest $request, Job $job) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -176,7 +176,7 @@ */ public function destroy(Job $job) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/SpecialCodeController.php b/Http/Controllers/SpecialCodeController.php index d9807ea..1bf99b9 100644 --- a/Http/Controllers/SpecialCodeController.php +++ b/Http/Controllers/SpecialCodeController.php @@ -27,7 +27,7 @@ */ public function index(SpecialCodeDataTable $dataTable) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -39,7 +39,7 @@ */ public function store(StoreSpecialCodeRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -67,7 +67,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -79,7 +79,7 @@ */ public function show(SpecialCode $special_code) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -91,7 +91,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -104,7 +104,7 @@ */ public function update(UpdateSpecialCodeRequest $request, SpecialCode $special_code) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -132,7 +132,7 @@ */ public function destroy(SpecialCode $special_code) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/SubDirectoratController.php b/Http/Controllers/SubDirectoratController.php index d1823df..054d829 100644 --- a/Http/Controllers/SubDirectoratController.php +++ b/Http/Controllers/SubDirectoratController.php @@ -34,7 +34,7 @@ */ public function index(SubDirectoratDataTable $dataTable, Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -79,7 +79,7 @@ */ public function store(StoreSubDirectoratRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -105,7 +105,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -121,7 +121,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -139,7 +139,7 @@ */ public function update(UpdateSubDirectoratRequest $request, SubDirectorat $subDirectorat) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -169,7 +169,7 @@ */ public function destroy(SubDirectorat $subDirectorat) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/SubJobController.php b/Http/Controllers/SubJobController.php index f3e7b17..f7162f3 100644 --- a/Http/Controllers/SubJobController.php +++ b/Http/Controllers/SubJobController.php @@ -34,7 +34,7 @@ */ public function index(SubJobDataTable $dataTable, Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -58,7 +58,7 @@ */ public function show(Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -85,7 +85,7 @@ */ public function store(StoreSubJobRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -113,7 +113,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -129,7 +129,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -147,7 +147,7 @@ */ public function update(UpdateSubJobRequest $request, SubJob $subJob) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -177,7 +177,7 @@ */ public function destroy(SubJob $subJob) { - if (is_null($this->user) || !$this->user->can('masters.delete')) { + if (is_null($this->user) || !$this->user->can('master.delete')) { abort(403, 'Sorry !! You are Unauthorized to delete any master data !'); } diff --git a/Http/Controllers/SubSubjobController.php b/Http/Controllers/SubSubjobController.php index d8ce7c0..1b45152 100644 --- a/Http/Controllers/SubSubjobController.php +++ b/Http/Controllers/SubSubjobController.php @@ -34,7 +34,7 @@ */ public function index(SubSubJobDataTable $dataTable, Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -58,7 +58,7 @@ */ public function show(Request $request) { - if (is_null($this->user) || !$this->user->can('masters.read')) { + if (is_null($this->user) || !$this->user->can('master.read')) { abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } @@ -85,7 +85,7 @@ */ public function store(StoreSubSubJobRequest $request) { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -112,7 +112,7 @@ */ public function create() { - if (is_null($this->user) || !$this->user->can('masters.create')) { + if (is_null($this->user) || !$this->user->can('master.create')) { abort(403, 'Sorry !! You are Unauthorized to create any master data !'); } @@ -124,7 +124,7 @@ */ public function edit($id) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } @@ -137,7 +137,7 @@ */ public function update(UpdateSubSubJobRequest $request, SubSubJob $subSubJob) { - if (is_null($this->user) || !$this->user->can('masters.update')) { + if (is_null($this->user) || !$this->user->can('master.update')) { abort(403, 'Sorry !! You are Unauthorized to update any master data !'); } diff --git a/Resources/views/partials/menu/_app.blade.php b/Resources/views/partials/menu/_app.blade.php new file mode 100644 index 0000000..f7f2255 --- /dev/null +++ b/Resources/views/partials/menu/_app.blade.php @@ -0,0 +1,121 @@ +@canany(['document.read','document.create','document.update','document.delete']) + + + +@endcanany + +@canany(['master.read','master.create','master.update','master.delete','setting.authorize']) + + + +@endcanany diff --git a/Resources/views/partials/menu/_system.blade.php b/Resources/views/partials/menu/_system.blade.php new file mode 100644 index 0000000..66a17b3 --- /dev/null +++ b/Resources/views/partials/menu/_system.blade.php @@ -0,0 +1,12 @@ +@canany(['setting.read','setting.create','setting.update','setting.delete','setting.authorize']) + + + +@endcanany diff --git a/Routes/web.php b/Routes/web.php index da7e489..8cfcd00 100644 --- a/Routes/web.php +++ b/Routes/web.php @@ -22,7 +22,10 @@ use Modules\Cetaklabel\Http\Controllers\SubJobController; use Modules\Cetaklabel\Http\Controllers\SubSubJobController; - Route::domain('cetaklabel.io')->group(function () { + $module = file_get_contents(dirname(__FILE__, 2) . '/module.json'); + $module = json_decode($module); + + Route::domain($module->domain)->group(function () { Route::group(['middleware' => ['auth', 'verified']], function () { Route::resource('directorat', DirectoratController::class); Route::resource('sub-directorat', SubDirectoratController::class);