Skip to content

Commit 4d39da9

Browse files
committed
Improve Admin Profiles page ✨
1 parent a29b82b commit 4d39da9

File tree

5 files changed

+367
-58
lines changed

5 files changed

+367
-58
lines changed

app/Http/Controllers/Api/AdminController.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Http\Controllers\Controller;
77
use App\Http\Resources\AdminHashtagResource;
88
use App\Http\Resources\AdminInstanceResource;
9+
use App\Http\Resources\AdminProfileResource;
910
use App\Http\Resources\CommentReplyResource;
1011
use App\Http\Resources\CommentResource;
1112
use App\Http\Resources\ProfileResource;
@@ -191,6 +192,10 @@ public function profiles(Request $request)
191192
$query->where('local', true);
192193
}
193194

195+
if (! in_array($sort, ['disabled', 'suspended', 'deleted'])) {
196+
$query->where('status', 1);
197+
}
198+
194199
if (! empty($search)) {
195200
if (str_starts_with($search, 'bio:')) {
196201
$bio = trim(substr($search, 4));
@@ -216,7 +221,7 @@ public function profiles(Request $request)
216221

217222
$profiles = $query->cursorPaginate(10)->withQueryString();
218223

219-
return ProfileResource::collection($profiles);
224+
return AdminProfileResource::collection($profiles);
220225
}
221226

222227
public function profileShow(Request $request, $id)
@@ -264,20 +269,21 @@ public function profilePermissionUpdate(Request $request, $id)
264269
]);
265270

266271
$profile = Profile::find($id);
267-
$user = User::whereProfileId($id)->firstOrFail();
268272

269273
if (! $profile) {
270274
return $this->error('Ooops!');
271275
}
272276

273-
if ($profile->user && $profile->user->is_admin) {
274-
return $this->success();
275-
}
276-
277277
$oldValues = $profile->only(['can_upload', 'can_follow', 'can_comment', 'can_like', 'can_share']);
278278

279279
$profile->update($validated);
280-
$user->update($userValidated);
280+
if ($profile->local) {
281+
if ($profile->user && $profile->user->is_admin) {
282+
return $this->success();
283+
}
284+
$user = User::whereProfileId($id)->firstOrFail();
285+
$user->update($userValidated);
286+
}
281287

282288
app(AdminAuditLogService::class)->logProfileAdminPermissionUpdate($request->user(), $profile, ['old' => $oldValues, 'new' => $validated]);
283289

@@ -1063,7 +1069,19 @@ private function applySortingJoin($query, $sort, $tableName = null)
10631069
'count_desc' => ['count', 'desc'],
10641070
];
10651071

