A free open source IT asset/license management system
Moved calendar icon, added new gate
snipe116866872a6c
diff --git a/app/Http/Controllers/Api/CalendarEventsController.php b/app/Http/Controllers/Api/CalendarEventsController.phpindex 1c9a254b95..761b007d1a 100644--- a/app/Http/Controllers/Api/CalendarEventsController.php+++ b/app/Http/Controllers/Api/CalendarEventsController.php@@ -54,7 +54,7 @@ class CalendarEventsController extends Controllerpublic function index(Request $request): JsonResponse{- $this->authorizeAnySource($request);+ $this->authorizeAnySource();[$rangeStart, $rangeEnd] = $this->resolveRange($request);$eventTypes = $this->resolveEventTypes($request);@@ -84,20 +84,12 @@ class CalendarEventsController extends Controller/*** Base gate: viewer must be able to view AT LEAST ONE registered- * HasCalendarEvents source model. Source list comes from- * CalendarEvent::sourceModels() so a new adopter of the trait is- * picked up automatically. Per-row policy checks inside+ * HasCalendarEvents source model. Per-row policy checks inside* buildEvents() handle the actual event-level scoping.*/- protected function authorizeAnySource(Request $request): void+ protected function authorizeAnySource(): void{- $viewer = $request->user();- foreach (CalendarEvent::sourceModels() as $sourceClass) {- if ($viewer?->can('view', $sourceClass)) {- return;- }- }- abort(403);+ $this->authorize('canViewUsersAndCheckoutables');}/**diff --git a/app/Http/Controllers/CalendarEventsController.php b/app/Http/Controllers/CalendarEventsController.phpindex ab8c2eaf26..e6a9d40ecb 100644--- a/app/Http/Controllers/CalendarEventsController.php+++ b/app/Http/Controllers/CalendarEventsController.php@@ -2,14 +2,13 @@namespace App\Http\Controllers;-use App\Models\CalendarEvent;use Illuminate\Contracts\View\View;use Illuminate\Http\Request;/*** Renders the unified calendar page. The heavy lifting (event* fetching, source hydration, per-row access checks) happens on the- * companion API endpoint at /api/v1/calendar/events; this controller+ * companion API endpoint at /api/v1/calendar/events. This controller* just gates page access and returns the shell blade that the* FullCalendar JS bundle mounts into.*/@@ -17,22 +16,7 @@ class CalendarEventsController extends Controller{public function index(Request $request): View{- // Base gate mirrors the API endpoint (Api\CalendarEventsController):- // viewer must be able to view AT LEAST ONE registered- // HasCalendarEvents source model. Source list comes from- // CalendarEvent::sourceModels() so a new adopter of the- // trait picks up here automatically. Per-row scoping happens- // inside the API endpoint, so a license-only admin lands- // here and gets only their license events on the calendar.- $viewer = $request->user();- $canViewAnySource = false;- foreach (CalendarEvent::sourceModels() as $sourceClass) {- if ($viewer?->can('view', $sourceClass)) {- $canViewAnySource = true;- break;- }- }- abort_unless($canViewAnySource, 403);+ $this->authorize('canViewUsersAndCheckoutables');return view('calendar.index');}diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.phpindex 1dddc8e154..8e0755484b 100644--- a/app/Providers/AuthServiceProvider.php+++ b/app/Providers/AuthServiceProvider.php@@ -5,6 +5,7 @@ namespace App\Providers;use App\Models\Accessory;use App\Models\Asset;use App\Models\AssetModel;+use App\Models\CalendarEvent;use App\Models\Category;use App\Models\CheckoutRequest;use App\Models\Company;@@ -222,6 +223,24 @@ class AuthServiceProvider extends ServiceProvider|| $user->can('checkout', License::class);});+ // True when the user can view at least one HasCalendarEvents+ // adopter. Named for the underlying question ("does this user+ // have any read access to fleet items or people?") rather+ // than a specific surface, so it reads sensibly for the+ // calendar sidenav gate + any future consumer that wants to+ // check the same shape. Delegates to+ // CalendarEvent::sourceModels() so a new adopter of the+ // HasCalendarEvents trait is picked up automatically.+ Gate::define('canViewUsersAndCheckoutables', function ($user) {+ foreach (CalendarEvent::sourceModels() as $sourceClass) {+ if ($user->can('view', $sourceClass)) {+ return true;+ }+ }++ return false;+ });+Gate::define('assets.view.encrypted_custom_fields', function ($user) {if ($user->hasAccess('assets.view.encrypted_custom_fields')) {return true;diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.phpindex 804462d22e..227fd80f18 100644--- a/resources/views/layouts/default.blade.php+++ b/resources/views/layouts/default.blade.php@@ -565,14 +565,7 @@</li>@endif- @can('view', \App\Models\Asset::class)- <li{!! (request()->routeIs('calendar.index') ? ' class="active" aria-current="page"' : '') !!}>- <a href="{{ route('calendar.index') }}">- <x-icon type="calendar" class="fa-fw"/>- <span>{{ trans('general.calendar') }}</span>- </a>- </li>- @endcan+@can('view', \App\Models\License::class)<li{!! (request()->is('licenses*') ? ' class="active" aria-current="page"' : '') !!}><a href="{{ route('licenses.index') }}">@@ -662,6 +655,14 @@</ul></li>@endcan+ @can('canViewUsersAndCheckoutables')+ <li{!! (request()->routeIs('calendar.index') ? ' class="active" aria-current="page"' : '') !!}>+ <a href="{{ route('calendar.index') }}">+ <x-icon type="calendar" class="fa-fw"/>+ <span>{{ trans('general.calendar') }}</span>+ </a>+ </li>+ @endcan@can('import')<li id="import-sidenav-option"{!! (request()->is('import*') ? ' class="active" aria-current="page"' : '') !!}><a href="{{ route('imports.index') }}">