-
-
Notifications
You must be signed in to change notification settings - Fork 446
Updated invitation flow #1078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
korridor
wants to merge
7
commits into
main
Choose a base branch
from
feature/user-management
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Updated invitation flow #1078
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3267acb
Updated invitation flow, Moved jetstream function to REST endpoints; …
korridor 0ba20fd
add banners for invitation accept
Onatcer 433a6f3
rephrase logged out user invite accept message to clarify that the
Onatcer 28ecfc6
Migrate permission away from Jetstream; Moved update user to REST API
korridor c2a8eac
Add migration to lower case the user emails
korridor dc70eb7
Add more tests
korridor 5b756be
Updated composer dependencies
korridor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,3 +42,4 @@ yarn-error.log | |
| /data | ||
| /config/caddy | ||
| /config/composer | ||
| /AGENTS.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Events; | ||
|
|
||
| use App\Models\Member; | ||
| use App\Models\Organization; | ||
| use App\Models\User; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| class MemberAdded | ||
| { | ||
| use Dispatchable; | ||
|
|
||
| public Member $member; | ||
|
|
||
| public Organization $organization; | ||
|
|
||
| public User $user; | ||
|
|
||
| public function __construct(Member $member, Organization $organization, User $user) | ||
| { | ||
| $this->member = $member; | ||
| $this->organization = $organization; | ||
| $this->user = $user; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Events; | ||
|
|
||
| use App\Enums\Role; | ||
| use App\Models\Organization; | ||
| use App\Models\User; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| class MemberAdding | ||
| { | ||
| use Dispatchable; | ||
|
|
||
| public User $user; | ||
|
|
||
| public Organization $organization; | ||
|
|
||
| public Role $role; | ||
|
|
||
| public function __construct(User $user, Organization $organization, Role $role) | ||
| { | ||
| $this->user = $user; | ||
| $this->organization = $organization; | ||
| $this->role = $role; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/Http/Controllers/Web/OrganizationInvitationController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers\Web; | ||
|
|
||
| use App\Enums\Role; | ||
| use App\Models\OrganizationInvitation; | ||
| use App\Models\User; | ||
| use App\Service\MemberService; | ||
| use Illuminate\Http\RedirectResponse; | ||
| use RuntimeException; | ||
|
|
||
| class OrganizationInvitationController extends Controller | ||
| { | ||
| public function accept(OrganizationInvitation $invitation, MemberService $memberService): RedirectResponse | ||
| { | ||
| $email = strtolower($invitation->email); | ||
| $role = Role::tryFrom($invitation->role); | ||
| if ($role === null || $role === Role::Owner || $role === Role::Placeholder) { | ||
| throw new RuntimeException('Invalid role'); | ||
| } | ||
|
|
||
| $newOrganizationMember = User::query() | ||
| ->where('email', $email) | ||
| ->where('is_placeholder', '=', false) | ||
| ->first(); | ||
|
|
||
| if ($newOrganizationMember === null) { | ||
| if ($invitation->accepted_at === null) { | ||
| $invitation->accepted_at = now(); | ||
| $invitation->save(); | ||
| } | ||
|
|
||
| return redirect(route('register', [ | ||
| 'bannerStyle' => 'info', | ||
| 'bannerText' => __('Please create an account to finish joining the :organization organization.', [ | ||
| 'organization' => $invitation->organization->name, | ||
| ]), | ||
| ])); | ||
| } else { | ||
| $organization = $invitation->organization; | ||
| if ($memberService->isEmailAlreadyMember($organization, $email)) { | ||
| return redirect(route('dashboard', [ | ||
| 'bannerStyle' => 'danger', | ||
| 'bannerText' => __('You are already a member of the :organization organization.', [ | ||
| 'organization' => $organization->name, | ||
| ]), | ||
| ])); | ||
| } | ||
|
|
||
| $memberService->addMember($newOrganizationMember, $organization, $role); | ||
|
|
||
| $invitation->delete(); | ||
|
|
||
| return redirect(route('dashboard', [ | ||
| 'bannerStyle' => 'success', | ||
| 'bannerText' => __('Great! You have accepted the invitation to join the :organization organization.', [ | ||
| 'organization' => $invitation->organization->name, | ||
| ]), | ||
| ])); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know why it is needed now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the
switchTeamor the refresh?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refresh. The comment just sounded like a leftover.