Skip to content
Open
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
2 changes: 1 addition & 1 deletion apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public function editUserMultiValue(
if ($value !== '') {
$value = mb_strtolower(trim($value));
$mailCollection->addPropertyWithDefaults($value);
$property = $mailCollection->getPropertyByValue($key);
$property = $mailCollection->getPropertyByValue($value);
if ($isAdminOrSubadmin && $property) {
// admin set mails are auto-verified
$property->setLocallyVerified(IAccountManager::VERIFIED);
Expand Down
62 changes: 62 additions & 0 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,68 @@ public function testEditUserAdminEditChangeLanguage(): void {
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
}

public function testEditUserMultiValueAdminAddAdditionalEmailIsVerified(): void {
$loggedInUser = $this->createMock(IUser::class);
$loggedInUser
->expects($this->any())
->method('getUID')
->willReturn('admin');
$targetUser = $this->createMock(IUser::class);
$targetUser
->expects($this->any())
->method('getUID')
->willReturn('UserToEdit');
$this->userSession
->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);
$this->userManager
->expects($this->once())
->method('get')
->with('UserToEdit')
->willReturn($targetUser);
$this->groupManager
->expects($this->any())
->method('isAdmin')
->with('admin')
->willReturn(true);
$subAdminManager = $this->createMock(SubAdmin::class);
$this->groupManager
->expects($this->once())
->method('getSubAdmin')
->willReturn($subAdminManager);

$property = $this->createMock(IAccountProperty::class);
$property->expects($this->once())
->method('setLocallyVerified')
->with(IAccountManager::VERIFIED);
$collection = $this->createMock(IAccountPropertyCollection::class);
$collection->expects($this->once())
->method('addPropertyWithDefaults')
->with('demo@nextcloud.com');
$collection->method('getPropertyByValue')
->willReturnMap([
['demo@nextcloud.com', $property],
]);

$userAccount = $this->createMock(IAccount::class);
$userAccount->method('getPropertyCollection')
->with(IAccountManager::COLLECTION_EMAIL)
->willReturn($collection);

$this->accountManager
->expects($this->once())
->method('getAccount')
->with($targetUser)
->willReturn($userAccount);
$this->accountManager
->expects($this->once())
->method('updateAccount')
->with($userAccount);

$this->assertEquals([], $this->api->editUserMultiValue('UserToEdit', 'additional_mail', '', 'demo@nextcloud.com')->getData());
}

#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserAdminEditChangeLanguageInvalidLanguage(): void {
$this->expectException(OCSException::class);
Expand Down