feat: audit log poin — catat pencatatan/penghapusan pelanggaran (sebelum/sesudah/delta, metadata snapshot, actor, IP) + halaman Riwayat Poin (filter, permission view-point-audit) + 4 feature test
This commit is contained in:
@@ -272,6 +272,31 @@ class ViolationController extends Controller
|
||||
|
||||
public function destroy(Violation $violation): RedirectResponse
|
||||
{
|
||||
abort_unless(auth()->user()->canViewStudent($violation->student_id), 403);
|
||||
|
||||
// Audit log perubahan poin (penghapusan pelanggaran)
|
||||
$student = $violation->student;
|
||||
$before = $student->total_points; // termasuk pelanggaran yang akan dihapus
|
||||
$after = max(0, $before - $violation->points);
|
||||
|
||||
\App\Models\PointAuditLog::log(
|
||||
studentId: $violation->student_id,
|
||||
action: \App\Models\PointAuditLog::ACTION_DELETED,
|
||||
pointsBefore: $before,
|
||||
pointsAfter: $after,
|
||||
description: ($violation->violationType?->name ?? 'Pelanggaran').' (dihapus)',
|
||||
metadata: [
|
||||
'violation_date' => $violation->violation_date?->format('Y-m-d'),
|
||||
'description' => $violation->description,
|
||||
'sanction' => $violation->sanction,
|
||||
'location' => $violation->location,
|
||||
'points' => $violation->points,
|
||||
],
|
||||
violationId: $violation->id,
|
||||
actorId: auth()->id(),
|
||||
ipAddress: request()->ip(),
|
||||
);
|
||||
|
||||
$violation->delete();
|
||||
|
||||
return redirect()->route('violations.index')
|
||||
|
||||
Reference in New Issue
Block a user