Skip to content

Commit cafaa10

Browse files
committed
feat(profile): unverified contributor badge, board of directors, batch, and website fields
1 parent 20b8476 commit cafaa10

17 files changed

Lines changed: 729 additions & 136 deletions

‎app/Http/Controllers/AuthController.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\AppSetting;
56
use App\Models\User;
67
use App\Models\UserAppreciation;
78
use App\Notifications\UserAppreciationNotification;
@@ -26,7 +27,11 @@ public function index()
2627
return redirect()->route('me');
2728
}
2829

29-
return Inertia::render('auth/Login');
30+
$allowRegistration = (bool) AppSetting::get('allow_registration', true);
31+
32+
return Inertia::render('auth/Login', [
33+
'allowRegistration' => $allowRegistration,
34+
]);
3035
}
3136

3237
public function redirectToGoogle(Request $request)
@@ -83,6 +88,11 @@ public function handleGoogleCallback(Request $request)
8388
return redirect()->intended($defaultUrl);
8489
}
8590

91+
$allowRegistration = (bool) AppSetting::get('allow_registration', true);
92+
if (! $allowRegistration) {
93+
return redirect()->route('login')->with('error', 'রেজিস্ট্রেশন সাময়িকভাবে স্থগিত রাখা হয়েছে। পূর্বে তৈরিকৃত অ্যাকাউন্ট দিয়ে লগইন করতে পারেন।');
94+
}
95+
8696
$rawName = $googleUser->getName() ?? $googleUser->getNickname() ?? '';
8797
$cleanGoogleName = ChatProfanityFilter::hasProfanity($rawName) ? 'Student' : $rawName;
8898

‎app/Http/Controllers/UserProfileController.php‎

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function show(string $username)
3737
'facebook' => $user->facebook,
3838
'instagram' => $user->instagram,
3939
'github' => $user->github,
40+
'website' => $user->website,
4041
'created_at' => $user->created_at?->format('M Y') ?? '2026',
4142
'is_verified' => $user->is_verified,
4243
'is_online' => $user->isOnline(),
@@ -85,18 +86,39 @@ public function show(string $username)
8586
}
8687
}
8788

88-
$appreciators = $user->appreciators()
89+
$authId = auth()->id();
90+
91+
$rawAppreciators = $user->appreciators()
8992
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.is_verified'])
9093
->latest('user_appreciations.id')
9194
->take(15)
9295
->get();
9396

94-
$appreciating = $user->appreciatingUsers()
97+
$rawAppreciating = $user->appreciatingUsers()
9598
->select(['users.id', 'users.name', 'users.username', 'users.image_path', 'users.institution', 'users.is_verified'])
9699
->latest('user_appreciations.id')
97100
->take(15)
98101
->get();
99102

103+
$allModalUserIds = $rawAppreciators->pluck('id')->concat($rawAppreciating->pluck('id'))->unique();
104+
$myAppreciatingIds = $authId && $allModalUserIds->isNotEmpty()
105+
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $allModalUserIds)->pluck('user_id')->flip()->toArray()
106+
: [];
107+
108+
$appreciators = $rawAppreciators->map(function ($u) use ($myAppreciatingIds) {
109+
$data = $u->toArray();
110+
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);
111+
112+
return $data;
113+
});
114+
115+
$appreciating = $rawAppreciating->map(function ($u) use ($myAppreciatingIds) {
116+
$data = $u->toArray();
117+
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);
118+
119+
return $data;
120+
});
121+
100122
$pokeEnabled = (bool) AppSetting::get('peer_poke_enabled', true);
101123
$canPoke = $pokeEnabled && ! $isOwner && ($user->allow_pokes ?? true);
102124
$isPokeOnCooldown = $canPoke && auth()->check() && Cache::has('study_poke:'.auth()->id().":{$user->id}");
@@ -281,9 +303,8 @@ private function getSyllabusProgress(User $user): array
281303
$trackableSubjects = $subjectsQuery
282304
->with(['nodes' => function ($query) {
283305
$query->where('is_trackable', true)
284-
->with('parent:id,name,sort_order')
285306
->orderBy('sort_order', 'asc')
286-
->select('id', 'subject_id', 'parent_id', 'name', 'slug', 'sort_order', 'weight');
307+
->select('id', 'subject_id', 'name', 'slug', 'sort_order', 'weight');
287308
}])
288309
->get(['id', 'name', 'slug', 'course', 'tailwind_format', 'icon', 'sort_order']);
289310

