Skip to content

Commit

Permalink
feat: Redirect from dashboard to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Sep 23, 2024
1 parent 4a95017 commit cfc31b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
20 changes: 17 additions & 3 deletions app/Classes/Authentication/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,40 @@ public static function createNewToken($token, ?Request $request = null)
];

$dashboardPermissions = [];
$permissions->map(function ($permission) use (&$dashboardPermissions, &$viewPermissions) {
$hasDashboardPermission = false;
$permissions->map(function ($permission) use (&$dashboardPermissions, &$viewPermissions, &$hasDashboardPermission) {
if ($permission->key === "sidebar") {
// if sidebar is set to extensions, you cannot override it.
if (isset($viewPermissions["sidebar"]) && $viewPermissions["sidebar"] === "extensions") {
return;
}
$viewPermissions["sidebar"] = json_decode($permission->value);
try {
$viewPermissions["sidebar"] = json_decode($permission->value, false, 512, JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
$viewPermissions["sidebar"] = $permission->value;
}
}

if ($permission->key === "dashboard") {
$hasDashboardPermission = true;
// merge all dashboard permissions that comes from roles
$dashboardPermissions = array_unique([
...$dashboardPermissions,
...json_decode($permission->value),
]);
}

if ($permission->key === "redirect") {
if (! auth()->user()->isAdmin()) {
$viewPermissions["redirect"] = $permission->value;
}
}
});

// if there is no dashboard permission, set it to default
$viewPermissions["dashboard"] = count($dashboardPermissions) > 0 ? $dashboardPermissions : $defaultPermissions["dashboard"];
$viewPermissions["dashboard"] = $hasDashboardPermission
? $dashboardPermissions
: $defaultPermissions["dashboard"];

return $viewPermissions;
})(),
Expand Down
16 changes: 14 additions & 2 deletions app/Http/Controllers/API/Settings/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ public function views(Request $request)
];

$permissions->map(function ($item) use (&$viewSettings) {
$viewSettings[$item->key] = json_decode($item->value);
try {
$viewSettings[$item->key] = json_decode($item->value, false, 512, JSON_THROW_ON_ERROR);
} catch (\Throwable) {
$viewSettings[$item->key] = $item->value;
}
});

return response()->json($viewSettings);
Expand All @@ -647,11 +651,19 @@ public function setViews(Request $request)
])->delete();

foreach ($request->views as $setting => $value) {
if ($value === '') {
continue;
}

if (is_array($value) || is_object($value)) {
$value = json_encode($value);
}

Permission::grant(
$request->role_id,
'view',
$setting,
json_encode($value),
$value,
null,
'roles'
);
Expand Down
1 change: 1 addition & 0 deletions config/liman.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'most_used_extensions',
'most_used_servers',
],
'redirect' => null
],
'search' => [
'admin' => [
Expand Down

0 comments on commit cfc31b6

Please sign in to comment.