feat: Implement Kosma selection and role management in general settings, refine Kosma permissions, and update the default semester value.

This commit is contained in:
Yoga Pangestu 2026-03-12 09:27:38 +07:00
parent 747ea2ca9a
commit 43bafef4cd
4 changed files with 32 additions and 23 deletions

View File

@ -2,7 +2,10 @@
namespace App\Filament\Pages\System;
use App\Enums\RoleEnum;
use App\Filament\Support\SystemNotification;
use App\Models\Student;
use App\Models\User;
use App\Settings\GeneralSettings;
use BackedEnum;
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
@ -59,6 +62,15 @@ public function form(Schema $schema): Schema
->native(false)
->required()
->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)
->columnSpanFull(),
@ -69,4 +81,20 @@ public function getSavedNotification(): ?Notification
{
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);
}
}
}
}

View File

@ -8,6 +8,8 @@ class GeneralSettings extends Settings
{
public int $current_semester;
public ?int $kosma_id;
public static function group(): string
{
return 'general';

View File

@ -167,32 +167,10 @@ public function run(): void
"name": "Kosma",
"guard_name": "web",
"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",
"Update:Attendance",
"Delete:Attendance",
"ViewAny:Material",
"View:Material",
"ViewAny:StudyGroup",
"View:StudyGroup",
"Create:StudyGroup",
"Update:StudyGroup",
"Delete:StudyGroup"

View File

@ -6,6 +6,7 @@
{
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);
}
};