feat: Implement Kosma selection and role management in general settings, refine Kosma permissions, and update the default semester value.
This commit is contained in:
parent
747ea2ca9a
commit
43bafef4cd
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages\System;
|
namespace App\Filament\Pages\System;
|
||||||
|
|
||||||
|
use App\Enums\RoleEnum;
|
||||||
use App\Filament\Support\SystemNotification;
|
use App\Filament\Support\SystemNotification;
|
||||||
|
use App\Models\Student;
|
||||||
|
use App\Models\User;
|
||||||
use App\Settings\GeneralSettings;
|
use App\Settings\GeneralSettings;
|
||||||
use BackedEnum;
|
use BackedEnum;
|
||||||
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
||||||
@ -59,6 +62,15 @@ public function form(Schema $schema): Schema
|
|||||||
->native(false)
|
->native(false)
|
||||||
->required()
|
->required()
|
||||||
->helperText('Tentukan semester yang sedang aktif saat ini. Semester ini akan digunakan untuk menyaring data yang relevan.'),
|
->helperText('Tentukan semester yang sedang aktif saat ini. Semester ini akan digunakan untuk menyaring data yang relevan.'),
|
||||||
|
|
||||||
|
Select::make('kosma_id')
|
||||||
|
->label('Kosma')
|
||||||
|
->placeholder('Pilih Mahasiswa sebagai Kosma')
|
||||||
|
->options(Student::query()->pluck('full_name', 'id'))
|
||||||
|
->searchable()
|
||||||
|
->preload()
|
||||||
|
->native(false)
|
||||||
|
->helperText('Pilih mahasiswa yang bertanggung jawab sebagai Kosma (Ketua Kelas).'),
|
||||||
])
|
])
|
||||||
->columns(2)
|
->columns(2)
|
||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
@ -69,4 +81,20 @@ public function getSavedNotification(): ?Notification
|
|||||||
{
|
{
|
||||||
return SystemNotification::update();
|
return SystemNotification::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function afterSave(): void
|
||||||
|
{
|
||||||
|
$settings = app(GeneralSettings::class);
|
||||||
|
$kosmaId = $settings->kosma_id;
|
||||||
|
|
||||||
|
User::role('Kosma')->get()->each(fn (User $user) => $user->removeRole('Kosma'));
|
||||||
|
|
||||||
|
if ($kosmaId) {
|
||||||
|
$student = Student::find($kosmaId);
|
||||||
|
|
||||||
|
if ($student?->user) {
|
||||||
|
$student->user->assignRole(RoleEnum::Kosma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ class GeneralSettings extends Settings
|
|||||||
{
|
{
|
||||||
public int $current_semester;
|
public int $current_semester;
|
||||||
|
|
||||||
|
public ?int $kosma_id;
|
||||||
|
|
||||||
public static function group(): string
|
public static function group(): string
|
||||||
{
|
{
|
||||||
return 'general';
|
return 'general';
|
||||||
|
|||||||
@ -167,32 +167,10 @@ public function run(): void
|
|||||||
"name": "Kosma",
|
"name": "Kosma",
|
||||||
"guard_name": "web",
|
"guard_name": "web",
|
||||||
"permissions" : [
|
"permissions" : [
|
||||||
"ViewAny:Student",
|
|
||||||
"View:Student",
|
|
||||||
|
|
||||||
"ViewAny:Lecturer",
|
|
||||||
"View:Lecturer",
|
|
||||||
|
|
||||||
"ViewAny:Course",
|
|
||||||
"View:Course",
|
|
||||||
|
|
||||||
"ViewAny:CourseSchedule",
|
|
||||||
"View:CourseSchedule",
|
|
||||||
|
|
||||||
"ViewAny:Assignment",
|
|
||||||
"View:Assignment",
|
|
||||||
|
|
||||||
"ViewAny:Attendance",
|
|
||||||
"View:Attendance",
|
|
||||||
"Create:Attendance",
|
"Create:Attendance",
|
||||||
"Update:Attendance",
|
"Update:Attendance",
|
||||||
"Delete:Attendance",
|
"Delete:Attendance",
|
||||||
|
|
||||||
"ViewAny:Material",
|
|
||||||
"View:Material",
|
|
||||||
|
|
||||||
"ViewAny:StudyGroup",
|
|
||||||
"View:StudyGroup",
|
|
||||||
"Create:StudyGroup",
|
"Create:StudyGroup",
|
||||||
"Update:StudyGroup",
|
"Update:StudyGroup",
|
||||||
"Delete:StudyGroup"
|
"Delete:StudyGroup"
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
{
|
{
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
$this->migrator->add('general.current_semester', 1);
|
$this->migrator->add('general.current_semester', 4);
|
||||||
|
$this->migrator->add('general.kosma_id', null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user