🛠️ Add anon column to self-hosted services: Update views, models, forms, and migrations to support anonymous service creation and display

This commit is contained in:
HolgerHatGarKeineNode
2025-12-07 06:16:47 +01:00
parent 9ee7ef1771
commit c4cea2ae7a
4 changed files with 36 additions and 6 deletions

View File

@@ -73,7 +73,7 @@ class ServiceForm extends Form
$this->ip = $service->ip;
$this->type = $service->type?->value;
$this->contact = $service->contact;
$this->anonymous = is_null($service->created_by);
$this->anonymous = $service->anon;
}
public function store(): SelfHostedService
@@ -91,7 +91,8 @@ class ServiceForm extends Form
'url_pkdns' => $this->url_pkdns,
'ip' => $this->ip,
'contact' => $this->contact,
'created_by' => $this->anonymous ? null : auth()->id(),
'anon' => $this->anonymous,
'created_by' => auth()->id(),
]);
}
@@ -110,7 +111,7 @@ class ServiceForm extends Form
'url_pkdns' => $this->url_pkdns,
'ip' => $this->ip,
'contact' => $this->contact,
'created_by' => $this->anonymous ? null : ($this->service->created_by ?? auth()->id()),
'anon' => $this->anonymous,
]);
}

View File

@@ -28,6 +28,7 @@ class SelfHostedService extends Model implements HasMedia
'id' => 'integer',
'created_by' => 'integer',
'type' => SelfHostedServiceType::class,
'anon' => 'boolean',
];
protected static function booted(): void

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('self_hosted_services', function (Blueprint $table) {
$table->boolean('anon')->default(false)->after('created_by');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('self_hosted_services', function (Blueprint $table) {
$table->dropColumn('anon');
});
}
};

View File

@@ -159,13 +159,13 @@ class extends Component {
</flux:table.cell>
<flux:table.cell>
@if($service->createdBy)
@if($service->anon || !$service->createdBy)
<span class="text-gray-500 dark:text-gray-400 italic">{{ __('Anonymous') }}</span>
@else
<div class="flex items-center gap-2">
<flux:avatar size="xs" src="{{ $service->createdBy->profile_photo_url }}"/>
<span>{{ Str::length($service->createdBy->name) > 20 ? Str::substr($service->createdBy->name, 0, 4) . '...' . Str::substr($service->createdBy->name, -3) : $service->createdBy->name }}</span>
</div>
@else
<span class="text-gray-500 dark:text-gray-400 italic">{{ __('Anonymous') }}</span>
@endif
</flux:table.cell>