Skip to content

Commit e65431d

Browse files
authored
Merge pull request #30491 from nextcloud/fix/30374/email-verification
Fix email verification
2 parents 1a235f5 + 19a3656 commit e65431d

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/private/Accounts/AccountManager.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,10 @@ protected function checkEmailVerification(IAccount $updatedAccount, array $oldDa
388388
} catch (PropertyDoesNotExistException $e) {
389389
return;
390390
}
391-
$oldMail = isset($oldData[self::PROPERTY_EMAIL]) ? $oldData[self::PROPERTY_EMAIL]['value']['value'] : '';
391+
392+
$oldMailIndex = array_search(self::PROPERTY_EMAIL, array_column($oldData, 'name'), true);
393+
$oldMail = $oldMailIndex !== false ? $oldData[$oldMailIndex]['value'] : '';
394+
392395
if ($oldMail !== $property->getValue()) {
393396
$this->jobList->add(
394397
VerifyUserData::class,

tests/lib/Accounts/AccountManagerTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use OC\Accounts\Account;
2626
use OC\Accounts\AccountManager;
27+
use OCA\Settings\BackgroundJobs\VerifyUserData;
2728
use OCP\Accounts\IAccountManager;
2829
use OCP\BackgroundJob\IJobList;
2930
use OCP\Defaults;
@@ -770,4 +771,42 @@ public function searchDataProvider(): array {
770771
],
771772
];
772773
}
774+
775+
public function dataCheckEmailVerification(): array {
776+
return [
777+
[$this->makeUser('steve', 'Steve Smith', '[email protected]'), null],
778+
[$this->makeUser('emma', 'Emma Morales', '[email protected]'), '[email protected]'],
779+
[$this->makeUser('[email protected]', 'Sarah Foster', '[email protected]'), null],
780+
[$this->makeUser('[email protected]', 'Cole Harrison', '[email protected]'), '[email protected]'],
781+
[$this->makeUser('8d29e358-cf69-4849-bbf9-28076c0b908b', 'Alice McPherson', '[email protected]'), '[email protected]'],
782+
[$this->makeUser('11da2744-3f4d-4c17-8c13-4c057a379237', 'James Loranger', '[email protected]'), ''],
783+
];
784+
}
785+
786+
/**
787+
* @dataProvider dataCheckEmailVerification
788+
*/
789+
public function testCheckEmailVerification(IUser $user, ?string $newEmail): void {
790+
$account = $this->accountManager->getAccount($user);
791+
$emailUpdated = false;
792+
793+
if (!empty($newEmail)) {
794+
$account->getProperty(IAccountManager::PROPERTY_EMAIL)->setValue($newEmail);
795+
$emailUpdated = true;
796+
}
797+
798+
if ($emailUpdated) {
799+
$this->jobList->expects($this->once())
800+
->method('add')
801+
->with(VerifyUserData::class);
802+
} else {
803+
$this->jobList->expects($this->never())
804+
->method('add')
805+
->with(VerifyUserData::class);
806+
}
807+
808+
/** @var array $oldData */
809+
$oldData = $this->invokePrivate($this->accountManager, 'getUser', [$user, false]);
810+
$this->invokePrivate($this->accountManager, 'checkEmailVerification', [$account, $oldData]);
811+
}
773812
}

0 commit comments

Comments
 (0)