@@ -322,12 +343,6 @@ private function getSyllabusProgress(User $user): array
322343
'name' => $node->name,
323344
'weight' => $nodeWeight,
324345
'is_completed' => $isDone,
325-
'parent_id' => $node->parent_id,
326-
'parent' => $node->parent ? [
327-
'id' => $node->parent->id,
328-
'name' => $node->parent->name,
329-
'sort_order' => $node->parent->sort_order,
330-
] : null,
331346
];
332347
}
333348

@@ -376,8 +391,20 @@ public function appreciators(Request $request, User $user): JsonResponse
376391
->latest('user_appreciations.id')
377392
->simplePaginate(15);
378393

394+
$authId = auth()->id();
395+
$myAppreciatingIds = $authId
396+
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $paginator->pluck('id'))->pluck('user_id')->flip()->toArray()
397+
: [];
398+
399+
$items = collect($paginator->items())->map(function ($u) use ($myAppreciatingIds) {
400+
$data = $u->toArray();
401+
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);
402+
403+
return $data;
404+
})->all();
405+
379406
return response()->json([
380-
'users' => $paginator->items(),
407+
'users' => $items,
381408
'has_more' => $paginator->hasMorePages(),
382409
'current_page' => $paginator->currentPage(),
383410
]);
@@ -393,8 +420,20 @@ public function appreciating(Request $request, User $user): JsonResponse
393420
->latest('user_appreciations.id')
394421
->simplePaginate(15);
395422

423+
$authId = auth()->id();
424+
$myAppreciatingIds = $authId
425+
? UserAppreciation::where('appreciator_id', $authId)->whereIn('user_id', $paginator->pluck('id'))->pluck('user_id')->flip()->toArray()
426+
: [];
427+
428+
$items = collect($paginator->items())->map(function ($u) use ($myAppreciatingIds) {
429+
$data = $u->toArray();
430+
$data['is_appreciated'] = isset($myAppreciatingIds[$u->id]);
431+
432+
return $data;
433+
})->all();
434+
396435
return response()->json([
397-
'users' => $paginator->items(),
436+
'users' => $items,
398437
'has_more' => $paginator->hasMorePages(),
399438
'current_page' => $paginator->currentPage(),
400439
]);

‎app/Http/Requests/Profile/UpdateProfileRequest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ public function rules(): array
4040
'about' => ['sometimes', 'nullable', 'string', 'max:255', new CleanText],
4141
'institution' => ['sometimes', 'nullable', 'string', 'max:255', new CleanText],
4242
'activity_privacy' => ['sometimes', 'string', Rule::in(['public', 'appreciators_only', 'private'])],
43+
'batch' => ['sometimes', 'nullable', 'string', 'max:32'],
4344
'allow_pokes' => ['sometimes', 'boolean'],
4445
'facebook' => ['sometimes', 'nullable', 'string', 'max:255'],
4546
'instagram' => ['sometimes', 'nullable', 'string', 'max:255'],
4647
'github' => ['sometimes', 'nullable', 'string', 'max:255'],
48+
'website' => ['sometimes', 'nullable', 'string', 'max:255'],
4749
'receive_emails' => ['sometimes', 'boolean'],
4850
];
4951
}

‎app/Http/Requests/User/StoreUserRequest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function rules(): array
2929
'username' => ['nullable', 'string', 'min:3', 'max:30', 'regex:/^[a-zA-Z0-9_]+$/', 'unique:users,username', new CleanText],
3030
'email' => ['required', 'email', 'unique:users,email'],
3131
'is_verified' => ['sometimes', 'boolean'],
32+
'is_board_member' => ['sometimes', 'boolean'],
3233
'priority' => ['sometimes', 'nullable', 'integer', 'min:0', 'max:1000000'],
3334
'role' => ['nullable', 'string'],
3435
'permissions' => ['nullable', 'array'],
@@ -40,6 +41,7 @@ public function rules(): array
4041
'facebook' => ['nullable', 'string', 'max:255'],
4142
'instagram' => ['nullable', 'string', 'max:255'],
4243
'github' => ['nullable', 'string', 'max:255'],
44+
'website' => ['nullable', 'string', 'max:255'],
4345
];
4446
}
4547

