added a sparkbooth section to gallery form, connection details reside there now.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,9 +4,9 @@ namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Gallery;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
@@ -88,11 +88,24 @@ class SparkboothConnections extends Page implements HasTable
|
||||
|
||||
return view('filament.pages.partials.sparkbooth-token', $data);
|
||||
}),
|
||||
Action::make('deleteConnection')
|
||||
->label('Verbindung loeschen')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Sparkbooth-Verbindung entfernen')
|
||||
->modalDescription('Die Galerie bleibt erhalten, aber Upload-Token und Zugangsdaten werden geloescht.')
|
||||
->action(function (Gallery $record): void {
|
||||
$record->clearSparkboothConnection();
|
||||
|
||||
Notification::make()
|
||||
->title('Sparkbooth-Verbindung entfernt.')
|
||||
->body('Der Upload-Token und die Zugangsdaten wurden geloescht.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
])
|
||||
->emptyStateHeading('Keine Sparkbooth-Verbindungen')
|
||||
->emptyStateDescription('Lege eine neue Verbindung an oder aktiviere Uploads fuer eine Galerie.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data, true);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -67,6 +68,7 @@ class GalleryResource extends Resource
|
||||
public static function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$data = self::mutatePassword($data);
|
||||
$data = self::mutateSparkbooth($data);
|
||||
$data['slug'] = $data['slug'] ?: Str::uuid()->toString();
|
||||
|
||||
return $data;
|
||||
@@ -83,4 +85,24 @@ class GalleryResource extends Resource
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function mutateSparkbooth(array $data, bool $isCreate = false): array
|
||||
{
|
||||
if (array_key_exists('sparkbooth_username', $data)) {
|
||||
$data['sparkbooth_username'] = $data['sparkbooth_username']
|
||||
? Str::of($data['sparkbooth_username'])->lower()->trim()->value()
|
||||
: null;
|
||||
}
|
||||
|
||||
$password = $data['sparkbooth_password'] ?? null;
|
||||
unset($data['sparkbooth_password']);
|
||||
|
||||
if (! empty($password)) {
|
||||
$data['sparkbooth_password'] = $password;
|
||||
} elseif ($isCreate && empty($password)) {
|
||||
$data['sparkbooth_password'] = Str::random(24);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,71 +3,125 @@
|
||||
namespace App\Filament\Resources\Galleries\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class GalleryForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->columns(1)
|
||||
->components([
|
||||
Section::make('Details')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->disabled()
|
||||
->dehydrated(true)
|
||||
->helperText('Wird automatisch erzeugt'),
|
||||
TextInput::make('title')
|
||||
->label('Titel')
|
||||
->required(),
|
||||
TextInput::make('images_path')
|
||||
->label('Bilder-Pfad')
|
||||
->helperText('Relativer Pfad unter public/storage')
|
||||
->required(),
|
||||
Toggle::make('is_public')
|
||||
->label('Öffentlich')
|
||||
->default(true),
|
||||
Toggle::make('allow_ai_styles')
|
||||
->label('AI-Stile erlauben')
|
||||
->default(true),
|
||||
Toggle::make('allow_print')
|
||||
->label('Drucken erlauben')
|
||||
->default(true),
|
||||
Toggle::make('require_password')
|
||||
->label('Passwortschutz aktiv')
|
||||
->default(false),
|
||||
TextInput::make('password')
|
||||
->label('Neues Passwort')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
DateTimePicker::make('expires_at')
|
||||
->label('Ablaufdatum')
|
||||
->native(false)
|
||||
->seconds(false),
|
||||
TextInput::make('access_duration_minutes')
|
||||
->label('Zugriffsdauer (Minuten)')
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->nullable()
|
||||
->helperText('Optional: Zeitfenster nach dem ersten Unlock.'),
|
||||
]),
|
||||
View::make('filament.components.gallery-link')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
Tabs::make('gallery_tabs')
|
||||
->tabs([
|
||||
Tab::make('Galerie')
|
||||
->schema([
|
||||
Section::make('Details')
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->label('Slug')
|
||||
->disabled()
|
||||
->dehydrated(true)
|
||||
->helperText('Wird automatisch erzeugt'),
|
||||
TextInput::make('title')
|
||||
->label('Titel')
|
||||
->required(),
|
||||
TextInput::make('images_path')
|
||||
->label('Bilder-Pfad')
|
||||
->helperText('Relativer Pfad unter public/storage')
|
||||
->required(),
|
||||
Toggle::make('is_public')
|
||||
->label('Öffentlich')
|
||||
->default(true),
|
||||
Toggle::make('allow_ai_styles')
|
||||
->label('AI-Stile erlauben')
|
||||
->default(true),
|
||||
Toggle::make('allow_print')
|
||||
->label('Drucken erlauben')
|
||||
->default(true),
|
||||
Toggle::make('require_password')
|
||||
->label('Passwortschutz aktiv')
|
||||
->default(false),
|
||||
TextInput::make('password')
|
||||
->label('Neues Passwort')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
DateTimePicker::make('expires_at')
|
||||
->label('Ablaufdatum')
|
||||
->native(false)
|
||||
->seconds(false),
|
||||
TextInput::make('access_duration_minutes')
|
||||
->label('Zugriffsdauer (Minuten)')
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->nullable()
|
||||
->helperText('Optional: Zeitfenster nach dem ersten Unlock.'),
|
||||
]),
|
||||
View::make('filament.components.gallery-link')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
]),
|
||||
]),
|
||||
Tab::make('Sparkbooth')
|
||||
->schema([
|
||||
Section::make('Sparkbooth Upload')
|
||||
->columns(2)
|
||||
->schema([
|
||||
Toggle::make('upload_enabled')
|
||||
->label('Uploads aktivieren')
|
||||
->helperText('Steuert, ob Sparkbooth-Uploads erlaubt sind.')
|
||||
->default(false),
|
||||
Select::make('sparkbooth_response_format')
|
||||
->label('Standard-Antwortformat')
|
||||
->options([
|
||||
'json' => 'JSON',
|
||||
'xml' => 'XML',
|
||||
])
|
||||
->default('json'),
|
||||
TextInput::make('sparkbooth_username')
|
||||
->label('Sparkbooth Benutzername')
|
||||
->helperText('Wird in Sparkbooth unter „Username“ eingetragen. Erlaubt sind Buchstaben, Zahlen sowie ._-')
|
||||
->maxLength(64)
|
||||
->rule('regex:/^[A-Za-z0-9._-]+$/')
|
||||
->unique(table: \App\Models\Gallery::class, column: 'sparkbooth_username', ignoreRecord: true)
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => $state ? Str::of($state)->lower()->trim()->value() : null),
|
||||
TextInput::make('sparkbooth_password')
|
||||
->label('Sparkbooth Passwort (neu)')
|
||||
->password()
|
||||
->revealable()
|
||||
->dehydrated(false)
|
||||
->afterStateHydrated(fn (callable $set) => $set('sparkbooth_password', null))
|
||||
->helperText('Leer lassen, um das bestehende Passwort zu behalten.'),
|
||||
]),
|
||||
View::make('filament.pages.partials.sparkbooth-token')
|
||||
->columnSpanFull()
|
||||
->visible(fn (?object $record) => (bool) $record?->id)
|
||||
->viewData(fn (?object $record) => [
|
||||
'upload_url' => URL::route('api.sparkbooth.upload'),
|
||||
'gallery_url' => $record ? URL::route('gallery.show', $record) : null,
|
||||
'sparkbooth_username' => $record?->sparkbooth_username,
|
||||
'sparkbooth_password' => $record?->sparkbooth_password,
|
||||
'response_format' => $record?->sparkbooth_response_format,
|
||||
'gallery' => $record ? $record->only(['slug', 'images_path']) : null,
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -74,4 +74,15 @@ class Gallery extends Model
|
||||
|
||||
return $password;
|
||||
}
|
||||
|
||||
public function clearSparkboothConnection(): void
|
||||
{
|
||||
$this->forceFill([
|
||||
'upload_token_hash' => null,
|
||||
'upload_token_expires_at' => null,
|
||||
'sparkbooth_username' => null,
|
||||
'sparkbooth_password' => null,
|
||||
'upload_enabled' => false,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ class GallerySeeder extends Seeder
|
||||
$settings = app(GeneralSettings::class);
|
||||
|
||||
Gallery::firstOrCreate(
|
||||
['slug' => Str::uuid()->toString()],
|
||||
['images_path' => 'uploads'],
|
||||
[
|
||||
'slug' => Str::uuid()->toString(),
|
||||
'name' => 'Default Gallery',
|
||||
'title' => $settings->gallery_heading ?? 'Style Gallery',
|
||||
'images_path' => 'uploads',
|
||||
'is_public' => true,
|
||||
'allow_ai_styles' => true,
|
||||
'allow_print' => true,
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class RoleSeeder extends Seeder
|
||||
{
|
||||
@@ -13,7 +12,7 @@ class RoleSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Role::create(['name' => 'admin']);
|
||||
Role::create(['name' => 'user']);
|
||||
Role::firstOrCreate(['name' => 'admin']);
|
||||
Role::firstOrCreate(['name' => 'user']);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
@@ -14,11 +13,15 @@ class UserSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::create([
|
||||
'name' => 'admin',
|
||||
'email' => 'admin@admin.com',
|
||||
'password' => Hash::make('admin'),
|
||||
'role_id' => 1
|
||||
]);
|
||||
$role = \App\Models\Role::firstOrCreate(['name' => 'admin']);
|
||||
|
||||
User::updateOrCreate(
|
||||
['email' => 'admin@admin.com'],
|
||||
[
|
||||
'name' => 'admin',
|
||||
'password' => Hash::make('admin'),
|
||||
'role_id' => $role->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +1,69 @@
|
||||
@php
|
||||
$uploadUrl = $upload_url ?? null;
|
||||
$galleryUrl = $gallery_url ?? null;
|
||||
$username = $sparkbooth_username ?? '—';
|
||||
$password = $sparkbooth_password ?? '—';
|
||||
$format = strtoupper($response_format ?? 'JSON');
|
||||
$imagesPath = $gallery['images_path'] ?? 'uploads';
|
||||
@endphp
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Upload Endpoint</p>
|
||||
<p class="mt-1 break-all font-semibold text-gray-900 dark:text-white">{{ $upload_url }}</p>
|
||||
<p class="mt-1 break-all font-semibold text-gray-900 dark:text-white">{{ $uploadUrl }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Methode: POST (multipart/form-data) mit Username/Password.</p>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Sparkbooth Benutzername</p>
|
||||
<p class="mt-1 break-all font-mono text-sm text-gray-900 dark:text-white">{{ $sparkbooth_username ?? '—' }}</p>
|
||||
<p class="mt-1 break-all font-mono text-sm text-gray-900 dark:text-white">{{ $username }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Eintragen im Sparkbooth Custom Upload Dialog unter „Username“.</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Sparkbooth Passwort</p>
|
||||
<p class="mt-1 break-all font-mono text-sm text-gray-900 dark:text-white">{{ $sparkbooth_password ?? '—' }}</p>
|
||||
<p class="mt-1 break-all font-mono text-sm text-gray-900 dark:text-white">{{ $password }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Eintragen unter „Password“.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Galerie-Link</p>
|
||||
<p class="mt-1 break-all font-semibold text-gray-900 dark:text-white">{{ $gallery_url }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Slug: {{ $gallery['slug'] }}, Pfad: storage/{{ $gallery['images_path'] }}</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Antwortformat</p>
|
||||
<p class="mt-1 font-semibold text-gray-900 dark:text-white">{{ strtoupper($response_format ?? 'JSON') }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Muss mit „JSON Response“ oder „XML Response“ in Sparkbooth übereinstimmen.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Legacy Upload Token</p>
|
||||
<p class="mt-1 break-all font-mono text-sm text-gray-900 dark:text-white">{{ $upload_token }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Optionales Secret (Feld „token“) für ältere Integrationen.</p>
|
||||
<p class="mt-1 font-semibold text-gray-900 dark:text-white">{{ $format }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">In Sparkbooth „JSON Response“ oder „XML Response“ passend auswählen.</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Sparkbooth Hinweise</p>
|
||||
<ul class="mt-2 list-disc space-y-1 pl-4 text-xs text-gray-600 dark:text-gray-300">
|
||||
<li>Uploader „Custom Upload“ wählen.</li>
|
||||
<li>Username & Password wie oben eintragen.</li>
|
||||
<li>Falls JSON Response aktiviert ist, hier ebenfalls JSON wählen (gleiches gilt für XML).</li>
|
||||
<li>Optional: Name/Email/Message Felder in Sparkbooth setzen.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Beispiel (curl)</p>
|
||||
<pre class="mt-2 rounded-xl border border-gray-200 bg-gray-900 p-4 text-xs text-gray-100 dark:border-white/10">curl -X POST {{ $uploadUrl }} \
|
||||
-F "media=@/pfad/zum/foto.jpg" \
|
||||
-F "username={{ $username }}" \
|
||||
-F "password={{ $password }}" \
|
||||
-F "response_format={{ strtolower($format) }}" \
|
||||
-F "name=Guest" \
|
||||
-F "message=Hallo von der Fotobox"</pre>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Galerie-Link</p>
|
||||
<p class="mt-1 break-all font-semibold text-gray-900 dark:text-white">{{ $galleryUrl }}</p>
|
||||
<p class="mt-2 text-xs text-gray-500 dark:text-gray-300">Slug: {{ $gallery['slug'] ?? '—' }}, Pfad: storage/{{ $imagesPath }}</p>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">QR Code (Galerie)</p>
|
||||
<div class="mt-2 rounded-lg border border-gray-200 bg-white p-2 shadow-sm dark:border-white/20 dark:bg-white/5">
|
||||
{!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(200)->margin(1)->generate($gallery_url) !!}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">QR Code (Upload)</p>
|
||||
<div class="mt-2 rounded-lg border border-gray-200 bg-white p-2 shadow-sm dark:border-white/20 dark:bg-white/5">
|
||||
{!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(200)->margin(1)->generate($upload_url.'?token='.$upload_token) !!}
|
||||
{!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(200)->margin(1)->generate($galleryUrl) !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -63,10 +63,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-sm dark:border-white/10 dark:bg-white/5">
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">QR Code (Upload)</p>
|
||||
<div class="mt-2 rounded-lg border border-gray-200 bg-white p-2 shadow-sm dark:border-white/20 dark:bg-white/5">
|
||||
{!! \SimpleSoftwareIO\QrCode\Facades\QrCode::size(200)->margin(1)->generate($result['upload_url'].'?token='.$result['upload_token']) !!}
|
||||
</div>
|
||||
<p class="text-xs uppercase tracking-[0.3em] text-gray-500 dark:text-gray-300">Legacy Upload (Token)</p>
|
||||
<p class="mt-1 text-xs text-gray-500 dark:text-gray-300">Nur falls eine alte Integration noch Token statt Username/Password nutzt.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
53
tests/Feature/Filament/SparkboothConnectionsTest.php
Normal file
53
tests/Feature/Filament/SparkboothConnectionsTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Filament;
|
||||
|
||||
use App\Filament\Pages\SparkboothConnections;
|
||||
use App\Models\Gallery;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SparkboothConnectionsTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_admin_can_delete_connection_without_deleting_gallery(): void
|
||||
{
|
||||
$adminRole = Role::create(['name' => 'Admin']);
|
||||
Role::create(['name' => 'User']);
|
||||
|
||||
$admin = User::factory()->create([
|
||||
'role_id' => $adminRole->id,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin);
|
||||
Filament::setCurrentPanel('admin');
|
||||
|
||||
$gallery = Gallery::factory()->create([
|
||||
'upload_enabled' => true,
|
||||
'sparkbooth_username' => 'spark-test',
|
||||
'sparkbooth_password' => 'secret-123',
|
||||
]);
|
||||
|
||||
$gallery->setUploadToken('tokentest');
|
||||
$gallery->save();
|
||||
|
||||
Livewire::test(SparkboothConnections::class)
|
||||
->callTableAction('deleteConnection', $gallery);
|
||||
|
||||
$updated = $gallery->fresh();
|
||||
|
||||
$this->assertDatabaseHas('galleries', ['id' => $gallery->id]);
|
||||
$this->assertNotNull($updated);
|
||||
$this->assertNull($updated->upload_token_hash);
|
||||
$this->assertNull($updated->upload_token_expires_at);
|
||||
$this->assertNull($updated->sparkbooth_username);
|
||||
$this->assertNull($updated->sparkbooth_password);
|
||||
$this->assertFalse($updated->upload_enabled);
|
||||
$this->assertSame(0, Gallery::query()->whereNotNull('upload_token_hash')->count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user