feat: two-role system — super_admin & admin program (Fasa 12)
- Replace is_admin boolean with role enum('super_admin','admin') via migration
- ProgramPolicy: admin program can only view/edit/delete own programs
- EnsureIsAdmin: accepts both roles; EnsureSuperAdmin: super_admin only
- UserController + views: super_admin can manage admin accounts
- Sidebar: user management link & role badge gated on isSuperAdmin()
- Fix Controller base class: add AuthorizesRequests trait
- Fix tests: replace nonAdmin() (invalid enum) with adminProgram() against super_admin-only route
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
83
resources/views/admin/users/index.blade.php
Normal file
83
resources/views/admin/users/index.blade.php
Normal file
@@ -0,0 +1,83 @@
|
||||
@extends('layouts.admin')
|
||||
|
||||
@section('title', 'Pengurusan Pengguna')
|
||||
@section('header', 'Pengurusan Pengguna')
|
||||
|
||||
@section('breadcrumb')
|
||||
<li class="breadcrumb-item active">Pengguna</li>
|
||||
@endsection
|
||||
|
||||
@section('header-actions')
|
||||
<a href="{{ route('admin.users.create') }}" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-person-plus me-1"></i> Tambah Pengguna
|
||||
</a>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="card border-0 shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Nama</th>
|
||||
<th>Emel</th>
|
||||
<th>Peranan</th>
|
||||
<th class="text-center">Program</th>
|
||||
<th>Tarikh Daftar</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($users as $user)
|
||||
<tr>
|
||||
<td>
|
||||
<div class="fw-medium">{{ $user->name }}</div>
|
||||
@if($user->id === auth()->id())
|
||||
<span class="badge bg-light text-muted border" style="font-size:.65rem;">Anda</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="small text-muted">{{ $user->email }}</td>
|
||||
<td>
|
||||
@if($user->role === 'super_admin')
|
||||
<span class="badge bg-danger">Super Admin</span>
|
||||
@else
|
||||
<span class="badge bg-primary">Admin Program</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span class="badge bg-secondary">{{ $user->programs_count }}</span>
|
||||
</td>
|
||||
<td class="small text-muted">{{ $user->created_at->format('d/m/Y') }}</td>
|
||||
<td class="text-end">
|
||||
<a href="{{ route('admin.users.edit', $user) }}"
|
||||
class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-pencil"></i>
|
||||
</a>
|
||||
@if($user->id !== auth()->id())
|
||||
<form method="POST" action="{{ route('admin.users.destroy', $user) }}"
|
||||
class="d-inline"
|
||||
onsubmit="return confirm('Padam pengguna {{ addslashes($user->name) }}? Program mereka tidak akan terjejas.')">
|
||||
@csrf @method('DELETE')
|
||||
<button class="btn btn-sm btn-outline-danger">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</form>
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="6" class="text-center py-4 text-muted">Tiada pengguna dijumpai.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if($users->hasPages())
|
||||
<div class="card-footer bg-white">{{ $users->links() }}</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
Reference in New Issue
Block a user