feat: add installer, ranks/groups enhancements, and founder protections

This commit is contained in:
2026-01-23 19:26:35 +01:00
parent 24c16ed0dd
commit d4fb86633b
43 changed files with 6176 additions and 4039 deletions

View File

@@ -13,7 +13,9 @@ class PostController extends Controller
public function index(Request $request): JsonResponse
{
$query = Post::query()->withoutTrashed()->with([
'user' => fn ($query) => $query->withCount('posts')->with('rank'),
'user' => fn ($query) => $query
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
->with(['rank', 'roles']),
]);
$threadParam = $request->query('thread');
@@ -49,7 +51,9 @@ class PostController extends Controller
]);
$post->loadMissing([
'user' => fn ($query) => $query->withCount('posts')->with('rank'),
'user' => fn ($query) => $query
->withCount(['posts', 'thanksGiven', 'thanksReceived'])
->with(['rank', 'roles']),
]);
return response()->json($this->serializePost($post), 201);
@@ -95,14 +99,38 @@ class PostController extends Controller
'user_posts_count' => $post->user?->posts_count,
'user_created_at' => $post->user?->created_at?->toIso8601String(),
'user_location' => $post->user?->location,
'user_thanks_given_count' => $post->user?->thanks_given_count ?? 0,
'user_thanks_received_count' => $post->user?->thanks_received_count ?? 0,
'user_rank_name' => $post->user?->rank?->name,
'user_rank_badge_type' => $post->user?->rank?->badge_type,
'user_rank_badge_text' => $post->user?->rank?->badge_text,
'user_rank_badge_url' => $post->user?->rank?->badge_image_path
? Storage::url($post->user->rank->badge_image_path)
: null,
'user_rank_color' => $post->user?->rank?->color,
'user_group_color' => $this->resolveGroupColor($post->user),
'created_at' => $post->created_at?->toIso8601String(),
'updated_at' => $post->updated_at?->toIso8601String(),
];
}
private function resolveGroupColor(?\App\Models\User $user): ?string
{
if (!$user) {
return null;
}
$roles = $user->roles;
if (!$roles) {
return null;
}
foreach ($roles->sortBy('name') as $role) {
if (!empty($role->color)) {
return $role->color;
}
}
return null;
}
}