Backup Perbaikan
This commit is contained in:
@@ -312,7 +312,7 @@ class PengajuanAbsenController extends Controller
|
||||
], 500);
|
||||
}
|
||||
|
||||
if ($request->hasFile('file_lampiran')) {
|
||||
if ($request->kategori == 2 && $request->hasFile('file_lampiran')) {
|
||||
$namaFileLampiran = uniqid().'-'.$pegawai->nip.'-lampiran.pdf';
|
||||
$filePathLampiran = $request->file('file_lampiran')->storeAs("absen/presensi/$periode", $namaFileLampiran, 'public');
|
||||
|
||||
|
||||
@@ -34,14 +34,10 @@ class VerifikasiAbsenController extends Controller
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'state' => 'unauthorized',
|
||||
'message' => 'Tautan ini tidak valid, sudah kedaluwarsa, atau Anda bukan atasan dari pegawai pemohon.',
|
||||
], 403);
|
||||
if (is_array($otorisasi)) {
|
||||
return $this->responseTidakBerwenang($otorisasi['reason']);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
@@ -60,15 +56,14 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
if (is_array($otorisasi)) {
|
||||
return $this->responseTidakBerwenang($otorisasi['reason']);
|
||||
}
|
||||
|
||||
$nipAtasan = $otorisasi;
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
}
|
||||
@@ -97,7 +92,7 @@ class VerifikasiAbsenController extends Controller
|
||||
Log::error("Gagal mengunggah dokumen tertandatangani ke Google Drive untuk pengajuan #$id");
|
||||
}
|
||||
|
||||
if (! $this->proses($pengajuan, 'Diterima', null, $nipAtasan)) {
|
||||
if (! $this->proses($pengajuan, 'Diterima', null, $nipAtasan, (string) $request->input('token'))) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menyetujui pengajuan absen. Silakan coba lagi.',
|
||||
@@ -120,20 +115,19 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
if (is_array($otorisasi)) {
|
||||
return $this->responseTidakBerwenang($otorisasi['reason']);
|
||||
}
|
||||
|
||||
$nipAtasan = $otorisasi;
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
}
|
||||
|
||||
if (! $this->proses($pengajuan, 'Ditolak', $request->catatan, $nipAtasan)) {
|
||||
if (! $this->proses($pengajuan, 'Ditolak', $request->catatan, $nipAtasan, (string) $request->input('token'))) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
||||
@@ -206,24 +200,48 @@ class VerifikasiAbsenController extends Controller
|
||||
return $pengajuan->created_at?->copy()->addDays(self::BATAS_HARI_VERIFIKASI)->isPast() ?? false;
|
||||
}
|
||||
|
||||
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|false
|
||||
/**
|
||||
* @return string|array{reason: string} Nip atasan kalau berhasil, atau array alasan gagal.
|
||||
*/
|
||||
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|array
|
||||
{
|
||||
$nip = $request->input('nip');
|
||||
$expires = $request->input('expires');
|
||||
$signature = $request->input('signature');
|
||||
$token = $request->input('token');
|
||||
|
||||
if (! $this->linkService->verify($pengajuan->id, $nip, $expires, $signature)) {
|
||||
return false;
|
||||
$hasil = $this->linkService->verify($pengajuan->id, $token);
|
||||
|
||||
if (! $hasil['ok']) {
|
||||
return ['reason' => $hasil['reason']];
|
||||
}
|
||||
|
||||
if (! $this->dawaiService->isAtasanDari($nip, $pengajuan->nip)) {
|
||||
return false;
|
||||
if (! $this->dawaiService->isAtasanDari($hasil['nip'], $pengajuan->nip)) {
|
||||
return ['reason' => 'invalid'];
|
||||
}
|
||||
|
||||
return $nip;
|
||||
return $hasil['nip'];
|
||||
}
|
||||
|
||||
private function proses(PengajuanPresensi $pengajuan, string $status, ?string $catatan, string $nipAtasan): bool
|
||||
private function responseTidakBerwenang(string $reason): JsonResponse
|
||||
{
|
||||
return match ($reason) {
|
||||
'link_expired' => response()->json([
|
||||
'success' => false,
|
||||
'state' => 'link_expired',
|
||||
'message' => 'Tautan verifikasi ini sudah kedaluwarsa.',
|
||||
], 403),
|
||||
'session_expired' => response()->json([
|
||||
'success' => false,
|
||||
'state' => 'session_expired',
|
||||
'message' => 'Sesi verifikasi ini sudah lewat 5 menit sejak tautan dibuka. Silakan minta tautan verifikasi baru.',
|
||||
], 403),
|
||||
default => response()->json([
|
||||
'success' => false,
|
||||
'state' => 'unauthorized',
|
||||
'message' => 'Tautan ini tidak valid, sudah kedaluwarsa, atau Anda bukan atasan dari pegawai pemohon.',
|
||||
], 403),
|
||||
};
|
||||
}
|
||||
|
||||
private function proses(PengajuanPresensi $pengajuan, string $status, ?string $catatan, string $nipAtasan, string $token): bool
|
||||
{
|
||||
$atasan = Pegawai::withoutGlobalScopes()->where('nip', $nipAtasan)->first();
|
||||
$verifikatorRole = 'Atasan (via WhatsApp)';
|
||||
@@ -255,6 +273,8 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
DB::commit();
|
||||
|
||||
$this->linkService->markUsed($pengajuan->id, $token);
|
||||
|
||||
$pengajuan->refresh()->load('notes');
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user