Repository navigation
Fix: Menghapus Jabatan Camat/Sekretaris membuat seluruh aplikasi error 500 - #1809
Merged
Merged
Conversation
…r 500 (#1796) - Tolak penghapusan jabatan inti (Camat/Sekretaris) di JabatanController::destroy - Sebutan Camat/Sekretaris di Controller dan GlobalShareMiddleware memakai Jabatan::sebutan() dengan nilai bawaan agar tidak error saat data hilang - Tambah test regresi feature dan unit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1796
🎯 Deskripsi
Tombol hapus jabatan hanya disembunyikan di UI untuk jabatan Camat dan Sekretaris, tetapi
DELETE /data/jabatan/{id}tidak memeriksa jenis jabatan. Bila jabatan Camat/Sekretaris terhapus (dan tidak sedang dipakai pengurus), konstruktorControllerdanGlobalShareMiddlewaremembacaJabatan::where('jenis', ...)->first()->namatanpa null-safe, sehingga semua halaman (termasuk login) menghasilkan error 500.PR ini:
'Camat'/'Sekretaris'. Lokasi kedua (GlobalShareMiddleware) tidak disebut di issue, tetapi memiliki bug yang sama dan berjalan di setiap request.🛠️ Perubahan yang Dilakukan
1.
app/Models/Jabatan.phpisJabatanInti():trueuntuk jabatan berjenis selainJabatanLainnya.static sebutan(int $jenis, string $default): nama jabatan berdasarkan jenis, atau nilai bawaan bila tidak ada.2.
app/Http/Controllers/Data/JabatanController.phpdestroy()menolak jabatan inti dengan redirect + flasherror; data tidak dihapus.isJabatanInti()agar aturan tidak terduplikasi.public function destroy($id) { + $jabatan = Jabatan::findOrFail($id); + + if ($jabatan->isJabatanInti()) { + return redirect()->route('data.jabatan.index')->with('error', 'Jabatan ' . $jabatan->nama . ' tidak dapat dihapus karena merupakan jabatan inti!'); + } + try { - Jabatan::findOrFail($id)->delete(); + $jabatan->delete();3.
app/Http/Controllers/Controller.php&app/Http/Middleware/GlobalShareMiddleware.php4. Test
tests/Feature/Controllers/Data/JabatanControllerTest.php(baru)tests/Unit/Models/JabatanTest.php(baru)✅ Test Cases yang Diimplementasikan
isJabatanInti()dansebutan()(ada data / fallback).Sebelum perbaikan, 3 feature test regresi gagal dengan
Attempt to read property "nama" on null in app/Http/Controllers/Controller.php:111. Setelah perbaikan seluruhnya lolos:📸 Cara Menjalankan Uji Coba Manual
DELETE /data/jabatan/{id_camat}(mis. via DevTools dengan_token).🤖 Generated with Claude Code