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:
Sari
2026-08-03 09:12:46 +07:00
parent 6f430f35d7
commit 2dda08bb8d
11 changed files with 576 additions and 0 deletions
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('point_audit_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('student_id');
$table->unsignedBigInteger('violation_id')->nullable();
$table->string('action', 20); // created | deleted | adjusted
$table->integer('points_before')->default(0);
$table->integer('points_after')->default(0);
$table->integer('points_delta')->default(0); // bertanda (+ / -)
$table->string('description')->nullable();
$table->json('metadata')->nullable(); // snapshot data saat aksi
$table->unsignedBigInteger('actor_id')->nullable();
$table->string('ip_address', 45)->nullable();
$table->timestamps();
$table->foreign('student_id')->references('id')->on('students')->cascadeOnDelete();
$table->foreign('violation_id')->references('id')->on('violations')->nullOnDelete();
$table->foreign('actor_id')->references('id')->on('users')->nullOnDelete();
$table->index(['student_id', 'created_at']);
$table->index('action');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('point_audit_logs');
}
};
@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Permission baru: view-point-audit (Riwayat Perubahan Poin).
*/
public function up(): void
{
$now = now();
DB::table('permissions')->insert([
'key' => 'view-point-audit',
'group' => 'master-data',
'label' => 'Lihat Riwayat Perubahan Poin',
'description' => 'Melihat audit log penambahan/pengurangan poin siswa',
'created_at' => $now,
'updated_at' => $now,
]);
$permissionId = DB::table('permissions')->where('key', 'view-point-audit')->value('id');
// BK & Waka Kesiswaan (waka disetarakan dengan BK)
foreach (['bk', 'waka_kesiswaan'] as $role) {
DB::table('role_permissions')->insert([
'role' => $role,
'permission_id' => $permissionId,
'created_at' => $now,
'updated_at' => $now,
]);
}
}
public function down(): void
{
$permissionId = DB::table('permissions')->where('key', 'view-point-audit')->value('id');
DB::table('role_permissions')->where('permission_id', $permissionId)->delete();
DB::table('permissions')->where('key', 'view-point-audit')->delete();
}
};