Deploy Ladill Frontdesk / deploy (push) Successful in 23s
Show Ladill Frontdesk or uploaded logo top-left on kiosk; allow logo upload in onboarding and organization settings. Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
4.3 KiB
PHP
108 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Models\Branch;
|
|
use App\Services\Frontdesk\FrontdeskPermissions;
|
|
use App\Support\OrganizationBranding;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class SettingsController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function edit(Request $request): View
|
|
{
|
|
$this->authorizeAbility($request, 'settings.view');
|
|
$organization = $this->organization($request);
|
|
$canManage = app(FrontdeskPermissions::class)->isAdmin($this->member($request));
|
|
|
|
$branches = Branch::owned($this->ownerRef($request))
|
|
->where('organization_id', $organization->id)
|
|
->count();
|
|
|
|
return view('frontdesk.settings.edit', [
|
|
'organization' => $organization,
|
|
'canManage' => $canManage,
|
|
'branchCount' => $branches,
|
|
'roles' => config('frontdesk.roles'),
|
|
'deviceTypes' => config('frontdesk.device_types'),
|
|
'notificationChannels' => config('frontdesk.notification_channels'),
|
|
'notificationEvents' => config('frontdesk.notification_events'),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request): RedirectResponse
|
|
{
|
|
$this->authorizeAbility($request, 'settings.manage');
|
|
$organization = $this->organization($request);
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'timezone' => ['required', 'timezone'],
|
|
'badge_expiry_hours' => ['required', 'integer', 'min:1', 'max:24'],
|
|
'kiosk_reset_seconds' => ['required', 'integer', 'min:30', 'max:600'],
|
|
'contractor_badge_expiry_hours' => ['nullable', 'integer', 'min:1', 'max:24'],
|
|
'visitor_policy' => ['nullable', 'string', 'max:5000'],
|
|
'notification_channels' => ['nullable', 'array'],
|
|
'notification_channels.*' => ['string', 'in:'.implode(',', array_keys(config('frontdesk.notification_channels')))],
|
|
'notification_events' => ['nullable', 'array'],
|
|
'report_daily_recipients' => ['nullable', 'string', 'max:2000'],
|
|
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
|
|
'remove_logo' => ['nullable', 'boolean'],
|
|
]);
|
|
|
|
$settings = $organization->settings ?? [];
|
|
$settings['onboarded'] = true;
|
|
$settings['badge_expiry_hours'] = $validated['badge_expiry_hours'];
|
|
$settings['kiosk_reset_seconds'] = $validated['kiosk_reset_seconds'];
|
|
$settings['visitor_policy'] = $validated['visitor_policy'] ?? null;
|
|
$settings['notification_channels'] = $validated['notification_channels'] ?? ['email'];
|
|
|
|
$eventKeys = array_keys(config('frontdesk.notification_events', []));
|
|
$submittedEvents = $validated['notification_events'] ?? [];
|
|
$settings['notification_events'] = [];
|
|
foreach ($eventKeys as $key) {
|
|
$settings['notification_events'][$key] = (bool) ($submittedEvents[$key] ?? false);
|
|
}
|
|
|
|
if (array_key_exists('report_daily_recipients', $validated)) {
|
|
$settings['report_daily_recipients'] = array_values(array_filter(array_map(
|
|
'trim',
|
|
explode(',', (string) ($validated['report_daily_recipients'] ?? '')),
|
|
)));
|
|
}
|
|
|
|
if (! empty($validated['contractor_badge_expiry_hours'])) {
|
|
$settings['type_badge_expiry_hours'] = array_merge(
|
|
$settings['type_badge_expiry_hours'] ?? [],
|
|
['contractor' => (int) $validated['contractor_badge_expiry_hours']],
|
|
);
|
|
}
|
|
|
|
$logoPath = $organization->logo_path;
|
|
|
|
if ($request->boolean('remove_logo')) {
|
|
OrganizationBranding::deleteStoredLogo($organization);
|
|
$logoPath = null;
|
|
}
|
|
|
|
if ($request->hasFile('logo')) {
|
|
$logoPath = OrganizationBranding::storeLogo($organization, $request->file('logo'));
|
|
}
|
|
|
|
$organization->update([
|
|
'name' => $validated['name'],
|
|
'timezone' => $validated['timezone'],
|
|
'logo_path' => $logoPath,
|
|
'settings' => $settings,
|
|
]);
|
|
|
|
return back()->with('success', 'Settings saved.');
|
|
}
|
|
}
|