Repository navigation
feat: let guild accept aliases #1664
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
Open
risadams
wants to merge
12
commits into
dev-null-sh:production
Choose a base branch
from
risadams:production
base: production
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4d2c241
docs: update knowledge base for guild aliases
risadams a508a55
test: add frontend tests for guild aliases
risadams bcf7ec7
feat: integrate guild aliases into frontend components
risadams eada1e5
feat: update frontend types and utility for guild aliases
risadams 3b409cb
test: add backend tests for guild aliases
risadams f4fdf44
feat: include guild aliases in data export
risadams 0ba0deb
refactor: update guild queries to support aliases
risadams 7bf2599
feat: add guild alias API and web routes
risadams cb611ad
feat: add guild alias request validation
risadams ffada21
feat: introduce GuildHandleTaken exception and alias actions
risadams 1164957
feat: add guild alias model and migration
risadams d229302
feat: enforce maximum alias limit per guild
risadams 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,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\UserUpdate; | ||
| use App\Events\UsersUpdated; | ||
| use App\Models\Guild; | ||
| use App\Models\GuildAlias; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class CreateGuildAlias | ||
| { | ||
| /** | ||
| * Held while a hashtag becomes a guild's handle or alias, so it never becomes both. | ||
| */ | ||
| public const string HANDLE_LOCK = 'guild-handle:'; | ||
|
|
||
| /** | ||
| * The alias is checked again under the lock, and left out when its hashtag was taken meanwhile or the user no | ||
| * longer moderates the guild. | ||
| * | ||
| * The request checks the cap before this runs, but aliases added at the same moment each see the others missing. | ||
| * So the cap is counted again here, under the guild's lock: an alias past it is left out. | ||
| */ | ||
| public function handle(Guild $guild, User $user, string $handle): void | ||
| { | ||
| DB::transaction(function () use ($guild, $user, $handle): void { | ||
| DB::select('select pg_advisory_xact_lock(hashtextextended(?, 0))', [self::HANDLE_LOCK.$handle]); | ||
| $guild = Guild::query()->whereKey($guild->id)->lockForUpdate()->firstOrFail(); | ||
|
|
||
| if ($guild->user_id !== $user->id || Guild::query()->where('handle', $handle)->exists() || GuildAlias::query()->where('handle', $handle)->exists()) { | ||
| return; | ||
| } | ||
|
|
||
| if ($guild->aliases()->count() >= GuildAlias::MAX_PER_GUILD) { | ||
| return; | ||
| } | ||
|
|
||
| $guild->aliases()->create(['handle' => $handle]); | ||
|
|
||
| event(new UsersUpdated(DB::table('guild_preferences')->where('guild_id', $guild->id)->pluck('user_id')->push($guild->user_id), UserUpdate::Guilds)); | ||
| }); | ||
| } | ||
| } | ||
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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\UserUpdate; | ||
| use App\Events\UsersUpdated; | ||
| use App\Models\Guild; | ||
| use App\Models\GuildAlias; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class DeleteGuildAlias | ||
| { | ||
| public function handle(Guild $guild, GuildAlias $alias): void | ||
| { | ||
| $alias->delete(); | ||
|
|
||
| event(new UsersUpdated(DB::table('guild_preferences')->where('guild_id', $guild->id)->pluck('user_id')->push($guild->user_id), UserUpdate::Guilds)); | ||
| } | ||
| } |
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,9 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Exceptions; | ||
|
|
||
| use RuntimeException; | ||
|
|
||
| final class GuildHandleTaken extends RuntimeException {} |
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,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Actions\CreateGuildAlias; | ||
| use App\Actions\DeleteGuildAlias; | ||
| use App\Http\Requests\CreateGuildAliasRequest; | ||
| use App\Http\Requests\DeleteGuildAliasRequest; | ||
| use App\Models\Guild; | ||
| use App\Models\GuildAlias; | ||
| use App\Models\User; | ||
| use Illuminate\Container\Attributes\CurrentUser; | ||
| use Illuminate\Http\RedirectResponse; | ||
|
|
||
| final readonly class GuildAliasController | ||
| { | ||
| public function store(CreateGuildAliasRequest $request, Guild $guild, #[CurrentUser] User $user, CreateGuildAlias $action): RedirectResponse | ||
| { | ||
| $action->handle($guild, $user, $request->string('handle')->value()); | ||
|
|
||
| return to_route('guild.show', $guild->handle); | ||
| } | ||
|
|
||
| public function destroy(DeleteGuildAliasRequest $request, Guild $guild, GuildAlias $alias, DeleteGuildAlias $action): RedirectResponse | ||
| { | ||
| $action->handle($guild, $alias); | ||
|
|
||
| return to_route('guild.show', $guild->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
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.