Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix email verification
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal authored and backportbot[bot] committed Jan 7, 2022
commit bbb78f848b07da606b6284334b2252bea3fbcade
5 changes: 4 additions & 1 deletion lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ protected function checkEmailVerification(IAccount $updatedAccount, array $oldDa
} catch (PropertyDoesNotExistException $e) {
return;
}
$oldMail = isset($oldData[self::PROPERTY_EMAIL]) ? $oldData[self::PROPERTY_EMAIL]['value']['value'] : '';

$oldMailIndex = array_search(self::PROPERTY_EMAIL, array_column($oldData, 'name'), true);
$oldMail = $oldMailIndex !== false ? $oldData[$oldMailIndex]['value'] : '';

if ($oldMail !== $property->getValue()) {
$this->jobList->add(VerifyUserData::class,
[
Expand Down
39 changes: 39 additions & 0 deletions tests/lib/Accounts/AccountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use OC\Accounts\Account;
use OC\Accounts\AccountManager;
use OCA\Settings\BackgroundJobs\VerifyUserData;
use OCP\Accounts\IAccountManager;
use OCP\BackgroundJob\IJobList;
use OCP\Defaults;
Expand Down Expand Up @@ -586,4 +587,42 @@ public function searchDataProvider(): array {
],
];
}

public function dataCheckEmailVerification(): array {
return [
[$this->makeUser('steve', 'Steve Smith', '[email protected]'), null],
[$this->makeUser('emma', 'Emma Morales', '[email protected]'), '[email protected]'],
[$this->makeUser('[email protected]', 'Sarah Foster', '[email protected]'), null],
[$this->makeUser('[email protected]', 'Cole Harrison', '[email protected]'), '[email protected]'],
[$this->makeUser('8d29e358-cf69-4849-bbf9-28076c0b908b', 'Alice McPherson', '[email protected]'), '[email protected]'],
[$this->makeUser('11da2744-3f4d-4c17-8c13-4c057a379237', 'James Loranger', '[email protected]'), ''],
];
}

/**
* @dataProvider dataCheckEmailVerification
*/
public function testCheckEmailVerification(IUser $user, ?string $newEmail): void {
$account = $this->accountManager->getAccount($user);
$emailUpdated = false;

if (!empty($newEmail)) {
$account->getProperty(IAccountManager::PROPERTY_EMAIL)->setValue($newEmail);
$emailUpdated = true;
}

if ($emailUpdated) {
$this->jobList->expects($this->once())
->method('add')
->with(VerifyUserData::class);
} else {
$this->jobList->expects($this->never())
->method('add')
->with(VerifyUserData::class);
}

/** @var array $oldData */
$oldData = $this->invokePrivate($this->accountManager, 'getUser', [$user, false]);
$this->invokePrivate($this->accountManager, 'checkEmailVerification', [$account, $oldData]);
}
}