Skip to content

Commit 383b9c5

Browse files
committed
Fix invitation flow
1 parent b28bede commit 383b9c5

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/Http/Controllers/Internal/v1/UserController.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,19 +383,21 @@ public function inviteUser(InviteUserRequest $request)
383383
$user->assignSingleRole($request->input('user.role_uuid'));
384384
}
385385

386-
$invitation = Invite::create([
387-
'company_uuid' => $company->uuid,
388-
'created_by_uuid' => session('user'),
389-
'subject_uuid' => $company->uuid,
390-
'subject_type' => Utils::getMutationType($company),
391-
'protocol' => 'email',
392-
'recipients' => [$user->email],
393-
'reason' => 'join_company',
394-
'meta' => array_filter(['role_uuid' => $request->input('user.role_uuid') ?? $request->input('user.role')]),
395-
'expires_at' => now()->addHours(48),
396-
]);
386+
if (!Invite::isAlreadySentToJoinCompany($user, $company)) {
387+
$invitation = Invite::create([
388+
'company_uuid' => $company->uuid,
389+
'created_by_uuid' => session('user'),
390+
'subject_uuid' => $company->uuid,
391+
'subject_type' => Utils::getMutationType($company),
392+
'protocol' => 'email',
393+
'recipients' => [$user->email],
394+
'reason' => 'join_company',
395+
'meta' => array_filter(['role_uuid' => $request->input('user.role_uuid') ?? $request->input('user.role')]),
396+
'expires_at' => now()->addHours(48),
397+
]);
397398

398-
$user->notify(new UserInvited($invitation));
399+
$user->notify(new UserInvited($invitation));
400+
}
399401

400402
return response()->json(['user' => new $this->resource($user)]);
401403
}

src/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ public function sendInviteFromCompany(?Company $company = null): bool
11491149
'protocol' => 'email',
11501150
'recipients' => [$this->email],
11511151
'reason' => 'join_company',
1152+
'expires_at' => now()->addHours(48),
11521153
]);
11531154

11541155
// notify user

0 commit comments

Comments
 (0)