hasFull($user) ? self::FULL : self::SIMPLE; } public function maySwitch(?object $user): bool { return $user !== null && config('manager.simple_view') && ($this->hasFull($user) || Gate::forUser($user)->allows('manager.switch')); } /** * @param list $allowed the permissions this account has * @return list */ public function for(?object $user, array $allowed): array { if ($user === null) { return []; } $simple = $this->view($user) === self::SIMPLE; $items = []; foreach ($this->modules->navigation() as $item) { if (($item['permission'] ?? null) !== null && ! in_array($item['permission'], $allowed, true)) { continue; } if ($simple && ! $item['simple']) { continue; } $items[] = array_filter([ 'label' => $simple ? ($item['simple_label'] ?? $item['label']) : $item['label'], 'href' => isset($item['route']) ? route($item['route'], $item['params'] ?? [], false) : (string) $item['url'], // The simple face is a short flat list: headings are for the full face. 'section' => $simple ? null : ($item['section'] ?? null), 'hint' => $item['hint'] ?? null, 'icon' => $item['icon'] ?? null, 'new_tab' => ($item['new_tab'] ?? false) ?: null, ], fn ($value) => $value !== null); } return $items; } private function hasFull(object $user): bool { return (method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin()) || Gate::forUser($user)->allows('manager.full'); } }