Add multi-use group invite links with expiry and auto-approval on email confirmation
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m46s
CI / PHPStan (pull_request) Successful in 2m51s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m38s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m46s
CI / PHPStan (pull_request) Successful in 2m51s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m38s
CI / Build Plugin Zip (pull_request) Skipped
A studio admin can generate a shareable group invite link (e.g. for a newsletter) from the Invites page, choosing a required expiry date. Anyone with the link may register while it is valid, in any registration mode: the form collects their own email, they must confirm it via the usual hashed token, and confirming approves the account immediately — group signups never enter the Pending Students queue. - us_invites grows kind (personal/group) and expires_at; an explicit expiry wins over the personal 14-day window. Group links stay pending (multi-use) until revoked or expired. - RegistrationPage: group signups create the account pending with the us_auto_approve marker and send the confirmation email; no auto-login. - EmailConfirmationHandler: auto-approve accounts are approved on confirmation, emailed the approved notice, and redirected to a new us_confirmed=ready notice with a sign-in link. Closes #77 Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -123,6 +123,79 @@ class RegistrationPageTest extends TestCase
|
||||
self::assertSame('confirm', $this->submit(null, true));
|
||||
}
|
||||
|
||||
public function testGroupInviteCreatesPendingAutoApproveAccountEvenWhenClosed(): void
|
||||
{
|
||||
$_POST = [ 'password' => 'password123', 'display_name' => 'Ada', 'email' => '[email protected]' ];
|
||||
|
||||
Functions\when('is_email')->justReturn(true);
|
||||
Functions\when('email_exists')->justReturn(false);
|
||||
Functions\when('wp_insert_user')->justReturn(42);
|
||||
Functions\when('is_wp_error')->justReturn(false);
|
||||
Functions\when('wp_generate_password')->justReturn('rawtok');
|
||||
// confirmUrl internals
|
||||
Functions\when('get_option')->justReturn(0);
|
||||
Functions\when('home_url')->justReturn('http://home.test/');
|
||||
Functions\when('add_query_arg')->alias(static fn (string $k, string $v, string $u): string => $u . '?' . $k . '=' . $v);
|
||||
|
||||
// The auto-approve marker must be set alongside the pending metas.
|
||||
$metas = [];
|
||||
Functions\when('update_user_meta')->alias(static function (int $id, string $key, $value) use (&$metas): bool {
|
||||
$metas[$key] = $value;
|
||||
return true;
|
||||
});
|
||||
|
||||
$user = Mockery::mock(\WP_User::class);
|
||||
Functions\when('get_user_by')->justReturn($user);
|
||||
|
||||
$this->ctx['mailer']->shouldReceive('sendConfirmation')->once()->with($user, Mockery::type('string'));
|
||||
// The link is multi-use: never marked accepted, and no auto-login.
|
||||
$this->ctx['invites']->shouldReceive('markAccepted')->never();
|
||||
Functions\expect('wp_set_auth_cookie')->never();
|
||||
|
||||
$invite = new Invite(
|
||||
email: '',
|
||||
token: 'hash',
|
||||
createdAt: '2024-01-01 00:00:00',
|
||||
kind: Invite::KIND_GROUP,
|
||||
expiresAt: '2024-02-01 23:59:59',
|
||||
id: 9
|
||||
);
|
||||
|
||||
// Registration mode is invite-only (open = false): the group link still works.
|
||||
self::assertSame('confirm_group', $this->submit($invite, false));
|
||||
self::assertSame('1', $metas['us_auto_approve'] ?? null);
|
||||
}
|
||||
|
||||
public function testGroupInviteRendersEditableEmailField(): void
|
||||
{
|
||||
$_REQUEST = ['us_invite' => 'raw-token'];
|
||||
Functions\when('is_user_logged_in')->justReturn(false);
|
||||
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
|
||||
Functions\when('wp_login_url')->justReturn('http://home.test/wp-login.php');
|
||||
Functions\when('wp_nonce_field')->justReturn('');
|
||||
// Invite-only mode: only the group link grants access to the form.
|
||||
$this->ctx['settings']->shouldReceive('openRegistrationEnabled')->andReturn(false);
|
||||
|
||||
$invite = new Invite(
|
||||
email: '',
|
||||
token: 'hash',
|
||||
createdAt: '2024-01-01 00:00:00',
|
||||
kind: Invite::KIND_GROUP,
|
||||
expiresAt: '2024-02-01 23:59:59',
|
||||
id: 9
|
||||
);
|
||||
$this->ctx['invites']->shouldReceive('findByToken')
|
||||
->once()
|
||||
->with(Invite::hashToken('raw-token'))
|
||||
->andReturn($invite);
|
||||
|
||||
$html = $this->ctx['page']->render([]);
|
||||
|
||||
self::assertStringContainsString('<form', $html);
|
||||
self::assertStringContainsString('name="email"', $html);
|
||||
self::assertStringNotContainsString('readonly', $html);
|
||||
}
|
||||
|
||||
public function testClosedModeWithoutInviteReturnsError(): void
|
||||
{
|
||||
$result = $this->submit(null, false);
|
||||
|
||||
Reference in New Issue
Block a user