-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve handling for changing email of invited users (#22644)
- Loading branch information
Showing
12 changed files
with
174 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
use Piwik\NoAccessException; | ||
use Piwik\Option; | ||
use Piwik\Piwik; | ||
use Piwik\Plugins\CoreAdminHome\Emails\UserCreatedEmail; | ||
use Piwik\Plugins\UsersManager\Emails\UserInviteEmail; | ||
use Piwik\Plugins\UsersManager\SystemSettings; | ||
use Piwik\Plugins\SitesManager\API as SitesManagerAPI; | ||
use Piwik\Plugins\UsersManager\API; | ||
|
@@ -1369,6 +1371,11 @@ public function testInviteUserInitialIdSiteError() | |
public function testInviteUserAsSuperUser() | ||
{ | ||
$eventWasFired = false; | ||
$capturedMails = []; | ||
|
||
Piwik::addAction('Mail.send', function (Mail $mail) use (&$capturedMails) { | ||
$capturedMails[] = $mail; | ||
}); | ||
|
||
EventDispatcher::getInstance()->addObserver( | ||
'UsersManager.inviteUser.end', | ||
|
@@ -1380,9 +1387,40 @@ function ($userLogin, $email) use (&$eventWasFired) { | |
); | ||
|
||
$this->api->inviteUser('pendingLoginTest', '[email protected]', 1); | ||
$user = $this->model->isPendingUser('pendingLoginTest'); | ||
self::assertTrue($user); | ||
$isPending = $this->model->isPendingUser('pendingLoginTest'); | ||
self::assertTrue($isPending); | ||
self::assertTrue($eventWasFired); | ||
|
||
self::assertCount(2, $capturedMails); | ||
self::assertInstanceOf(UserCreatedEmail::class, $capturedMails[0]); | ||
self::assertInstanceOf(UserInviteEmail::class, $capturedMails[1]); | ||
} | ||
|
||
public function testChangingEmailOfInvitedUserShouldResendInvitation() | ||
{ | ||
Fixture::createSuperUser(); | ||
$this->api->inviteUser('pendingLoginTest', '[email protected]', 1); | ||
$isPending = $this->model->isPendingUser('pendingLoginTest'); | ||
self::assertTrue($isPending); | ||
|
||
$eventWasFired = false; | ||
$capturedMails = []; | ||
|
||
Piwik::addAction('Mail.send', function (Mail $mail) use (&$capturedMails) { | ||
$capturedMails[] = $mail; | ||
}); | ||
|
||
EventDispatcher::getInstance()->addObserver( | ||
'UsersManager.inviteUser.end', | ||
function ($userLogin, $email) use (&$eventWasFired) { | ||
$eventWasFired = true; | ||
} | ||
); | ||
|
||
$this->api->updateUser('pendingLoginTest', false, '[email protected]', false, Fixture::ADMIN_USER_PASSWORD); | ||
self::assertFalse($eventWasFired); // event should not be fired on email change | ||
self::assertCount(1, $capturedMails); | ||
self::assertInstanceOf(UserInviteEmail::class, $capturedMails[0]); | ||
} | ||
|
||
public function testInviteUserAsAdmin() | ||
|
This file contains 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 |
---|---|---|
|
@@ -249,7 +249,25 @@ describe("UsersManager", function () { | |
expect(await page.screenshotSelector('.usersManager')).to.matchImage('user_created'); | ||
}); | ||
|
||
it('should warn about invitation resend when changing email', async function () { | ||
await page.evaluate(() => $('.userEditForm #user_email').val('[email protected]')); | ||
await page.evaluate(() => $('.userEditForm .matomo-save-button input').click()); | ||
await page.waitForTimeout(100); | ||
await page.waitForFunction(() => $('.modal.open:visible').length) | ||
const modal = await page.jQuery('.modal.open:visible'); | ||
await page.focus('.modal.open #currentUserPassword'); | ||
await page.waitForTimeout(250); | ||
expect(await modal.screenshot()).to.matchImage({ | ||
imageName: 'user_invited_change', | ||
comparisonThreshold: 0.025 | ||
}); | ||
}); | ||
|
||
it('should show the permissions edit when the permissions tab is clicked', async function () { | ||
// close modal from previous step | ||
await (await page.jQuery('.confirm-password-modal .modal-close.modal-no:visible')).click(); | ||
await page.waitForNetworkIdle(); | ||
|
||
await page.click('.userEditForm .menuPermissions'); | ||
await page.mouse.move(0, 0); | ||
|
||
|
@@ -483,7 +501,7 @@ describe("UsersManager", function () { | |
|
||
it('should fail to set superuser access if password is wrong', async function () { | ||
await page.type('.modal.open #currentUserPassword', 'wrongpassword'); | ||
await (await page.jQuery('.modal.open .modal-close:not(.modal-no):visible')).click(); | ||
await page.evaluate(() => $('.modal.open .modal-close:not(.modal-no):visible').click()); | ||
await page.waitForNetworkIdle(); | ||
|
||
await page.waitForSelector('.notification-error', { visible: true }); | ||
|
3 changes: 3 additions & 0 deletions
3
...UsersManager/tests/UI/expected-screenshots/UsersManager_user_invited_change.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.