fix: policy koordinator hilang, source_type hardcode, validasi executed_at salah kondisi
This commit is contained in:
@@ -59,7 +59,7 @@ class ParticipantsRelationManager extends RelationManager
|
|||||||
if (($data['status'] ?? 'hadir') === 'hadir') {
|
if (($data['status'] ?? 'hadir') === 'hadir') {
|
||||||
$activity = $this->getOwnerRecord();
|
$activity = $this->getOwnerRecord();
|
||||||
MemberPoint::firstOrCreate(
|
MemberPoint::firstOrCreate(
|
||||||
['user_id' => $data['recordId'], 'source_type' => 'activity', 'source_id' => $activity->id],
|
['user_id' => $data['recordId'], 'source_type' => \App\Models\Activity::class, 'source_id' => $activity->id],
|
||||||
['points' => 10, 'reason' => "Hadir di kegiatan: {$activity->title}"]
|
['points' => 10, 'reason' => "Hadir di kegiatan: {$activity->title}"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ class ParticipantsRelationManager extends RelationManager
|
|||||||
->after(function (EditAction $action, $record, array $data) {
|
->after(function (EditAction $action, $record, array $data) {
|
||||||
$activity = $this->getOwnerRecord();
|
$activity = $this->getOwnerRecord();
|
||||||
$existing = MemberPoint::where('user_id', $record->id)
|
$existing = MemberPoint::where('user_id', $record->id)
|
||||||
->where('source_type', 'activity')
|
->where('source_type', \App\Models\Activity::class)
|
||||||
->where('source_id', $activity->id)
|
->where('source_id', $activity->id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ class ParticipantsRelationManager extends RelationManager
|
|||||||
'user_id' => $record->id,
|
'user_id' => $record->id,
|
||||||
'points' => 10,
|
'points' => 10,
|
||||||
'reason' => "Hadir di kegiatan: {$activity->title}",
|
'reason' => "Hadir di kegiatan: {$activity->title}",
|
||||||
'source_type' => 'activity',
|
'source_type' => \App\Models\Activity::class,
|
||||||
'source_id' => $activity->id,
|
'source_id' => $activity->id,
|
||||||
]);
|
]);
|
||||||
} elseif (($data['status'] ?? 'hadir') !== 'hadir' && $existing) {
|
} elseif (($data['status'] ?? 'hadir') !== 'hadir' && $existing) {
|
||||||
@@ -90,7 +90,7 @@ class ParticipantsRelationManager extends RelationManager
|
|||||||
->after(function ($record) {
|
->after(function ($record) {
|
||||||
$activity = $this->getOwnerRecord();
|
$activity = $this->getOwnerRecord();
|
||||||
MemberPoint::where('user_id', $record->id)
|
MemberPoint::where('user_id', $record->id)
|
||||||
->where('source_type', 'activity')
|
->where('source_type', \App\Models\Activity::class)
|
||||||
->where('source_id', $activity->id)
|
->where('source_id', $activity->id)
|
||||||
->delete();
|
->delete();
|
||||||
}),
|
}),
|
||||||
@@ -100,7 +100,7 @@ class ParticipantsRelationManager extends RelationManager
|
|||||||
DetachBulkAction::make()
|
DetachBulkAction::make()
|
||||||
->after(function ($records) {
|
->after(function ($records) {
|
||||||
$activity = $this->getOwnerRecord();
|
$activity = $this->getOwnerRecord();
|
||||||
MemberPoint::where('source_type', 'activity')
|
MemberPoint::where('source_type', \App\Models\Activity::class)
|
||||||
->where('source_id', $activity->id)
|
->where('source_id', $activity->id)
|
||||||
->whereIn('user_id', $records->pluck('id'))
|
->whereIn('user_id', $records->pluck('id'))
|
||||||
->delete();
|
->delete();
|
||||||
|
|||||||
@@ -30,13 +30,6 @@ class ActivityObserver
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($new === 'approved' && $activity->wasChanged('executed_at') && empty($activity->execution_notes)) {
|
|
||||||
Notification::make()->title('Catatan pelaksanaan wajib diisi')
|
|
||||||
->danger()->send();
|
|
||||||
$activity->executed_at = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActivityLog::create([
|
ActivityLog::create([
|
||||||
'user_id' => Auth::id(),
|
'user_id' => Auth::id(),
|
||||||
'action' => 'status_changed',
|
'action' => 'status_changed',
|
||||||
|
|||||||
@@ -29,12 +29,24 @@ class ActivityPolicy
|
|||||||
|
|
||||||
public function update(AuthUser $authUser, Activity $activity): bool
|
public function update(AuthUser $authUser, Activity $activity): bool
|
||||||
{
|
{
|
||||||
return $authUser->can('Update:Activity');
|
if ($authUser->can('Update:Activity')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $authUser->hasRole('koordinator')
|
||||||
|
&& $activity->created_by === $authUser->id
|
||||||
|
&& is_null($activity->approved_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(AuthUser $authUser, Activity $activity): bool
|
public function delete(AuthUser $authUser, Activity $activity): bool
|
||||||
{
|
{
|
||||||
return $authUser->can('Delete:Activity');
|
if ($authUser->can('Delete:Activity')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $authUser->hasRole('koordinator')
|
||||||
|
&& $activity->created_by === $authUser->id
|
||||||
|
&& is_null($activity->approved_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteAny(AuthUser $authUser): bool
|
public function deleteAny(AuthUser $authUser): bool
|
||||||
|
|||||||
Reference in New Issue
Block a user