Repository navigation
add invitation #863
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
nananankona
wants to merge
12
commits into
nextcloud:master
Choose a base branch
from
nananankona:master
base: master
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
add invitation #863
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
82575bf
feat: add invitation codes and invitation links with quota and usage …
nananankona a7ed978
feat: add Japanese translations and per-invitation email verification…
nananankona 492c60e
fix: serialize invitation dates as strings for the admin listThe date…
nananankona a48f749
fix: default skipEmailVerification to false and guard null valuesThe …
nananankona 22f1372
feat: add per-invitation administrator approval bypass
nananankona 8e7e847
fix: portable uses increment and reject malformed emails in domain check
nananankona 0e3c632
fix: admin-only default, entity sync, test stubs, portable SQL
nananankona 571c283
style: apply php-cs-fixer
nananankona c04ef18
fix: use nullable boolean columns in invitation migrations
nananankona 5a3d0da
fix: shorten invitation code index name to 30 chars
nananankona 51b7e5b
fix: set explicit primary key name for invitation table
nananankona 1cd1df5
fix: quote uses column portably in incrementUses
nananankona 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Registration\Controller; | ||
|
|
||
| use OCA\Registration\Db\Invitation; | ||
| use OCA\Registration\Service\InvitationService; | ||
| use OCA\Registration\Service\RegistrationException; | ||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\IL10N; | ||
| use OCP\IRequest; | ||
|
|
||
| class InvitationController extends Controller { | ||
|
|
||
| public function __construct( | ||
| string $appName, | ||
| IRequest $request, | ||
| private InvitationService $invitationService, | ||
| private IL10N $l10n, | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
|
|
||
| public function index(): DataResponse { | ||
| $invitations = array_map( | ||
| fn (Invitation $invitation) => $this->serialize($invitation), | ||
| $this->invitationService->getAll() | ||
| ); | ||
|
|
||
| return new DataResponse($invitations); | ||
| } | ||
|
|
||
| public function create(string $code = '', string $email = '', string $domain = '', string $quota = '', string $max_uses = '', string $expires = '', string $skip_email_verification = '', string $skip_admin_approval = ''): DataResponse { | ||
| if ($code === '') { | ||
| $code = $this->invitationService->generateCode(); | ||
| } | ||
|
|
||
| try { | ||
| $invitation = $this->invitationService->createInvitation( | ||
| $code, | ||
| $email, | ||
| $domain, | ||
| $quota, | ||
| $max_uses !== '' ? (int)$max_uses : null, | ||
| $expires !== '' ? $expires : null, | ||
| $skip_email_verification === 'true' || $skip_email_verification === '1', | ||
| $skip_admin_approval === 'true' || $skip_admin_approval === '1' | ||
| ); | ||
| } catch (RegistrationException $e) { | ||
| return new DataResponse( | ||
| [ | ||
| 'status' => 'error', | ||
| 'message' => $e->getMessage(), | ||
| ], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
| } | ||
|
|
||
| return new DataResponse($this->serialize($invitation)); | ||
| } | ||
|
|
||
| public function destroy(int $id): DataResponse { | ||
| $this->invitationService->deleteById($id); | ||
|
|
||
| return new DataResponse([ | ||
| 'status' => 'success', | ||
| ]); | ||
| } | ||
|
|
||
| private function serialize(Invitation $invitation): array { | ||
| return [ | ||
| 'id' => $invitation->getId(), | ||
| 'code' => $invitation->getCode(), | ||
| 'email' => $invitation->getEmail(), | ||
| 'domain' => $invitation->getDomain(), | ||
| 'quota' => $invitation->getQuota(), | ||
| 'max_uses' => $invitation->getMaxUses(), | ||
| 'uses' => $invitation->getUses(), | ||
| 'expires' => $this->formatDateTime($invitation->getExpires()), | ||
| 'created_at' => $this->formatDateTime($invitation->getCreatedAt()), | ||
| 'skip_email_verification' => $invitation->getSkipEmailVerification() === true, | ||
| 'skip_admin_approval' => $invitation->getSkipAdminApproval() === true, | ||
| 'link' => $this->invitationService->generateLink($invitation), | ||
| ]; | ||
| } | ||
|
|
||
| private function formatDateTime(mixed $value): ?string { | ||
| if ($value === null) { | ||
| return null; | ||
| } | ||
|
|
||
| if ($value instanceof \DateTimeInterface) { | ||
| return $value->format('Y-m-d H:i:s'); | ||
| } | ||
|
|
||
| return (string)$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.
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.
Add
AnonRateLimitandBruteForceProtectionattributes to avoid attackers guessing simple invite codes.