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

@@ -85,9 +85,24 @@ class AccountAnonymizer
'location' => null,
'slug' => 'anonymized-event-'.$event->id,
'status' => 'archived',
'photobooth_enabled' => false,
'photobooth_path' => null,
])->save();
$event->loadMissing('photoboothSetting');
if ($event->photoboothSetting) {
$event->photoboothSetting->forceFill([
'enabled' => false,
'status' => 'inactive',
'username' => null,
'password' => null,
'path' => null,
'expires_at' => null,
'last_deprovisioned_at' => now(),
'last_upload_at' => null,
'uploads_last_24h' => 0,
'uploads_total' => 0,
])->save();
}
}
});

View File

@@ -35,14 +35,16 @@ class PhotoboothIngestService
public function ingest(Event $event, ?int $maxFiles = null, string $ingestSource = Photo::SOURCE_PHOTOBOOTH): array
{
$event->loadMissing('photoboothSetting');
$eventSetting = $event->photoboothSetting;
$tenant = $event->tenant;
if (! $tenant) {
if (! $tenant || ! $eventSetting) {
return ['processed' => 0, 'skipped' => 0];
}
$importDisk = config('photobooth.import.disk', 'photobooth');
$basePath = ltrim((string) $event->photobooth_path, '/');
$basePath = ltrim((string) $eventSetting->path, '/');
if (str_starts_with($basePath, 'photobooth/')) {
$basePath = substr($basePath, strlen('photobooth/'));
}
@@ -178,6 +180,9 @@ class PhotoboothIngestService
$destinationPath,
$thumbnailRelative,
$thumbnailToStore,
$watermarkedPath,
$watermarkedThumb,
$ingestSource,
$mimeType,
$size,
$filename,

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;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Services\Photobooth;
use App\Models\Event;
use App\Models\EventPhotoboothSetting;
use App\Models\Photo;
use App\Services\Photobooth\Exceptions\SparkboothUploadException;
use Illuminate\Http\UploadedFile;
@@ -21,47 +22,52 @@ class SparkboothUploadService
*/
public function handleUpload(UploadedFile $media, ?string $username, ?string $password): array
{
$event = $this->authenticate($username, $password);
$setting = $this->authenticate($username, $password);
$event = $setting->event;
$this->enforceExpiry($event);
if (! $event) {
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
}
$this->enforceExpiry($setting);
$this->enforceRateLimit($event);
$this->assertValidFile($media);
$importDisk = config('photobooth.import.disk', 'photobooth');
$basePath = ltrim((string) ($event->photobooth_path ?: $this->buildPath($event)), '/');
$basePath = ltrim((string) ($setting->path ?: $this->buildPath($event)), '/');
$extension = strtolower($media->getClientOriginalExtension() ?: $media->extension() ?: 'jpg');
$filename = Str::uuid().'.'.$extension;
$relativePath = "{$basePath}/{$filename}";
if (! $event->photobooth_path) {
$event->forceFill([
'photobooth_path' => $basePath,
if (! $setting->path) {
$setting->forceFill([
'path' => $basePath,
])->save();
}
Storage::disk($importDisk)->makeDirectory($basePath);
Storage::disk($importDisk)->putFileAs($basePath, $media, $filename);
$summary = $this->ingestService->ingest($event->fresh(), 1, Photo::SOURCE_SPARKBOOTH);
$summary = $this->ingestService->ingest($event->fresh('photoboothSetting'), 1, Photo::SOURCE_SPARKBOOTH);
if (($summary['processed'] ?? 0) < 1) {
throw new SparkboothUploadException('ingest_failed', 'Upload failed, please retry.', 500);
}
$event->forceFill([
'sparkbooth_last_upload_at' => now(),
'sparkbooth_uploads_last_24h' => ($event->sparkbooth_uploads_last_24h ?? 0) + 1,
'sparkbooth_uploads_total' => ($event->sparkbooth_uploads_total ?? 0) + 1,
$setting->forceFill([
'last_upload_at' => now(),
'uploads_last_24h' => ($setting->uploads_last_24h ?? 0) + 1,
'uploads_total' => ($setting->uploads_total ?? 0) + 1,
])->save();
return [
'event' => $event->fresh(),
'event' => $event->fresh('photoboothSetting'),
'processed' => $summary['processed'] ?? 0,
'skipped' => $summary['skipped'] ?? 0,
];
}
protected function authenticate(?string $username, ?string $password): Event
protected function authenticate(?string $username, ?string $password): EventPhotoboothSetting
{
if (! $username || ! $password) {
throw new SparkboothUploadException('missing_credentials', 'Invalid credentials', 401);
@@ -69,29 +75,34 @@ class SparkboothUploadService
$normalizedUsername = strtolower(trim($username));
/** @var Event|null $event */
$event = Event::query()
->whereRaw('LOWER(sparkbooth_username) = ?', [$normalizedUsername])
/** @var EventPhotoboothSetting|null $setting */
$setting = EventPhotoboothSetting::query()
->where('username', $normalizedUsername)
->with('event')
->first();
if (! $event) {
if (! $setting) {
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
}
if ($event->photobooth_mode !== 'sparkbooth' || ! $event->photobooth_enabled) {
if (! $setting->event) {
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
}
if ($setting->mode !== 'sparkbooth' || ! $setting->enabled) {
throw new SparkboothUploadException('disabled', 'Upload not active for this event', 403);
}
if (! hash_equals($event->sparkbooth_password ?? '', $password ?? '')) {
if (! hash_equals($setting->password ?? '', $password ?? '')) {
throw new SparkboothUploadException('invalid_credentials', 'Invalid credentials', 401);
}
return $event;
return $setting;
}
protected function enforceExpiry(Event $event): void
protected function enforceExpiry(EventPhotoboothSetting $setting): void
{
if ($event->sparkbooth_expires_at && $event->sparkbooth_expires_at->isPast()) {
if ($setting->expires_at && $setting->expires_at->isPast()) {
throw new SparkboothUploadException('expired', 'Upload access has expired', 403);
}
}