1066-
if ($sort && isset($sortOptions[$sort])) {
1072+
if ($sort && $sort == 'suspended') {
1073+
$query->where('status', 6);
1074+
1075+
return $query;
1076+
} elseif ($sort && $sort == 'disabled') {
1077+
$query->where('status', 7);
1078+
1079+
return $query;
1080+
} elseif ($sort && $sort == 'deleted') {
1081+
$query->where('status', 8);
1082+
1083+
return $query;
1084+
} elseif ($sort && isset($sortOptions[$sort])) {
10671085
[$column, $direction] = $sortOptions[$sort];
10681086

10691087
$tablePrefix = $columnTableMap[$column].'.';
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace App\Http\Resources;
4+
5+
use App\Models\Profile;
6+
use App\Services\AvatarService;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Http\Resources\Json\JsonResource;
9+
10+
/**
11+
* @mixin Profile
12+
*/
13+
class AdminProfileResource extends JsonResource
14+
{
15+
public function __construct(Profile $resource)
16+
{
17+
parent::__construct($resource);
18+
}
19+
20+
/**
21+
* Transform the resource into an array.
22+
*
23+
* @return array<string, mixed>
24+
*/
25+
public function toArray(Request $request): array
26+
{
27+
$avatarUrl = $this->avatar ?? url('/storage/avatars/default.jpg');
28+
29+
if ($this->uri || $this->domain) {
30+
$avatarUrl = AvatarService::remote($this->id);
31+
}
32+
33+
return [
34+
'id' => (string) $this->id,
35+
'name' => $this->name ?? 'user'.$this->id,
36+
'avatar' => $avatarUrl,
37+
'username' => $this->username,
38+
'is_owner' => false,
39+
'local' => (bool) $this->local,
40+
'bio' => $this->bio,
41+
'post_count' => $this->video_count,
42+
'follower_count' => $this->followers,
43+
'following_count' => $this->following,
44+
'url' => url('/@'.$this->username),
45+
'is_blocking' => null,
46+
'links' => $this->links ?? [],
47+
'is_suspended' => $this->is_suspended,
48+
'is_hidden' => $this->is_hidden,
49+
'status' => $this->status,
50+
'status_desc' => $this->getStatusDescription(),
51+
'can_upload' => $this->can_upload,
52+
'can_share' => $this->can_share,
53+
'can_like' => $this->can_like,
54+
'can_comment' => $this->can_comment,
55+
'can_follow' => $this->can_follow,
56+
'created_at' => $this->created_at->format('c'),
57+
];
58+
}
59+
}

app/Models/Profile.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,13 @@ class Profile extends Model
173173
'status' => 'integer',
174174
'links' => 'array',
175175
'local' => 'boolean',
176+
'is_suspended' => 'boolean',
177+
'is_hidden' => 'boolean',
178+
'can_upload' => 'boolean',
179+
'can_follow' => 'boolean',
180+
'can_comment' => 'boolean',
181+
'can_share' => 'boolean',
182+
'can_like' => 'boolean',
176183
'discoverable' => 'boolean',
177184
'manuallyApprovesFollowers' => 'boolean',
178185
];

resources/js/pages/admin/ProfileShow.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
<div class="flex items-center space-x-3 mt-4 sm:mt-0">
8585
<button
86-
v-if="profile.local"
86+
v-if="profile.local && profile.status != 'deleted'"
8787
@click="toggleVerification"
8888
:class="[
8989
'px-6 py-3 text-sm font-medium rounded-lg transition-colors',
@@ -118,7 +118,7 @@
118118
</div>
119119
</div>
120120

121-
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
121+
<div v-if="profile?.status != 'deleted'" class="grid grid-cols-2 md:grid-cols-4 gap-4">
122122
<router-link :to="`/admin/videos?q=${profile.username}`" class="cursor-pointer">
123123
<div class="card-info">
124124
<div class="card-info-value">
@@ -188,7 +188,7 @@
188188
Account Information
189189
</h3>
190190
<div class="space-y-4">
191-
<div>
191+
<div v-if="profile?.email">
192192
<label class="block text-xs font-medium text-gray-500 dark:text-gray-400"
193193
>Email</label
194194
>
@@ -222,7 +222,7 @@
222222
Permissions & Restrictions
223223
</h3>
224224
<div class="space-y-6">
225-
<div>
225+
<div v-if="profile.status != 'deleted'">
226226
<div class="flex items-center justify-between mb-3">
227227
<div>
228228
<h4 class="text-sm font-medium text-gray-900 dark:text-white">
@@ -258,7 +258,7 @@
258258
</div>
259259
</div>
260260

261-
<div>
261+
<div v-if="profile.status != 'deleted'">
262262
<div class="flex items-center justify-between mb-3">
263263
<div>
264264
<h4 class="text-sm font-medium text-gray-900 dark:text-white">
@@ -294,7 +294,7 @@
294294
</div>
295295
</div>
296296

297-
<div>
297+
<div v-if="profile.status != 'deleted'">
298298
<div class="flex items-center justify-between mb-3">
299299
<div>
300300
<h4 class="text-sm font-medium text-gray-900 dark:text-white">
@@ -330,7 +330,7 @@
330330
</div>
331331
</div>
332332

333-
<div>
333+
<div v-if="profile.status != 'deleted'">
334334
<div class="flex items-center justify-between mb-3">
335335
<div>
336336
<h4 class="text-sm font-medium text-gray-900 dark:text-white">
@@ -383,6 +383,7 @@
383383
</div>
384384

385385
<div
386+
v-if="profile.status != 'deleted'"
386387
class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-6"
387388
>
388389
<h3 class="text-lg font-semibold text-red-900 dark:text-red-200 mb-2">Danger Zone</h3>
@@ -677,9 +678,11 @@ watch(
677678
.card-info {
678679
@apply bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-6;
679680
}
681+
680682
.card-info-value {
681683
@apply text-2xl font-bold text-gray-900 dark:text-white;
682684
}
685+
683686
.card-info-label {
684687
@apply text-sm text-gray-600 dark:text-gray-400;
685688
}

0 commit comments

Comments
 (0)