‎app/Http/Requests/User/UpdateUserRequest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public function rules(): array
4545
'facebook' => ['sometimes', 'nullable', 'string', 'max:255'],
4646
'instagram' => ['sometimes', 'nullable', 'string', 'max:255'],
4747
'github' => ['sometimes', 'nullable', 'string', 'max:255'],
48+
'website' => ['sometimes', 'nullable', 'string', 'max:255'],
4849
'is_verified' => ['sometimes', 'boolean'],
50+
'is_board_member' => ['sometimes', 'boolean'],
4951
'priority' => ['sometimes', 'nullable', 'integer', 'min:0', 'max:1000000'],
5052
'role' => ['sometimes', 'nullable', 'string'],
5153
'permissions' => ['sometimes', 'nullable', 'array'],

‎app/Models/User.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class User extends Authenticatable
4444
'email',
4545
'receive_emails',
4646
'is_verified',
47+
'is_board_member',
4748
'priority',
4849
'google_id',
4950
'email_verified_at',
@@ -55,10 +56,12 @@ class User extends Authenticatable
5556
'activity_privacy',
5657
'curriculum',
5758
'group',
59+
'batch',
5860
'allow_pokes',
5961
'facebook',
6062
'instagram',
6163
'github',
64+
'website',
6265
'optional_subject_ids',
6366
'last_active_at',
6467
'last_seen_at',

‎app/Notifications/SupportTicketUpdatedNotification.php‎

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Models\SupportTicket;
66
use Illuminate\Bus\Queueable;
77
use Illuminate\Contracts\Queue\ShouldQueue;
8-
use Illuminate\Notifications\Messages\MailMessage;
98
use Illuminate\Notifications\Notification;
109
use Illuminate\Support\Str;
1110

@@ -18,45 +17,13 @@ public function __construct(
1817
) {}
1918

2019
/**
21-
* Get the notification's delivery channels.
20+
* Get the notification's delivery channels (In-app database only).
2221
*
2322
* @return array<int, string>
2423
*/
2524
public function via(object $notifiable): array
2625
{
27-
$channels = ['database'];
28-
29-
if (! empty($notifiable->email) && ($notifiable->receive_emails ?? true)) {
30-
$channels[] = 'mail';
31-
}
32-
33-
return $channels;
34-
}
35-
36-
/**
37-
* Get the mail representation of the notification.
38-
*/
39-
public function toMail(object $notifiable): MailMessage
40-
{
41-
$statusLabel = ucfirst(str_replace('_', ' ', $this->ticket->status));
42-
$lines = [
43-
"Your support ticket #{$this->ticket->ticket_number} (\"{$this->ticket->subject}\") has an update from our team.",
44-
"Current Status: {$statusLabel}",
45-
];
46-
47-
if ($this->ticket->admin_reply) {
48-
$lines[] = "Staff Reply: \"{$this->ticket->admin_reply}\"";
49-
}
50-
51-
return (new MailMessage)
52-
->subject("Support Ticket #{$this->ticket->ticket_number} Updated 🎫")
53-
->view('emails.default', [
54-
'subject' => "Ticket #{$this->ticket->ticket_number} Updated",
55-
'greeting' => "Hello {$notifiable->name},",
56-
'lines' => $lines,
57-
'actionText' => 'View My Tickets',
58-
'actionUrl' => route('support.my-tickets'),
59-
]);
26+
return ['database'];
6027
}
6128

6229
/**

‎app/Notifications/UserAppreciationNotification.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function toArray(object $notifiable): array
7070
'type' => 'user_appreciation',
7171
'title' => "{$this->appreciator->name} appreciated you!",
7272
'message' => "You have {$this->totalAppreciations} community appreciations.",
73-
'url' => route('user.profile', $notifiable->username),
73+
'url' => route('user.profile', $notifiable->username).'#appreciators',
7474
'appreciator_id' => $this->appreciator->id,
7575
'total_appreciations' => $this->totalAppreciations,
7676
'count' => 1,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('users', function (Blueprint $table) {
15+
$table->string('batch', 32)->nullable()->after('group');
16+
$table->index('batch');
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::table('users', function (Blueprint $table) {
26+
$table->dropIndex(['batch']);
27+
$table->dropColumn('batch');
28+
});
29+
}
30+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('users', function (Blueprint $table) {
15+
$table->string('website')->nullable()->after('github');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('users', function (Blueprint $table) {
25+
$table->dropColumn('website');
26+
});
27+
}
28+
};

0 commit comments

Comments
 (0)