Compare commits

..

4 Commits

Author SHA1 Message Date
arbi c10cdf39ca Merge pull request 'Revert "Perbaikan API WA" dan "Perbaikan Generate Token Baru"' (#27) from development into main
Reviewed-on: #27
2026-09-27 16:34:04 +07:00
Ariyutta 6672f34adc Revert "Perbaikan API WA" dan "Perbaikan Generate Token Baru"
Mengembalikan fitur verifikasi presensi via WhatsApp ke kondisi semula
sebelum perubahan mekanisme regenerasi token sesi.

This reverts commit 1d58c66a7a.
This reverts commit dcf57bcfdc.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 16:32:21 +07:00
arbi 70c796d230 Merge pull request 'Perbaikan API WA' (#26) from development into main
Reviewed-on: #26
2026-09-27 16:10:27 +07:00
Ariyutta 1d58c66a7a Perbaikan API WA 2026-09-27 16:09:37 +07:00
3 changed files with 18 additions and 40 deletions
@@ -34,9 +34,9 @@ class VerifikasiAbsenController extends Controller
{
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
$otorisasi = $this->otorisasiAtasan($request, $pengajuan, renewSesi: true);
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
@@ -44,7 +44,6 @@ class VerifikasiAbsenController extends Controller
'success' => true,
'state' => $this->resolveState($pengajuan),
'data' => $this->formatPengajuan($pengajuan),
'new_token' => $otorisasi['new_token'],
]);
}
@@ -59,11 +58,11 @@ class VerifikasiAbsenController extends Controller
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
$nipAtasan = $otorisasi['nip'];
$nipAtasan = $otorisasi;
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
return $gagal;
@@ -118,11 +117,11 @@ class VerifikasiAbsenController extends Controller
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
if (! $otorisasi['ok']) {
if (is_array($otorisasi)) {
return $this->responseTidakBerwenang($otorisasi['reason']);
}
$nipAtasan = $otorisasi['nip'];
$nipAtasan = $otorisasi;
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
return $gagal;
@@ -202,23 +201,23 @@ class VerifikasiAbsenController extends Controller
}
/**
* @return array{ok: bool, nip: ?string, reason: ?string, new_token: ?string}
* @return string|array{reason: string} Nip atasan kalau berhasil, atau array alasan gagal.
*/
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan, bool $renewSesi = false): array
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|array
{
$token = $request->input('token');
$hasil = $this->linkService->verify($pengajuan->id, $token, $renewSesi);
$hasil = $this->linkService->verify($pengajuan->id, $token);
if (! $hasil['ok']) {
return ['ok' => false, 'nip' => null, 'reason' => $hasil['reason'], 'new_token' => null];
return ['reason' => $hasil['reason']];
}
if (! $this->dawaiService->isAtasanDari($hasil['nip'], $pengajuan->nip)) {
return ['ok' => false, 'nip' => null, 'reason' => 'invalid', 'new_token' => null];
return ['reason' => 'invalid'];
}
return ['ok' => true, 'nip' => $hasil['nip'], 'reason' => null, 'new_token' => $hasil['new_token']];
return $hasil['nip'];
}
private function responseTidakBerwenang(string $reason): JsonResponse
+5 -19
View File
@@ -44,15 +44,11 @@ class VerifikasiAbsenLinkService
}
/**
* @param bool $renewSesi Saat true dan sesi sudah lewat 5 menit, token lama akan digantikan dengan
* token baru (bukan langsung ditolak). Dipakai saat tautan dibuka ulang dari
* WhatsApp (klik tombol "Tinjau Pengajuan"), supaya tidak perlu membuat
* pengajuan baru hanya untuk mendapatkan token baru.
* @return array{ok: bool, nip: ?string, reason: ?string, new_token: ?string}
* @return array{ok: bool, nip: ?string, reason: ?string}
*/
public function verify(int $pengajuanId, ?string $token, bool $renewSesi = false): array
public function verify(int $pengajuanId, ?string $token): array
{
$gagal = fn (string $reason) => ['ok' => false, 'nip' => null, 'reason' => $reason, 'new_token' => null];
$gagal = fn (string $reason) => ['ok' => false, 'nip' => null, 'reason' => $reason];
if (! $token) {
return $gagal('invalid');
@@ -71,23 +67,13 @@ class VerifikasiAbsenLinkService
return $gagal('link_expired');
}
$tokenBaru = null;
if ($row->first_accessed_at === null) {
$row->update(['first_accessed_at' => now()]);
} elseif (now()->greaterThan($row->first_accessed_at->copy()->addMinutes(self::SESI_MENIT))) {
if (! $renewSesi) {
return $gagal('session_expired');
}
$tokenBaru = Str::random(40);
$row->update([
'token' => $this->hash($tokenBaru),
'first_accessed_at' => now(),
]);
return $gagal('session_expired');
}
return ['ok' => true, 'nip' => $row->nip, 'reason' => null, 'new_token' => $tokenBaru];
return ['ok' => true, 'nip' => $row->nip, 'reason' => null];
}
public function markUsed(int $pengajuanId, string $token): void
@@ -210,7 +210,7 @@
<script>
const pengajuanId = {{ (int) $id }};
let token = new URLSearchParams(window.location.search).get('token');
const token = new URLSearchParams(window.location.search).get('token');
const apiBase = "{{ url('/api/v1/verifikasi-absen') }}/" + pengajuanId;
function showNotification(status, title, text) {
@@ -288,13 +288,6 @@
url: `${apiBase}?token=${encodeURIComponent(token)}`,
method: 'GET',
success: function (res) {
if (res.new_token) {
token = res.new_token;
const url = new URL(window.location.href);
url.searchParams.set('token', token);
window.history.replaceState({}, '', url);
}
tampilkanDetail(res.data, res.state);
selesaiLoading();
},