updated table structure for photobooth/sparkbooth settings. now there's a separate table for it. update all references and tests. also fixed the notification panel and the lightbox in the guest app.

This commit is contained in:
Codex Agent
2025-12-18 08:49:56 +01:00
parent ece38fc009
commit 1c4acda332
30 changed files with 734 additions and 538 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Services\Photobooth;
use App\Models\Event;
use App\Models\EventPhotoboothSetting;
use App\Models\PhotoboothSetting;
use Carbon\CarbonInterface;
use Illuminate\Support\Carbon;
@@ -20,9 +21,10 @@ class PhotoboothProvisioner
public function enable(Event $event, ?PhotoboothSetting $settings = null): Event
{
$settings ??= PhotoboothSetting::current();
$event->loadMissing('tenant');
$event->loadMissing(['tenant', 'photoboothSetting']);
return DB::transaction(function () use ($event, $settings) {
$eventSetting = $this->resolveEventSetting($event);
$username = $this->generateUniqueUsername($event, $settings);
$password = $this->credentialGenerator->generatePassword();
$path = $this->buildPath($event);
@@ -39,21 +41,24 @@ class PhotoboothProvisioner
$this->client->provisionUser($payload, $settings);
$event->forceFill([
'photobooth_enabled' => true,
'photobooth_username' => $username,
'photobooth_password' => $password,
'photobooth_path' => $path,
'photobooth_expires_at' => $expiresAt,
'photobooth_status' => 'active',
'photobooth_last_provisioned_at' => now(),
'photobooth_metadata' => [
$eventSetting->forceFill([
'enabled' => true,
'mode' => 'ftp',
'username' => $username,
'password' => $password,
'path' => $path,
'expires_at' => $expiresAt,
'status' => 'active',
'last_provisioned_at' => now(),
'metadata' => [
'rate_limit_per_minute' => $settings->rate_limit_per_minute,
],
])->save();
return tap($event->refresh(), function (Event $refreshed) use ($password) {
$refreshed->setAttribute('plain_photobooth_password', $password);
return tap($event->refresh()->load('photoboothSetting'), function (Event $refreshed) use ($password) {
if ($refreshed->photoboothSetting) {
$refreshed->photoboothSetting->setAttribute('plain_password', $password);
}
});
});
}
@@ -62,11 +67,14 @@ class PhotoboothProvisioner
{
$settings ??= PhotoboothSetting::current();
if (! $event->photobooth_enabled || ! $event->photobooth_username) {
$event->loadMissing('photoboothSetting');
$eventSetting = $event->photoboothSetting;
if (! $eventSetting || ! $eventSetting->enabled || ! $eventSetting->username) {
return $this->enable($event, $settings);
}
return DB::transaction(function () use ($event, $settings) {
return DB::transaction(function () use ($event, $settings, $eventSetting) {
$password = $this->credentialGenerator->generatePassword();
$expiresAt = $this->resolveExpiry($event, $settings);
@@ -76,78 +84,90 @@ class PhotoboothProvisioner
'rate_limit_per_minute' => $settings->rate_limit_per_minute,
];
$this->client->rotateUser($event->photobooth_username, $payload, $settings);
$this->client->rotateUser($eventSetting->username, $payload, $settings);
$event->forceFill([
'photobooth_password' => $password,
'photobooth_expires_at' => $expiresAt,
'photobooth_status' => 'active',
'photobooth_last_provisioned_at' => now(),
$eventSetting->forceFill([
'enabled' => true,
'mode' => 'ftp',
'password' => $password,
'expires_at' => $expiresAt,
'status' => 'active',
'path' => $eventSetting->path ?: $this->buildPath($event),
'last_provisioned_at' => now(),
])->save();
return tap($event->refresh(), function (Event $refreshed) use ($password) {
$refreshed->setAttribute('plain_photobooth_password', $password);
return tap($event->refresh()->load('photoboothSetting'), function (Event $refreshed) use ($password) {
if ($refreshed->photoboothSetting) {
$refreshed->photoboothSetting->setAttribute('plain_password', $password);
}
});
});
}
public function disable(Event $event, ?PhotoboothSetting $settings = null): Event
{
if (! $event->photobooth_username) {
$event->loadMissing('photoboothSetting');
$eventSetting = $event->photoboothSetting;
if (! $eventSetting || ! $eventSetting->username) {
return $event;
}
$settings ??= PhotoboothSetting::current();
return DB::transaction(function () use ($event, $settings) {
return DB::transaction(function () use ($event, $settings, $eventSetting) {
try {
$this->client->deleteUser($event->photobooth_username, $settings);
$this->client->deleteUser($eventSetting->username, $settings);
} catch (\Throwable $exception) {
Log::warning('Photobooth account deletion failed', [
'event_id' => $event->id,
'username' => $event->photobooth_username,
'username' => $eventSetting->username,
'message' => $exception->getMessage(),
]);
}
$event->forceFill([
'photobooth_enabled' => false,
'photobooth_status' => 'inactive',
'photobooth_username' => null,
'photobooth_password' => null,
'photobooth_path' => null,
'photobooth_expires_at' => null,
'photobooth_last_deprovisioned_at' => now(),
$eventSetting->forceFill([
'enabled' => false,
'status' => 'inactive',
'username' => null,
'password' => null,
'path' => null,
'expires_at' => null,
'last_deprovisioned_at' => now(),
])->save();
return $event->refresh();
return $event->refresh()->load('photoboothSetting');
});
}
public function enableSparkbooth(Event $event, ?PhotoboothSetting $settings = null): Event
{
$settings ??= PhotoboothSetting::current();
$event->loadMissing('tenant');
$event->loadMissing(['tenant', 'photoboothSetting']);
return DB::transaction(function () use ($event, $settings) {
$eventSetting = $this->resolveEventSetting($event);
$username = $this->generateUniqueUsername($event, $settings);
$password = $this->credentialGenerator->generatePassword();
$path = $this->buildPath($event);
$expiresAt = $this->resolveExpiry($event, $settings);
$event->forceFill([
'photobooth_enabled' => true,
'photobooth_mode' => 'sparkbooth',
'sparkbooth_username' => $username,
'sparkbooth_password' => $password,
'sparkbooth_expires_at' => $expiresAt,
'sparkbooth_status' => 'active',
'photobooth_path' => $path,
'sparkbooth_uploads_last_24h' => 0,
$eventSetting->forceFill([
'enabled' => true,
'mode' => 'sparkbooth',
'username' => $username,
'password' => $password,
'expires_at' => $expiresAt,
'status' => 'active',
'path' => $path,
'uploads_last_24h' => 0,
'last_provisioned_at' => now(),
])->save();
return tap($event->refresh(), function (Event $refreshed) use ($password) {
$refreshed->setAttribute('plain_sparkbooth_password', $password);
return tap($event->refresh()->load('photoboothSetting'), function (Event $refreshed) use ($password) {
if ($refreshed->photoboothSetting) {
$refreshed->photoboothSetting->setAttribute('plain_password', $password);
}
});
});
}
@@ -155,48 +175,68 @@ class PhotoboothProvisioner
public function rotateSparkbooth(Event $event, ?PhotoboothSetting $settings = null): Event
{
$settings ??= PhotoboothSetting::current();
$event->loadMissing('photoboothSetting');
$eventSetting = $event->photoboothSetting;
if ($event->photobooth_mode !== 'sparkbooth' || ! $event->sparkbooth_username) {
if (! $eventSetting || $eventSetting->mode !== 'sparkbooth' || ! $eventSetting->username) {
return $this->enableSparkbooth($event, $settings);
}
return DB::transaction(function () use ($event, $settings) {
return DB::transaction(function () use ($event, $settings, $eventSetting) {
$password = $this->credentialGenerator->generatePassword();
$expiresAt = $this->resolveExpiry($event, $settings);
$event->forceFill([
'sparkbooth_password' => $password,
'sparkbooth_expires_at' => $expiresAt,
'sparkbooth_status' => 'active',
'photobooth_enabled' => true,
'photobooth_mode' => 'sparkbooth',
$eventSetting->forceFill([
'enabled' => true,
'mode' => 'sparkbooth',
'password' => $password,
'expires_at' => $expiresAt,
'status' => 'active',
'path' => $eventSetting->path ?: $this->buildPath($event),
'last_provisioned_at' => now(),
])->save();
return tap($event->refresh(), function (Event $refreshed) use ($password) {
$refreshed->setAttribute('plain_sparkbooth_password', $password);
return tap($event->refresh()->load('photoboothSetting'), function (Event $refreshed) use ($password) {
if ($refreshed->photoboothSetting) {
$refreshed->photoboothSetting->setAttribute('plain_password', $password);
}
});
});
}
public function disableSparkbooth(Event $event): Event
{
return DB::transaction(function () use ($event) {
$event->forceFill([
'photobooth_enabled' => false,
'photobooth_mode' => 'ftp',
'sparkbooth_username' => null,
'sparkbooth_password' => null,
'sparkbooth_expires_at' => null,
'sparkbooth_status' => 'inactive',
'sparkbooth_last_upload_at' => null,
'sparkbooth_uploads_last_24h' => 0,
'sparkbooth_uploads_total' => 0,
$event->loadMissing('photoboothSetting');
$eventSetting = $event->photoboothSetting;
if (! $eventSetting) {
return $event;
}
return DB::transaction(function () use ($event, $eventSetting) {
$eventSetting->forceFill([
'enabled' => false,
'mode' => 'ftp',
'username' => null,
'password' => null,
'expires_at' => null,
'status' => 'inactive',
'last_upload_at' => null,
'uploads_last_24h' => 0,
'uploads_total' => 0,
])->save();
return $event->refresh();
return $event->refresh()->load('photoboothSetting');
});
}
protected function resolveEventSetting(Event $event): EventPhotoboothSetting
{
$event->loadMissing('photoboothSetting');
return $event->photoboothSetting ?? $event->photoboothSetting()->make();
}
protected function resolveExpiry(Event $event, PhotoboothSetting $settings): CarbonInterface
{
$eventEnd = $event->date ? Carbon::parse($event->date) : now();
@@ -214,14 +254,15 @@ class PhotoboothProvisioner
for ($i = 0; $i < $maxAttempts; $i++) {
$username = $this->credentialGenerator->generateUsername($event);
$exists = Event::query()
->where('photobooth_username', $username)
->orWhere('sparkbooth_username', $username)
->whereKeyNot($event->getKey())
$normalized = strtolower($username);
$exists = EventPhotoboothSetting::query()
->where('username', $normalized)
->where('event_id', '!=', $event->getKey())
->exists();
if (! $exists) {
return strtolower($username);
return $normalized;
}
}