Repository navigation
feat: let API clients create guilds #1631
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
paulinevos
merged 4 commits into
dev-null-sh:production
from
WendellAdriel:feat/api-guild-create
Nov 23, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
58bf654
refactor: share the guild creation rules between requests
WendellAdriel 940606e
test: cover creating a guild through the API
WendellAdriel b7bb5e0
feat: let API clients create guilds
WendellAdriel 1849069
fix: refuse a flagged guild whose hashtag was taken after validation
WendellAdriel 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
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,74 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use App\Enums\Feature; | ||
| use App\Models\User; | ||
| use App\Rules\FlaggedGuild; | ||
| use App\Services\EmojiShortcodes; | ||
| use App\Services\Features; | ||
| use Closure; | ||
| use Illuminate\Auth\Access\Response; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
| use Illuminate\Http\UploadedFile; | ||
| use Illuminate\Validation\Rules\In; | ||
| use Illuminate\Validation\Rules\Unique; | ||
| use Illuminate\Validation\Validator; | ||
|
|
||
| final class CreateApiGuildRequest extends FormRequest | ||
| { | ||
| private bool $isFlagged = false; | ||
|
|
||
| public function authorize(Features $features): Response | ||
| { | ||
| return $features->available(Feature::Guilds, $this->user()) ? Response::allow() : Response::denyAsNotFound(); | ||
| } | ||
|
|
||
| /** @return array<string, list<string|In|Unique>> */ | ||
| public function rules(EmojiShortcodes $emoji): array | ||
| { | ||
| return CreateGuildRequest::guildRules($emoji); | ||
| } | ||
|
|
||
| /** @return list<Closure(Validator): void> */ | ||
| public function after(FlaggedGuild $flagged): array | ||
| { | ||
| return [function (Validator $validator) use ($flagged): void { | ||
| if ($validator->errors()->isNotEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| $user = $this->user(); | ||
| assert($user instanceof User); | ||
| $icon = $this->file('images.0'); | ||
| $this->isFlagged = CreateGuildRequest::validateNewGuild($validator, $flagged, $user, $this->string('handle')->value(), $this->string('name')->value(), $this->string('description')->value(), $icon instanceof UploadedFile ? $icon : null); | ||
| }]; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the moderation flagged the guild, so it waits for an admin instead of being published. | ||
| */ | ||
| public function isFlagged(): bool | ||
| { | ||
| return $this->isFlagged; | ||
| } | ||
|
|
||
| /** @return array<string, string> */ | ||
| public function messages(): array | ||
| { | ||
| return CreateGuildRequest::guildMessages(); | ||
| } | ||
|
|
||
| public function prepareForValidation(): void | ||
| { | ||
| if (! $this->has('handle') && is_string($this->input('name'))) { | ||
| $this->merge(['handle' => CreateGuildRequest::hashtagOf($this->string('name')->value())]); | ||
| } | ||
|
|
||
| if (is_string($this->input('handle'))) { | ||
| $this->merge(['handle' => $this->string('handle')->trim()->lower()->value()]); | ||
| } | ||
| } | ||
| } |
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.