fix: draft kegiatan hanya terlihat oleh kreator dan super_admin, hanya ketua yang bisa approve, hilangkan field status dari form, default status draft
This commit is contained in:
@@ -19,15 +19,6 @@ class ActivityForm
|
||||
Textarea::make('description')->label('Deskripsi')->rows(3)->columnSpanFull(),
|
||||
DatePicker::make('start_date')->label('Mulai')->required(),
|
||||
DatePicker::make('end_date')->label('Selesai')->required(),
|
||||
Select::make('status')
|
||||
->options([
|
||||
'draft' => 'Draft',
|
||||
'pending' => 'Pending',
|
||||
'approved' => 'Disetujui',
|
||||
'rejected' => 'Ditolak',
|
||||
])
|
||||
->default('draft')
|
||||
->required(),
|
||||
Select::make('participants')
|
||||
->label('Peserta')
|
||||
->relationship('participants', 'name')
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Activities\Tables;
|
||||
|
||||
use App\Models\Activity;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
@@ -15,6 +16,14 @@ class ActivitiesTable
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->modifyQueryUsing(function ($query) {
|
||||
if (! auth()->user()->hasRole('super_admin')) {
|
||||
$query->where(fn ($q) => $q
|
||||
->where('status', '!=', 'draft')
|
||||
->orWhere('created_by', auth()->id())
|
||||
);
|
||||
}
|
||||
})
|
||||
->columns([
|
||||
TextColumn::make('title')->label('Judul')->searchable()->sortable(),
|
||||
TextColumn::make('start_date')->label('Mulai')->date('d M Y')->sortable(),
|
||||
@@ -50,7 +59,8 @@ class ActivitiesTable
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $record->status === 'pending')
|
||||
->visible(fn ($record) => $record->status === 'pending'
|
||||
&& auth()->user()->hasAnyRole(['ketua', 'super_admin']))
|
||||
->action(fn ($record) => $record->update([
|
||||
'status' => 'approved',
|
||||
'approved_by' => auth()->id(),
|
||||
@@ -61,7 +71,8 @@ class ActivitiesTable
|
||||
->icon('heroicon-o-x-circle')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->visible(fn ($record) => $record->status === 'pending')
|
||||
->visible(fn ($record) => $record->status === 'pending'
|
||||
&& auth()->user()->hasAnyRole(['ketua', 'super_admin']))
|
||||
->action(fn ($record) => $record->update(['status' => 'rejected'])),
|
||||
])
|
||||
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
||||
|
||||
@@ -21,6 +21,14 @@ class Activity extends Model
|
||||
'executed_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (Activity $activity) {
|
||||
$activity->created_by ??= auth()->id();
|
||||
$activity->status ??= 'draft';
|
||||
});
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
|
||||
@@ -19,6 +19,9 @@ class ActivityPolicy
|
||||
|
||||
public function view(AuthUser $authUser, Activity $activity): bool
|
||||
{
|
||||
if ($activity->status === 'draft' && $activity->created_by !== $authUser->id) {
|
||||
return $authUser->hasRole('super_admin');
|
||||
}
|
||||
return $authUser->can('View:Activity');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user