feat: tambah role koordinator dengan akses buat/edit/hapus kegiatan milik sendiri
This commit is contained in:
@@ -36,7 +36,20 @@ class UserForm
|
||||
->columnSpanFull(),
|
||||
DatePicker::make('last_activity_date')->label('Terakhir Aktif'),
|
||||
Select::make('roles')->relationship('roles', 'name')
|
||||
->multiple()->preload()->label('Role'),
|
||||
->multiple()->preload()->label('Role')
|
||||
->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
|
||||
->options(function () {
|
||||
$user = auth()->user();
|
||||
$query = \Spatie\Permission\Models\Role::query()
|
||||
->whereNotIn('name', ['super_admin', 'panel_user']);
|
||||
|
||||
// Hanya ketua (AssignKoordinator) yang bisa assign role koordinator
|
||||
if (! $user->can('AssignKoordinator')) {
|
||||
$query->where('name', '!=', 'koordinator');
|
||||
}
|
||||
|
||||
return $query->pluck('name', 'id');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,8 +233,9 @@ return [
|
||||
*/
|
||||
|
||||
'custom_permissions' => [
|
||||
'ViewDraft:Activity', // Lihat kegiatan berstatus draft milik user lain (hanya super_admin)
|
||||
'Publish:Post', // Publish / unpublish artikel (editor)
|
||||
'ViewDraft:Activity', // Lihat kegiatan berstatus draft milik user lain (hanya super_admin)
|
||||
'Publish:Post', // Publish / unpublish artikel (editor)
|
||||
'AssignKoordinator', // Assign/cabut role koordinator ke anggota (hanya ketua)
|
||||
],
|
||||
|
||||
/*
|
||||
|
||||
@@ -13,7 +13,7 @@ class PermissionSeeder extends Seeder
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
// Buat roles jika belum ada
|
||||
foreach (['super_admin', 'ketua', 'bendahara', 'pengurus', 'anggota', 'auditor', 'editor'] as $role) {
|
||||
foreach (['super_admin', 'ketua', 'bendahara', 'pengurus', 'anggota', 'auditor', 'editor', 'koordinator'] as $role) {
|
||||
Role::firstOrCreate(['name' => $role, 'guard_name' => 'web']);
|
||||
}
|
||||
|
||||
@@ -29,12 +29,25 @@ class PermissionSeeder extends Seeder
|
||||
$anggota = Role::findByName('anggota');
|
||||
$auditor = Role::findByName('auditor');
|
||||
$editor = Role::findByName('editor');
|
||||
$koordinator = Role::findByName('koordinator');
|
||||
|
||||
$ketua->syncPermissions(Permission::where('name', 'not like', '%Role%')
|
||||
->where('name', 'not like', '%Permission%')
|
||||
->where('name', '!=', 'ViewDraft:Activity')
|
||||
->get());
|
||||
|
||||
// Pastikan ketua punya AssignKoordinator
|
||||
if ($p = Permission::where('name', 'AssignKoordinator')->first()) {
|
||||
$ketua->givePermissionTo($p);
|
||||
}
|
||||
|
||||
$koordinator->syncPermissions(Permission::whereIn('name', [
|
||||
'ViewAny:Activity', 'View:Activity', 'Create:Activity', 'Update:Activity', 'Delete:Activity',
|
||||
'ViewAny:Vote', 'View:Vote',
|
||||
'ViewAny:Post', 'View:Post', 'Create:Post', 'Update:Post', 'Delete:Post',
|
||||
'ViewAny:MemberPoint', 'View:MemberPoint',
|
||||
])->get());
|
||||
|
||||
$bendahara->syncPermissions(Permission::where('name', 'like', '%CashRecord%')
|
||||
->orWhere('name', 'like', '%CashCategory%')
|
||||
->orWhere('name', 'like', '%MemberDue%')
|
||||
|
||||
Reference in New Issue
Block a user