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:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPhotoboothSetting;
|
||||
use App\Services\Photobooth\PhotoboothProvisioner;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -17,12 +17,20 @@ class DeactivateExpiredPhotoboothAccounts extends Command
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
Event::query()
|
||||
->where('photobooth_enabled', true)
|
||||
->whereNotNull('photobooth_expires_at')
|
||||
->where('photobooth_expires_at', '<=', now())
|
||||
->chunkById(50, function ($events) use (&$total, $provisioner) {
|
||||
foreach ($events as $event) {
|
||||
EventPhotoboothSetting::query()
|
||||
->where('enabled', true)
|
||||
->where('mode', 'ftp')
|
||||
->whereNotNull('expires_at')
|
||||
->where('expires_at', '<=', now())
|
||||
->with('event')
|
||||
->chunkById(50, function ($settings) use (&$total, $provisioner) {
|
||||
foreach ($settings as $setting) {
|
||||
$event = $setting->event;
|
||||
|
||||
if (! $event) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$provisioner->disable($event);
|
||||
$total++;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPhotoboothSetting;
|
||||
use App\Services\Photobooth\PhotoboothIngestService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -20,16 +20,23 @@ class PhotoboothIngestCommand extends Command
|
||||
$processedTotal = 0;
|
||||
$skippedTotal = 0;
|
||||
|
||||
$query = Event::query()
|
||||
->where('photobooth_enabled', true)
|
||||
->whereNotNull('photobooth_path');
|
||||
$query = EventPhotoboothSetting::query()
|
||||
->where('enabled', true)
|
||||
->whereNotNull('path')
|
||||
->with('event');
|
||||
|
||||
if ($eventId) {
|
||||
$query->whereKey($eventId);
|
||||
$query->where('event_id', $eventId);
|
||||
}
|
||||
|
||||
$query->chunkById(25, function ($events) use ($ingestService, $maxFiles, &$processedTotal, &$skippedTotal) {
|
||||
foreach ($events as $event) {
|
||||
$query->chunkById(25, function ($settings) use ($ingestService, $maxFiles, &$processedTotal, &$skippedTotal) {
|
||||
foreach ($settings as $setting) {
|
||||
$event = $setting->event;
|
||||
|
||||
if (! $event) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$summary = $ingestService->ingest($event, $maxFiles ? (int) $maxFiles : null);
|
||||
$processedTotal += $summary['processed'] ?? 0;
|
||||
$skippedTotal += $summary['skipped'] ?? 0;
|
||||
|
||||
@@ -7,13 +7,13 @@ use App\Enums\GuestNotificationDeliveryStatus;
|
||||
use App\Enums\GuestNotificationState;
|
||||
use App\Enums\GuestNotificationType;
|
||||
use App\Events\GuestPhotoUploaded;
|
||||
use App\Jobs\ProcessPhotoSecurityScan;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventJoinToken;
|
||||
use App\Models\EventMediaAsset;
|
||||
use App\Models\GuestNotification;
|
||||
use App\Models\Photo;
|
||||
use App\Models\PhotoShareLink;
|
||||
use App\Jobs\ProcessPhotoSecurityScan;
|
||||
use App\Services\Analytics\JoinTokenAnalyticsRecorder;
|
||||
use App\Services\EventJoinTokenService;
|
||||
use App\Services\EventTasksCacheService;
|
||||
@@ -44,6 +44,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class EventPublicController extends BaseController
|
||||
{
|
||||
private const SIGNED_URL_TTL_SECONDS = 1800;
|
||||
|
||||
private const BRANDING_SIGNED_TTL_SECONDS = 3600;
|
||||
|
||||
public function __construct(
|
||||
@@ -952,7 +953,7 @@ class EventPublicController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array|mixed> $sources
|
||||
* @param array<int, array|mixed> $sources
|
||||
*/
|
||||
private function firstStringFromSources(array $sources, array $keys): ?string
|
||||
{
|
||||
@@ -969,7 +970,7 @@ class EventPublicController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array|mixed> $sources
|
||||
* @param array<int, array|mixed> $sources
|
||||
*/
|
||||
private function firstNumberFromSources(array $sources, array $keys): ?float
|
||||
{
|
||||
@@ -1778,6 +1779,7 @@ class EventPublicController extends BaseController
|
||||
$branding = $this->buildGalleryBranding($event);
|
||||
$settings = $this->normalizeSettings($event->settings ?? []);
|
||||
$engagementMode = $settings['engagement_mode'] ?? 'tasks';
|
||||
$event->loadMissing('photoboothSetting');
|
||||
|
||||
if ($joinToken) {
|
||||
$this->joinTokenService->incrementUsage($joinToken);
|
||||
@@ -1792,7 +1794,7 @@ class EventPublicController extends BaseController
|
||||
'updated_at' => $event->updated_at,
|
||||
'type' => $eventTypeData,
|
||||
'join_token' => $joinToken?->token,
|
||||
'photobooth_enabled' => (bool) $event->photobooth_enabled,
|
||||
'photobooth_enabled' => (bool) ($event->photoboothSetting?->enabled),
|
||||
'branding' => $branding,
|
||||
'guest_upload_visibility' => Arr::get($event->settings ?? [], 'guest_upload_visibility', 'review'),
|
||||
'engagement_mode' => $engagementMode,
|
||||
@@ -2558,7 +2560,7 @@ class EventPublicController extends BaseController
|
||||
$lastPage = (int) ceil($total / $perPage);
|
||||
$hasMore = $page < $lastPage;
|
||||
|
||||
$etag = sha1($baseHash . ':' . $page . ':' . $perPage . ':' . $seedValue);
|
||||
$etag = sha1($baseHash.':'.$page.':'.$perPage.':'.$seedValue);
|
||||
$reqEtag = $request->headers->get('If-None-Match');
|
||||
|
||||
if ($reqEtag && $reqEtag === $etag) {
|
||||
|
||||
@@ -7,8 +7,8 @@ use App\Models\Event;
|
||||
use App\Services\Photobooth\Exceptions\SparkboothUploadException;
|
||||
use App\Services\Photobooth\SparkboothUploadService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SparkboothUploadController extends Controller
|
||||
@@ -68,7 +68,8 @@ class SparkboothUploadController extends Controller
|
||||
return $preferred;
|
||||
}
|
||||
|
||||
$configured = $event?->photobooth_metadata['sparkbooth_response_format'] ?? null;
|
||||
$event?->loadMissing('photoboothSetting');
|
||||
$configured = ($event?->photoboothSetting?->metadata ?? [])['sparkbooth_response_format'] ?? null;
|
||||
|
||||
if ($configured && in_array($configured, ['json', 'xml'], true)) {
|
||||
return $configured;
|
||||
|
||||
@@ -72,7 +72,7 @@ class PhotoboothController extends Controller
|
||||
protected function resource(Event $event): PhotoboothStatusResource
|
||||
{
|
||||
return PhotoboothStatusResource::make([
|
||||
'event' => $event->fresh(),
|
||||
'event' => $event->fresh('photoboothSetting'),
|
||||
'settings' => PhotoboothSetting::current(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Resources\Tenant;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPhotoboothSetting;
|
||||
use App\Models\PhotoboothSetting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@@ -20,31 +21,32 @@ class PhotoboothStatusResource extends JsonResource
|
||||
/** @var PhotoboothSetting $settings */
|
||||
$settings = $payload['settings'];
|
||||
|
||||
$mode = $event->photobooth_mode ?? 'ftp';
|
||||
$event->loadMissing('photoboothSetting');
|
||||
$eventSetting = $event->photoboothSetting;
|
||||
|
||||
$mode = $eventSetting?->mode ?? 'ftp';
|
||||
$isSparkbooth = $mode === 'sparkbooth';
|
||||
|
||||
$password = $isSparkbooth
|
||||
? $event->getAttribute('plain_sparkbooth_password') ?? $event->sparkbooth_password
|
||||
: $event->getAttribute('plain_photobooth_password') ?? $event->photobooth_password;
|
||||
$password = $eventSetting?->getAttribute('plain_password') ?? $eventSetting?->password;
|
||||
|
||||
$activeUsername = $isSparkbooth ? $event->sparkbooth_username : $event->photobooth_username;
|
||||
$activeStatus = $isSparkbooth ? $event->sparkbooth_status : $event->photobooth_status;
|
||||
$activeExpires = $isSparkbooth ? $event->sparkbooth_expires_at : $event->photobooth_expires_at;
|
||||
$activeUsername = $eventSetting?->username;
|
||||
$activeStatus = $eventSetting?->status ?? 'inactive';
|
||||
$activeExpires = $eventSetting?->expires_at;
|
||||
|
||||
$sparkMetrics = [
|
||||
'last_upload_at' => optional($event->sparkbooth_last_upload_at)->toIso8601String(),
|
||||
'uploads_24h' => (int) ($event->sparkbooth_uploads_last_24h ?? 0),
|
||||
'uploads_total' => (int) ($event->sparkbooth_uploads_total ?? 0),
|
||||
'last_upload_at' => optional($eventSetting?->last_upload_at)->toIso8601String(),
|
||||
'uploads_24h' => (int) ($eventSetting?->uploads_last_24h ?? 0),
|
||||
'uploads_total' => (int) ($eventSetting?->uploads_total ?? 0),
|
||||
];
|
||||
|
||||
return [
|
||||
'mode' => $mode,
|
||||
'enabled' => (bool) $event->photobooth_enabled,
|
||||
'enabled' => (bool) ($eventSetting?->enabled),
|
||||
'status' => $activeStatus,
|
||||
'username' => $activeUsername,
|
||||
'password' => $password,
|
||||
'path' => $event->photobooth_path,
|
||||
'ftp_url' => $isSparkbooth ? null : $this->buildFtpUrl($event, $settings, $password),
|
||||
'path' => $eventSetting?->path,
|
||||
'ftp_url' => $isSparkbooth ? null : $this->buildFtpUrl($eventSetting, $settings, $password),
|
||||
'upload_url' => $isSparkbooth ? route('api.v1.photobooth.sparkbooth.upload') : null,
|
||||
'expires_at' => optional($activeExpires)->toIso8601String(),
|
||||
'rate_limit_per_minute' => (int) $settings->rate_limit_per_minute,
|
||||
@@ -55,13 +57,13 @@ class PhotoboothStatusResource extends JsonResource
|
||||
],
|
||||
'metrics' => $isSparkbooth ? $sparkMetrics : null,
|
||||
'sparkbooth' => [
|
||||
'enabled' => $mode === 'sparkbooth' && $event->photobooth_enabled,
|
||||
'status' => $event->sparkbooth_status,
|
||||
'username' => $event->sparkbooth_username,
|
||||
'password' => $event->getAttribute('plain_sparkbooth_password') ?? $event->sparkbooth_password,
|
||||
'expires_at' => optional($event->sparkbooth_expires_at)->toIso8601String(),
|
||||
'enabled' => $mode === 'sparkbooth' && (bool) ($eventSetting?->enabled),
|
||||
'status' => $mode === 'sparkbooth' ? ($eventSetting?->status) : 'inactive',
|
||||
'username' => $mode === 'sparkbooth' ? $eventSetting?->username : null,
|
||||
'password' => $mode === 'sparkbooth' ? $password : null,
|
||||
'expires_at' => $mode === 'sparkbooth' ? optional($eventSetting?->expires_at)->toIso8601String() : null,
|
||||
'upload_url' => route('api.v1.photobooth.sparkbooth.upload'),
|
||||
'response_format' => $event->photobooth_metadata['sparkbooth_response_format'] ?? config('photobooth.sparkbooth.response_format', 'json'),
|
||||
'response_format' => ($eventSetting?->metadata ?? [])['sparkbooth_response_format'] ?? config('photobooth.sparkbooth.response_format', 'json'),
|
||||
'metrics' => $sparkMetrics,
|
||||
],
|
||||
];
|
||||
@@ -87,10 +89,10 @@ class PhotoboothStatusResource extends JsonResource
|
||||
];
|
||||
}
|
||||
|
||||
protected function buildFtpUrl(Event $event, PhotoboothSetting $settings, ?string $password): ?string
|
||||
protected function buildFtpUrl(?EventPhotoboothSetting $eventSetting, PhotoboothSetting $settings, ?string $password): ?string
|
||||
{
|
||||
$host = config('photobooth.ftp.host');
|
||||
$username = $event->photobooth_username;
|
||||
$username = $eventSetting?->username;
|
||||
|
||||
if (! $host || ! $username || ! $password) {
|
||||
return null;
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\EventJoinTokenService;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Event extends Model
|
||||
{
|
||||
@@ -24,17 +23,6 @@ class Event extends Model
|
||||
'is_active' => 'boolean',
|
||||
'name' => 'array',
|
||||
'description' => 'array',
|
||||
'photobooth_enabled' => 'boolean',
|
||||
'photobooth_mode' => 'string',
|
||||
'photobooth_expires_at' => 'datetime',
|
||||
'photobooth_metadata' => 'array',
|
||||
'sparkbooth_expires_at' => 'datetime',
|
||||
'sparkbooth_last_upload_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'photobooth_password_encrypted',
|
||||
'sparkbooth_password_encrypted',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
@@ -126,6 +114,11 @@ class Event extends Model
|
||||
return $this->hasMany(EventMember::class);
|
||||
}
|
||||
|
||||
public function photoboothSetting(): HasOne
|
||||
{
|
||||
return $this->hasOne(EventPhotoboothSetting::class);
|
||||
}
|
||||
|
||||
public function guestNotifications(): HasMany
|
||||
{
|
||||
return $this->hasMany(GuestNotification::class);
|
||||
@@ -178,48 +171,4 @@ class Event extends Model
|
||||
|
||||
$this->attributes['settings'] = json_encode($value ?? []);
|
||||
}
|
||||
|
||||
public function getPhotoboothPasswordAttribute(): ?string
|
||||
{
|
||||
$encrypted = $this->attributes['photobooth_password_encrypted'] ?? null;
|
||||
|
||||
if (! $encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($encrypted);
|
||||
} catch (DecryptException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPhotoboothPasswordAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['photobooth_password_encrypted'] = $value
|
||||
? Crypt::encryptString($value)
|
||||
: null;
|
||||
}
|
||||
|
||||
public function getSparkboothPasswordAttribute(): ?string
|
||||
{
|
||||
$encrypted = $this->attributes['sparkbooth_password_encrypted'] ?? null;
|
||||
|
||||
if (! $encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($encrypted);
|
||||
} catch (DecryptException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setSparkboothPasswordAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['sparkbooth_password_encrypted'] = $value
|
||||
? Crypt::encryptString($value)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
64
app/Models/EventPhotoboothSetting.php
Normal file
64
app/Models/EventPhotoboothSetting.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
class EventPhotoboothSetting extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\EventPhotoboothSettingFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'enabled' => 'boolean',
|
||||
'expires_at' => 'datetime',
|
||||
'last_provisioned_at' => 'datetime',
|
||||
'last_deprovisioned_at' => 'datetime',
|
||||
'last_upload_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
'uploads_last_24h' => 'integer',
|
||||
'uploads_total' => 'integer',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password_encrypted',
|
||||
];
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function getPasswordAttribute(): ?string
|
||||
{
|
||||
$encrypted = $this->attributes['password_encrypted'] ?? null;
|
||||
|
||||
if (! $encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Crypt::decryptString($encrypted);
|
||||
} catch (DecryptException) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function setPasswordAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['password_encrypted'] = $value
|
||||
? Crypt::encryptString($value)
|
||||
: null;
|
||||
}
|
||||
|
||||
public function setUsernameAttribute(?string $value): void
|
||||
{
|
||||
$this->attributes['username'] = $value ? strtolower($value) : null;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user