Repository navigation
feat: let organization admins manage members in the organization's settings #1304
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
Merged
+1,542
−120
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
37cabbc
feat: let organization admins manage members in the organization's se…
mnapoli 37493cd
feat: move the organization's color into its settings
mnapoli 2101f55
fix: version the export now that organizations replace claimed organi…
mnapoli 46ea4ae
fix: check the last admin again under a lock, so an organization can'…
mnapoli e1f1921
feat: open organization settings on a Profile tab, and say why the on…
mnapoli 9d805ed
fix: lock the claims while they are copied to organization members, s…
mnapoli b64859f
refactor: render the organization's Profile tab from its own controll…
mnapoli 060557b
refactor: throw when a member change would leave the organization wit…
mnapoli 3331958
refactor: name the exception for the rule it protects, OrganizationMu…
mnapoli eb54ea0
fix: never let admins make themselves admins, which could undo anothe…
mnapoli 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
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,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\OrganizationRole; | ||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
|
|
||
| final readonly class CreateOrganizationMember | ||
| { | ||
| /** | ||
| * Adds the user to the organization as a member, whom an admin can then make an admin. | ||
| */ | ||
| public function handle(Profile $organization, User $user): void | ||
| { | ||
| $organization->members()->attach($user->id, ['role' => OrganizationRole::Member]); | ||
| } | ||
| } |
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,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\OrganizationRole; | ||
| use App\Exceptions\OrganizationMustHaveAnAdmin; | ||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class DeleteOrganizationMember | ||
| { | ||
| /** | ||
| * Removes the member from the organization, whether an admin removed them or they left. The organization is locked | ||
| * while its last admin is checked again, as two admins removing each other at once can both pass the request's | ||
| * check: the second removal then throws instead. | ||
| * | ||
| * @throws OrganizationMustHaveAnAdmin | ||
| */ | ||
| public function handle(Profile $organization, User $member): void | ||
| { | ||
| DB::transaction(function () use ($organization, $member): void { | ||
| Profile::query()->whereKey($organization->id)->lockForUpdate()->first(); | ||
|
|
||
| if ($organization->roleOf($member) === OrganizationRole::Admin && $organization->admins()->whereKeyNot($member->id)->doesntExist()) { | ||
| throw new OrganizationMustHaveAnAdmin($organization); | ||
| } | ||
|
|
||
| $organization->members()->detach($member->id); | ||
| }); | ||
| } | ||
| } |
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,34 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\OrganizationRole; | ||
| use App\Exceptions\OrganizationMustHaveAnAdmin; | ||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class UpdateOrganizationMemberRole | ||
| { | ||
| /** | ||
| * Makes the member an admin or a member. The organization is locked while its last admin is checked again, as two | ||
| * admins making each other members at once can both pass the request's check: the second change then throws | ||
| * instead. | ||
| * | ||
| * @throws OrganizationMustHaveAnAdmin | ||
| */ | ||
| public function handle(Profile $organization, User $member, OrganizationRole $role): void | ||
| { | ||
| DB::transaction(function () use ($organization, $member, $role): void { | ||
| Profile::query()->whereKey($organization->id)->lockForUpdate()->first(); | ||
|
|
||
| if ($role === OrganizationRole::Member && $organization->admins()->whereKeyNot($member->id)->doesntExist()) { | ||
| throw new OrganizationMustHaveAnAdmin($organization); | ||
| } | ||
|
|
||
| $organization->members()->updateExistingPivot($member->id, ['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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| /** | ||
| * Admins manage an organization's members on /dev/null: they add them, remove them, and make them admins or members. | ||
| */ | ||
| enum OrganizationRole: string | ||
| { | ||
| case Admin = 'admin'; | ||
| case Member = 'member'; | ||
| } |
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,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use App\Models\Profile; | ||
| use RuntimeException; | ||
|
|
||
| /** | ||
| * Changing or removing the member would leave the organization without an admin. The request checks it first, so this | ||
| * only happens when two admins change or remove each other at the same moment. | ||
| */ | ||
| final class OrganizationMustHaveAnAdmin extends RuntimeException | ||
| { | ||
| public function __construct(public readonly Profile $organization) | ||
| { | ||
| parent::__construct(__('@:handle needs at least one admin.', ['handle' => $organization->handle])); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.