mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 17:15:08 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Audit\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Modules\Audit\Models\DashboardWidgetPreference;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
/**
|
|
* Saves a staff member's dashboard layout (per-widget enabled/column/
|
|
* position, plus column count) — every account manages their own, same
|
|
* "self-scoped, no extra permission needed" shape as
|
|
* NotificationPreferencesController. Which widgets a viewer can even
|
|
* toggle is enforced entirely by DashboardController's own permission
|
|
* checks on read — this endpoint only ever stores a preference, it never
|
|
* grants visibility a viewer's Gates don't already allow.
|
|
*/
|
|
class DashboardWidgetPreferencesController extends Controller
|
|
{
|
|
/**
|
|
* Every key DashboardController::__invoke() knows how to render —
|
|
* kept here as the single validation allowlist so a stray/typo'd key
|
|
* can't accumulate a dead row.
|
|
*/
|
|
private const WIDGET_KEYS = [
|
|
'counters',
|
|
'transfers',
|
|
'top_clients_by_storage',
|
|
'largest_files',
|
|
'recent',
|
|
'system',
|
|
'news',
|
|
'expired_files',
|
|
'api',
|
|
];
|
|
|
|
public function update(Request $request): RedirectResponse
|
|
{
|
|
$user = $request->user();
|
|
assert($user !== null);
|
|
|
|
$validated = $request->validate([
|
|
'columns' => ['required', 'integer', 'between:1,4'],
|
|
'widgets' => ['required', 'array'],
|
|
'widgets.*.widget_key' => ['required', 'string', Rule::in(self::WIDGET_KEYS)],
|
|
'widgets.*.enabled' => ['required', 'boolean'],
|
|
'widgets.*.column_index' => ['required', 'integer', 'between:0,3'],
|
|
'widgets.*.position' => ['required', 'integer', 'min:0'],
|
|
]);
|
|
|
|
foreach ($validated['widgets'] as $widget) {
|
|
DashboardWidgetPreference::query()->updateOrCreate(
|
|
['user_id' => $user->id, 'widget_key' => $widget['widget_key']],
|
|
[
|
|
'enabled' => $widget['enabled'],
|
|
'column_index' => $widget['column_index'],
|
|
'position' => $widget['position'],
|
|
],
|
|
);
|
|
}
|
|
|
|
$user->update(['dashboard_columns' => $validated['columns']]);
|
|
|
|
return back();
|
|
}
|
|
}
|