feat: granular permissions, export backup, user/role management
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled

- PermissionSeeder: 29 permissions with role mapping (admin/manager/staff)
- Policies updated to use hasPermissionTo() instead of hasRole()
- ExportBackup command: JSON per-table backup with chunk processing
- UserResource: CRUD users with role assignment (admin only)
- RoleResource: CRUD roles with permission assignment (admin only)
- UserPolicy + RolePolicy: admin-only access control
- ImportCskh: detailed skip logging with color in dry-run mode
- Widgets: permission-based visibility checks
- Tests: 8/8 pass (21 assertions)
This commit is contained in:
2026-05-02 04:47:10 +00:00
parent 7c5055075b
commit 3a8db5cae6
40 changed files with 1804 additions and 440 deletions

View File

@@ -10,6 +10,8 @@ class HandlerPerformanceWidget extends ChartWidget
{
protected ?string $heading = 'Avg Processing Time by Handler';
protected ?string $description = 'Average time from ticket creation to resolution, broken down by handler.';
protected int|string|array $columnSpan = 'full';
protected function getType(): string
@@ -25,7 +27,7 @@ class HandlerPerformanceWidget extends ChartWidget
->whereIn('status', ['resolved', 'closed'])
->whereNotNull('assigned_to');
if ($user->hasRole('manager')) {
if ($user->hasRole('manager') && ! $user->hasRole('admin')) {
$deptIds = Department::where('manager_id', $user->id)->pluck('id');
$query->whereIn('current_department_id', $deptIds);
}
@@ -40,12 +42,37 @@ class HandlerPerformanceWidget extends ChartWidget
$labels = $handlers->map(fn ($h) => $h->assignedTo?->name ?? 'Unknown')->toArray();
$data = $handlers->map(fn ($h) => round($h->avg_minutes, 1))->toArray();
// Generate gradient colors based on performance
$maxMinutes = max($data) ?: 1;
$colors = collect($data)->map(function ($minutes) use ($maxMinutes) {
$ratio = $minutes / $maxMinutes;
if ($ratio > 0.8) {
return 'rgba(220, 38, 38, 0.8)'; // Red for slow
} elseif ($ratio > 0.5) {
return 'rgba(217, 119, 6, 0.8)'; // Amber for medium
}
return 'rgba(26, 86, 219, 0.8)'; // Blue for fast
})->toArray();
$borderColors = collect($data)->map(function ($minutes) use ($maxMinutes) {
$ratio = $minutes / $maxMinutes;
if ($ratio > 0.8) {
return 'rgb(220, 38, 38)';
} elseif ($ratio > 0.5) {
return 'rgb(217, 119, 6)';
}
return 'rgb(26, 86, 219)';
})->toArray();
return [
'datasets' => [
[
'label' => 'Avg Time (minutes)',
'data' => $data,
'backgroundColor' => '#3b82f6',
'backgroundColor' => $colors,
'borderColor' => $borderColors,
'borderWidth' => 1,
'borderRadius' => 6,
],
],
'labels' => $labels,
@@ -54,6 +81,6 @@ class HandlerPerformanceWidget extends ChartWidget
public static function canView(): bool
{
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
return auth()->user()?->hasPermissionTo('view-dashboard-widgets') ?? false;
}
}