Deploy Ladill Frontdesk / deploy (push) Failing after 26s
Enables staff roster, PIN/code kiosk flow, attendance reports, evacuation staff roll call, webhooks, branch mismatch warnings, and a linked-user My presence portal. Co-authored-by: Cursor <cursoragent@cursor.com>
126 lines
5.3 KiB
PHP
126 lines
5.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\Services\Frontdesk\NotificationPricingService;
|
|
use App\Services\Frontdesk\NotificationUsageService;
|
|
use App\Services\Frontdesk\PlanService;
|
|
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, PlanService $plans, NotificationUsageService $usage, NotificationPricingService $pricing): 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();
|
|
|
|
$monthlyUsage = $usage->forOrganization($organization);
|
|
$plan = $plans->plan($organization);
|
|
$freeEmailAllowance = $plans->freeEmailsPerMonth($organization);
|
|
|
|
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'),
|
|
'plan' => $plan,
|
|
'isPro' => $plans->isPro($organization),
|
|
'proPriceMinor' => $plans->proPriceMinor(),
|
|
'monthlyUsage' => $monthlyUsage,
|
|
'freeEmailAllowance' => $freeEmailAllowance,
|
|
'emailCostFormatted' => $pricing->formatMinor($pricing->emailCostMinor()),
|
|
'smsCostFormatted' => $pricing->formatMinor(
|
|
$pricing->smsCostMinor('Sample SMS message for pricing display.'),
|
|
),
|
|
]);
|
|
}
|
|
|
|
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'],
|
|
'employee_kiosk_enabled' => ['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['employee_kiosk_enabled'] = $request->boolean('employee_kiosk_enabled');
|
|
$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.');
|
|
}
|
|
}
|