feat: moderation
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\ModerationCaseStatus;
|
||||
use App\Models\MealPosts;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ModerationCase>
|
||||
*/
|
||||
class ModerationCaseFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'caseable_type' => MealPosts::class,
|
||||
'caseable_id' => MealPosts::factory(),
|
||||
'status' => ModerationCaseStatus::OPEN,
|
||||
'reports_count' => 0,
|
||||
'threshold' => 3,
|
||||
'threshold_notified_at' => null,
|
||||
'assigned_to' => null,
|
||||
'resolved_by' => null,
|
||||
'resolved_at' => null,
|
||||
'resolution_note' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\ReportReason;
|
||||
use App\Enums\ReportStatus;
|
||||
use App\Models\MealPosts;
|
||||
use App\Models\ModerationCase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Report>
|
||||
*/
|
||||
class ReportFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'moderation_case_id' => ModerationCase::factory(),
|
||||
'reporter_id' => User::factory(),
|
||||
'reportable_type' => MealPosts::class,
|
||||
'reportable_id' => MealPosts::factory(),
|
||||
'reason' => ReportReason::OTHER,
|
||||
'details' => $this->faker->optional()->sentence(),
|
||||
'status' => ReportStatus::OPEN,
|
||||
'reviewed_by' => null,
|
||||
'reviewed_at' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user