From 093ce9301636de6ad9d0a30e8e8b44980eebcd76 Mon Sep 17 00:00:00 2001 From: lazerg Date: Sat, 31 Oct 2026 13:14:19 +0500 Subject: [PATCH] fix(provisioning_api): auto-verify additional mail set by admin Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: lazerg --- .../lib/Controller/UsersController.php | 2 +- .../tests/Controller/UsersControllerTest.php | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index ff507ceac3a8c..4fe69ece96856 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -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); diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 89884448c3577..850055a121ef4 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -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);