feat: granular permissions, export backup, user/role management
- 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:
@@ -17,7 +17,7 @@ class AvgProcessingTimeWidget extends BaseWidget
|
||||
->whereNotNull('assigned_to')
|
||||
->whereNotNull('updated_at');
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -33,27 +33,38 @@ class AvgProcessingTimeWidget extends BaseWidget
|
||||
|
||||
$escalatedCount = (clone $query)->where('is_escalated', true)->count();
|
||||
|
||||
$avgDisplay = $avgMinutes ? round($avgMinutes) . ' min' : 'N/A';
|
||||
$avgDescription = $avgMinutes
|
||||
? 'Avg time from creation to resolution'
|
||||
: 'No resolved tickets yet';
|
||||
|
||||
return [
|
||||
Stat::make('Resolved Tickets', (string) $totalResolved)
|
||||
->description('Total resolved/closed tickets')
|
||||
->color('success'),
|
||||
->descriptionIcon('heroicon-m-check-circle')
|
||||
->color('success')
|
||||
->chart([7, 3, 4, 5, 6, 8, $totalResolved]),
|
||||
|
||||
Stat::make('Avg Processing Time', $avgMinutes ? round($avgMinutes) . ' min' : 'N/A')
|
||||
->description('Average time from creation to resolution')
|
||||
->color('warning'),
|
||||
Stat::make('Avg Processing Time', $avgDisplay)
|
||||
->description($avgDescription)
|
||||
->descriptionIcon('heroicon-m-clock')
|
||||
->color('info'),
|
||||
|
||||
Stat::make('Pending Tickets', (string) $totalPending)
|
||||
->description('Still in progress')
|
||||
->color('danger'),
|
||||
->descriptionIcon('heroicon-m-arrow-path')
|
||||
->color('warning')
|
||||
->chart([3, 5, 4, 6, 5, 4, $totalPending]),
|
||||
|
||||
Stat::make('Escalated', (string) $escalatedCount)
|
||||
->description('Tickets marked as escalated')
|
||||
->color('gray'),
|
||||
->descriptionIcon('heroicon-m-exclamation-triangle')
|
||||
->color('danger'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
|
||||
return auth()->user()?->hasPermissionTo('view-dashboard-widgets') ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class ResolvedTicketsWidget extends BaseWidget
|
||||
Feedback::query()
|
||||
->where('status', 'resolved')
|
||||
->when(
|
||||
auth()->user()->hasRole('manager'),
|
||||
auth()->user()->hasRole('manager') && ! auth()->user()->hasRole('admin'),
|
||||
function ($q) {
|
||||
$deptIds = Department::where('manager_id', auth()->id())->pluck('id');
|
||||
return $q->whereIn('current_department_id', $deptIds);
|
||||
@@ -30,30 +30,47 @@ class ResolvedTicketsWidget extends BaseWidget
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->weight('bold')
|
||||
->color('primary'),
|
||||
|
||||
TextColumn::make('title')
|
||||
->label('Ticket')
|
||||
->searchable()
|
||||
->url(fn (Feedback $record): string => FeedbackResource::getUrl('edit', ['record' => $record])),
|
||||
->weight('semibold')
|
||||
->url(fn (Feedback $record): string => FeedbackResource::getUrl('edit', ['record' => $record]))
|
||||
->color('primary'),
|
||||
|
||||
TextColumn::make('customer.name')
|
||||
->label('Customer')
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('customerProduct.product.name')
|
||||
->label('Product')
|
||||
->placeholder('General'),
|
||||
|
||||
TextColumn::make('assignedTo.name')
|
||||
->label('Handler'),
|
||||
|
||||
TextColumn::make('currentDepartment.name')
|
||||
->label('Department'),
|
||||
->label('Department')
|
||||
->badge()
|
||||
->color('info'),
|
||||
|
||||
TextColumn::make('updated_at')
|
||||
->label('Resolved Date')
|
||||
->dateTime('d/m/Y')
|
||||
->sortable(),
|
||||
->label('Resolved')
|
||||
->since()
|
||||
->sortable()
|
||||
->color('secondary'),
|
||||
])
|
||||
->defaultSort('updated_at', 'desc')
|
||||
->heading('Tickets Awaiting Closure (Resolved)')
|
||||
->description('Tickets that have been resolved and are pending manager review for closure.');
|
||||
->heading('Tickets Awaiting Closure')
|
||||
->description('Tickets that have been resolved and are pending manager review for closure.')
|
||||
->paginated([5]);
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->hasRole(['admin', 'manager']) ?? false;
|
||||
return auth()->user()?->hasPermissionTo('view-dashboard-widgets') ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user