feat: Plan 2 — Form Edit Rumah Ibadah & Keluarga Miskin + Ownership
- Add user_id FK (nullable) to rumah_ibadah for ownership tracking - IbadahController: set user_id on store; enforce ownership on update/destroy - Add edit modals to map and data views (ibadah + miskin) - Popup and table row Edit buttons with per-record ownership check - 7 new tests covering ownership and full-field updates - Fix ExampleTest for auth-protected routes - Fix UserFactory missing email_verified_at column - Mark Plan 2 complete in missing_features.md; update README Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,12 +16,18 @@ class IbadahController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nama' => 'required|string',
|
||||
'alamat' => 'required|string',
|
||||
'jenis' => 'nullable|string',
|
||||
'alamat' => 'nullable|string',
|
||||
'latitude' => 'required|numeric',
|
||||
'longitude' => 'required|numeric',
|
||||
'radius' => 'nullable|integer',
|
||||
'jumlah_jemaah' => 'nullable|integer',
|
||||
'pengurus' => 'nullable|string',
|
||||
'telepon' => 'nullable|string',
|
||||
'keterangan' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['user_id'] = auth()->id();
|
||||
$ibadah = RumahIbadah::create($validated);
|
||||
return response()->json(['success' => true, 'data' => $ibadah]);
|
||||
}
|
||||
@@ -29,12 +35,22 @@ class IbadahController extends Controller
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$ibadah = RumahIbadah::findOrFail($id);
|
||||
|
||||
if (!auth()->user()->hasRole('administrator') && $ibadah->user_id !== auth()->id()) {
|
||||
return response()->json(['message' => 'Tidak diizinkan mengubah data ini.'], 403);
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'nama' => 'required|string',
|
||||
'alamat' => 'required|string',
|
||||
'jenis' => 'nullable|string',
|
||||
'alamat' => 'nullable|string',
|
||||
'latitude' => 'required|numeric',
|
||||
'longitude' => 'required|numeric',
|
||||
'radius' => 'required|integer',
|
||||
'jumlah_jemaah' => 'nullable|integer',
|
||||
'pengurus' => 'nullable|string',
|
||||
'telepon' => 'nullable|string',
|
||||
'keterangan' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$ibadah->update($validated);
|
||||
@@ -44,6 +60,11 @@ class IbadahController extends Controller
|
||||
public function destroy($id)
|
||||
{
|
||||
$ibadah = RumahIbadah::findOrFail($id);
|
||||
|
||||
if (!auth()->user()->hasRole('administrator') && $ibadah->user_id !== auth()->id()) {
|
||||
return response()->json(['message' => 'Tidak diizinkan menghapus data ini.'], 403);
|
||||
}
|
||||
|
||||
$ibadah->delete();
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user