v0.6.0
This commit is contained in:
commit
a2a48d7ce2
148 files changed
+9946
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\ManagerServiceProvider;
|
||||
use IriksIT\Manager\Models\UserSetting;
|
||||
|
||||
/** What the first page of the screens needs to know: who, what they may do, the menu and the look. */
|
||||
class Shell
|
||||
{
|
||||
public function __construct(private readonly ModuleRegistry $modules, private readonly Themes $themes, private readonly Menu $menu, private readonly LoginChecks $loginChecks) {}
|
||||
|
||||
/** @return array{boot: array<string, mixed>, css: string, scripts: string, styles: string} */
|
||||
public function data(Request $request): array
|
||||
{
|
||||
$user = $request->user();
|
||||
$key = $this->themes->keyFor($user);
|
||||
$theme = $this->themes->all()[$key];
|
||||
$dist = __DIR__.'/../../resources/dist';
|
||||
|
||||
$allowed = $user === null ? [] : array_values(array_filter(
|
||||
[...$this->modules->permissionValues(), ManagerServiceProvider::MANAGE_GROUPS],
|
||||
fn (string $permission) => Gate::forUser($user)->allows($permission),
|
||||
));
|
||||
|
||||
$navigation = $this->menu->for($user, $allowed);
|
||||
|
||||
$extensions = array_values(array_filter(
|
||||
(array) config('manager.extensions', []),
|
||||
fn ($url) => is_string($url) && preg_match('#^(/(?!/)|https://)[^\s<>"\'\\\\]*$#', $url) === 1,
|
||||
));
|
||||
|
||||
return [
|
||||
'extensions' => $extensions,
|
||||
'css' => $this->themes->css($theme),
|
||||
'title' => $theme['name'] ?? config('manager.name') ?? config('app.name', 'Manager'),
|
||||
'version' => is_file($dist.'/manager.js') ? substr(md5_file($dist.'/manager.js').md5_file($dist.'/manager.css'), 0, 10) : 'dev',
|
||||
'boot' => [
|
||||
'base' => '/'.trim((string) config('manager.path'), '/'),
|
||||
'name' => $theme['name'] ?? config('manager.name') ?? config('app.name', 'Manager'),
|
||||
'logo' => $theme['logo'],
|
||||
'locale' => app()->getLocale(),
|
||||
'user' => $user === null ? null : [
|
||||
'name' => (string) ($user->name ?? ''),
|
||||
'email' => (string) ($user->email ?? ''),
|
||||
'is_super_admin' => method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin(),
|
||||
],
|
||||
'permissions' => $allowed,
|
||||
'navigation' => $navigation,
|
||||
'extensions' => $user === null ? [] : $extensions,
|
||||
'view' => $this->menu->view($user),
|
||||
'can_switch' => $this->menu->maySwitch($user),
|
||||
'simple_view' => (bool) config('manager.simple_view'),
|
||||
'tutorial' => UserSetting::value($user, 'tutorial') === 'pending',
|
||||
'tutorial_state' => UserSetting::value($user, 'tutorial'),
|
||||
'tutorial_steps' => $user === null ? [] : $this->modules->tutorial($allowed),
|
||||
'mascot' => '/'.trim((string) config('manager.path'), '/').'/_assets/mascot/',
|
||||
'locales' => UserSetting::LOCALES,
|
||||
'theme' => $key,
|
||||
'can_login' => Route::has(Names::route('login')),
|
||||
'login_fields' => $user === null ? $this->loginChecks->fields() : [],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user