added "members" for an event that help the admins to moderate. members must be invited via email.

This commit is contained in:
Codex Agent
2025-11-09 22:24:40 +01:00
parent 082b78cd43
commit 7ec3db9c59
23 changed files with 836 additions and 101 deletions

View File

@@ -0,0 +1,77 @@
<?php
namespace Database\Factories;
use App\Models\Event;
use App\Models\EventMember;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\EventMember>
*/
class EventMemberFactory extends Factory
{
protected $model = EventMember::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'tenant_id' => Tenant::factory(),
'event_id' => Event::factory(),
'user_id' => null,
'invited_by' => null,
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'role' => 'member',
'status' => 'invited',
'invite_token' => Str::random(32),
'invited_at' => now(),
'joined_at' => null,
'last_activity_at' => null,
'permissions' => null,
];
}
public function admin(): static
{
return $this->state(fn () => [
'role' => 'tenant_admin',
'status' => 'active',
'joined_at' => now(),
]);
}
public function withUser(): static
{
return $this->state(fn (array $attributes) => [
'user_id' => User::factory()->state([
'role' => $attributes['role'] ?? 'member',
]),
'email' => $attributes['email'] ?? $this->faker->unique()->safeEmail(),
]);
}
public function configure(): static
{
return $this->afterMaking(function (EventMember $member): void {
$event = $member->event ?? Event::find($member->event_id);
if ($event && $member->tenant_id !== $event->tenant_id) {
$member->tenant_id = $event->tenant_id;
}
})->afterCreating(function (EventMember $member): void {
$event = $member->event()->withoutGlobalScopes()->first();
if ($event && $member->tenant_id !== $event->tenant_id) {
$member->tenant_id = $event->tenant_id;
$member->save();
}
});
}
}

View File

@@ -0,0 +1,43 @@
<?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::create('event_members', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
$table->foreignId('event_id')->constrained()->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->cascadeOnDelete();
$table->foreignId('invited_by')->nullable()->constrained('users')->nullOnDelete();
$table->string('name')->nullable();
$table->string('email')->nullable();
$table->string('role')->default('member');
$table->string('status')->default('invited');
$table->string('invite_token', 64)->nullable()->unique();
$table->timestamp('invited_at')->nullable();
$table->timestamp('joined_at')->nullable();
$table->timestamp('last_activity_at')->nullable();
$table->json('permissions')->nullable();
$table->timestamps();
$table->unique(['event_id', 'email']);
$table->index(['tenant_id', 'role']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('event_members');
}
};