feat: moderation

This commit is contained in:
2026-05-22 11:56:17 +02:00
parent f5b460c650
commit 1c472e46db
43 changed files with 1836 additions and 3 deletions
@@ -0,0 +1,40 @@
<?php
use App\Enums\ModerationCaseStatus;
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('moderation_cases', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->ulidMorphs('caseable');
$table->string('status', 32)->default(ModerationCaseStatus::OPEN->value);
$table->unsignedInteger('reports_count')->default(0);
$table->unsignedSmallInteger('threshold')->default(3);
$table->timestamp('threshold_notified_at')->nullable();
$table->foreignUlid('assigned_to')->nullable()->constrained('users')->nullOnDelete();
$table->foreignUlid('resolved_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('resolved_at')->nullable();
$table->text('resolution_note')->nullable();
$table->timestamps();
$table->unique(['caseable_type', 'caseable_id'], 'moderation_cases_caseable_unique');
$table->index(['status', 'created_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('moderation_cases');
}
};
@@ -0,0 +1,39 @@
<?php
use App\Enums\ReportStatus;
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('reports', function (Blueprint $table) {
$table->ulid('id')->primary();
$table->foreignUlid('moderation_case_id')->constrained('moderation_cases')->cascadeOnDelete();
$table->foreignUlid('reporter_id')->nullable()->constrained('users')->nullOnDelete();
$table->ulidMorphs('reportable');
$table->string('reason', 64);
$table->text('details')->nullable();
$table->string('status', 32)->default(ReportStatus::OPEN->value);
$table->foreignUlid('reviewed_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('reviewed_at')->nullable();
$table->timestamps();
$table->unique(['reporter_id', 'reportable_type', 'reportable_id'], 'reports_reporter_reportable_unique');
$table->index(['status', 'created_at']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('reports');
}
};
@@ -0,0 +1,31 @@
<?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('meal_posts', function (Blueprint $table) {
$table->timestamp('hidden_at')->nullable()->after('deleted_at')->index();
$table->foreignUlid('hidden_by')->nullable()->after('hidden_at')->constrained('users')->nullOnDelete();
$table->text('hidden_reason')->nullable()->after('hidden_by');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('meal_posts', function (Blueprint $table) {
$table->dropForeign(['hidden_by']);
$table->dropColumn(['hidden_at', 'hidden_by', 'hidden_reason']);
});
}
};
@@ -0,0 +1,31 @@
<?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('users', function (Blueprint $table) {
$table->timestamp('suspended_at')->nullable()->after('deleted_at')->index();
$table->foreignUlid('suspended_by')->nullable()->after('suspended_at')->constrained('users')->nullOnDelete();
$table->text('suspended_reason')->nullable()->after('suspended_by');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['suspended_by']);
$table->dropColumn(['suspended_at', 'suspended_by', 'suspended_reason']);
});
}
};