Update Seeder, Add Partials Menu and Update Permission access name

This commit is contained in:
Daeng Deni Mardaeni 2023-06-08 15:12:23 +07:00
parent ce1c7f4481
commit 61fb6e50be
11 changed files with 234 additions and 50 deletions

View File

@ -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;
}
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -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 !');
}

View File

@ -0,0 +1,121 @@
@canany(['document.read','document.create','document.update','document.delete'])
<!--begin:Menu item-->
<div class="menu-item {{ $route[0] == 'document' ? 'here' : '' }}">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'document' ? 'active' : '' }}" href="{{ route('document.index') }}">
<span class="menu-icon">{!! getIcon('profile-user', 'fs-2') !!}</span>
<span class="menu-title">Document Management</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
@endcanany
@canany(['master.read','master.create','master.update','master.delete','setting.authorize'])
<!--begin:Menu item-->
<div data-kt-menu-trigger="click"
class="menu-item menu-accordion {{ $route[0] == 'directorat' || $route[0] == 'sub-directorat' || $route[0] == 'job' || $route[0] == 'sub-job' || $route[0] == 'sub-sub-job' || $route[0] == 'special-code' || $route[0] == 'document-type' ? 'show' : '' }}">
<!--begin:Menu link-->
<span class="menu-link">
<span class="menu-icon">{!! getIcon('abstract-28', 'fs-2','duotone') !!}</span>
<span class="menu-title">Masters</span>
<span class="menu-arrow"></span>
</span>
<!--end:Menu link-->
<!--begin:Menu sub-->
<div class="menu-sub menu-sub-accordion">
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'directorat' ? 'active' : '' }}"
href="{{ route('directorat.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Direktorat</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'sub-directorat' ? 'active' : '' }}"
href="{{ route('sub-directorat.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Sub Direktorat</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'job' ? 'active' : '' }}" href="{{ route('job.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Pekerjaan</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'sub-job' ? 'active' : '' }}" href="{{ route('sub-job.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Sub Pekerjaan</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'sub-sub-job' ? 'active' : '' }}"
href="{{ route('sub-sub-job.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Sub Sub Pekerjaan</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'special-code' ? 'active' : '' }}"
href="{{ route('special-code.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Kode Khusus</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
<!--begin:Menu item-->
<div class="menu-item">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == 'document-type' ? 'active' : '' }}"
href="{{ route('document-type.index') }}">
<span class="menu-bullet">
<span class="bullet bullet-dot"></span>
</span>
<span class="menu-title">Jenis Dokumen</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
</div>
<!--end:Menu sub-->
</div>
<!--end:Menu item-->
@endcanany

View File

@ -0,0 +1,12 @@
@canany(['setting.read','setting.create','setting.update','setting.delete','setting.authorize'])
<!--begin:Menu item-->
<div class="menu-item {{ $route[0] == "settings" ? "here" : "" }}">
<!--begin:Menu link-->
<a class="menu-link {{ $route[0] == "settings" ? "active" : "" }}" href="{{ route('settings.index') }}">
<span class="menu-icon">{!! getIcon('setting-4', 'fs-2','duotone') !!}</span>
<span class="menu-title">Setting Parameter</span>
</a>
<!--end:Menu link-->
</div>
<!--end:Menu item-->
@endcanany

View File

@ -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);