diff --git a/app/Models/User.php b/app/Models/User.php index 7c6910e2b..ef26f2d75 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -427,6 +427,40 @@ final class User extends Authenticatable ]); } + /** + * Get all pending stacked role changes for this user. + * Returns an array of stacked role changes that haven't been activated yet (effective_date is in the future). + * + * @return \Illuminate\Support\Collection + */ + public function getAllPendingStackedRoles(): \Illuminate\Support\Collection + { + // Get all stacked role changes from history where effective_date is in the future + $stackedHistory = UserRoleHistory::where('user_id', $this->id) + ->where('is_stacked', true) + ->where('effective_date', '>', now()) + ->orderBy('effective_date', 'asc') + ->get(); + + return $stackedHistory->map(function ($history) { + $role = Role::find($history->new_role_id); + return [ + 'role' => $role, + 'role_name' => $role?->name ?? 'Unknown Role', + 'start_date' => $history->effective_date, + 'end_date' => $history->new_expiry_date, + 'is_current_pending' => $this->pending_roles_id === $history->new_role_id + && $this->pending_role_start_date?->equalTo($history->effective_date), + ]; + }); + } + /** * Get comprehensive role expiry information. * diff --git a/resources/views/admin/users/edit.blade.php b/resources/views/admin/users/edit.blade.php index 82e71833d..4e049ef0b 100644 --- a/resources/views/admin/users/edit.blade.php +++ b/resources/views/admin/users/edit.blade.php @@ -322,51 +322,117 @@ - @if(!is_array($user) && !empty($user->pending_roles_id) && !empty($user->pending_role_start_date)) -
-
- - - SCHEDULED - + @if(!is_array($user)) + @php + $allPendingRoles = $user->getAllPendingStackedRoles(); + @endphp + @if($allPendingRoles->count() > 0) +
+
+ + + SCHEDULED + +
+ +
+ @foreach($allPendingRoles as $index => $pendingRoleInfo) +
+
+ + {{ $index + 1 }} + + {{ $pendingRoleInfo['role_name'] }} +
+
+
+ + Starts: + + {{ $pendingRoleInfo['start_date']->format('M j, Y g:i A') }} +
+ @if($pendingRoleInfo['end_date']) +
+ + Ends: + + {{ $pendingRoleInfo['end_date']->format('M j, Y g:i A') }} +
+ @endif +
+ Time until activation: + {{ $pendingRoleInfo['start_date']->diffForHumans() }} +
+
+
+ @endforeach +
+ +
+

+ + These roles will automatically activate in sequence as each previous role expires +

+ @if(!empty($user->pending_roles_id)) + + @endif +
- - @php - $pendingRole = \Spatie\Permission\Models\Role::find($user->pending_roles_id); - $pendingStartDate = \Carbon\Carbon::parse($user->pending_role_start_date); - $daysUntilActivation = $pendingStartDate->diffInDays(now()); - @endphp - -
-
- Will change to: - {{ $pendingRole->name ?? 'Unknown' }} + @elseif(!empty($user->pending_roles_id) && !empty($user->pending_role_start_date)) + {{-- Fallback to old display if no history records but pending_roles_id is set --}} +
+
+ + + SCHEDULED +
-
- Activation date: - {{ $pendingStartDate->format('M j, Y g:i A') }} + + @php + $pendingRole = \Spatie\Permission\Models\Role::find($user->pending_roles_id); + $pendingStartDate = \Carbon\Carbon::parse($user->pending_role_start_date); + $daysUntilActivation = $pendingStartDate->diffInDays(now()); + @endphp + +
+
+ Will change to: + {{ $pendingRole->name ?? 'Unknown' }} +
+
+ Activation date: + {{ $pendingStartDate->format('M j, Y g:i A') }} +
+
+ Time until activation: + {{ $pendingStartDate->diffForHumans() }} +
+
- Time until activation: - {{ $pendingStartDate->diffForHumans() }} +

+ + This role will automatically activate when the current role expires +

+
- -
-

- - This role will automatically activate when the current role expires -

- -
-
+ @endif @endif diff --git a/resources/views/profile/index.blade.php b/resources/views/profile/index.blade.php index f3099d071..5b1ca46fa 100644 --- a/resources/views/profile/index.blade.php +++ b/resources/views/profile/index.blade.php @@ -139,7 +139,50 @@
@endif - @if($user->hasPendingRole()) + @php + $allPendingRoles = $user->getAllPendingStackedRoles(); + @endphp + @if($allPendingRoles->count() > 0) +
+
Pending Role{{ $allPendingRoles->count() > 1 ? 's' : '' }}
+
+
+ @foreach($allPendingRoles as $index => $pendingRoleInfo) +
+
+ + {{ $index + 1 }} + + + {{ $pendingRoleInfo['role_name'] }} + + Scheduled + +
+
+
+ + Starts: {{ $pendingRoleInfo['start_date']->format('M d, Y g:i A') }} + ({{ $pendingRoleInfo['start_date']->diffForHumans() }}) +
+ @if($pendingRoleInfo['end_date']) +
+ + Ends: {{ $pendingRoleInfo['end_date']->format('M d, Y g:i A') }} +
+ @endif +
+
+ @endforeach +
+ + These roles will automatically activate in sequence as each previous role expires +
+
+
+
+ @elseif($user->hasPendingRole()) + {{-- Fallback to old display if no history records but pending_roles_id is set --}}
Pending Role