diff --git a/apps/provisioning_api/lib/Users.php b/apps/provisioning_api/lib/Users.php index 1be707f056b2..72b67cdc63e2 100644 --- a/apps/provisioning_api/lib/Users.php +++ b/apps/provisioning_api/lib/Users.php @@ -310,8 +310,9 @@ public function editUser($parameters) { } break; case 'email': - if (\filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { - $targetUser->setEMailAddress($parameters['_put']['value']); + $emailAddress = $parameters['_put']['value']; + if (($emailAddress === '') || \filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { + $targetUser->setEMailAddress($emailAddress); } else { return new Result(null, 102); } diff --git a/apps/provisioning_api/tests/UsersTest.php b/apps/provisioning_api/tests/UsersTest.php index b7144dd468dd..d811cc86cdff 100644 --- a/apps/provisioning_api/tests/UsersTest.php +++ b/apps/provisioning_api/tests/UsersTest.php @@ -989,6 +989,31 @@ public function testEditUserRegularUserSelfEditChangeEmailValid() { $this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit', '_put' => ['key' => 'email', 'value' => 'demo@owncloud.org']])); } + public function testEditUserRegularUserSelfEditClearEmail() { + $loggedInUser = $this->createMock(IUser::class); + $loggedInUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UserToEdit')); + $targetUser = $this->createMock(IUser::class); + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($loggedInUser)); + $this->userManager + ->expects($this->once()) + ->method('get') + ->with('UserToEdit') + ->will($this->returnValue($targetUser)); + $targetUser + ->expects($this->once()) + ->method('setEMailAddress') + ->with(''); + + $expected = new Result(null, 100); + $this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit', '_put' => ['key' => 'email', 'value' => '']])); + } + public function testEditUserRegularUserSelfEditChangeEmailInvalid() { $loggedInUser = $this->createMock(IUser::class); $loggedInUser diff --git a/changelog/unreleased/37424-2 b/changelog/unreleased/37424-2 new file mode 100644 index 000000000000..07a950abe7de --- /dev/null +++ b/changelog/unreleased/37424-2 @@ -0,0 +1,8 @@ +Bugfix: Allow clearing a user email address with the Provisioning API + +Specifying the empty string as the email address is now valid when editing a +user with the Provisioning API. This allows the email address of a user to be +cleared. + +https://github.com/owncloud/core/issues/37424 +https://github.com/owncloud/core/pull/37427 diff --git a/tests/acceptance/features/apiProvisioning-v1/editUser.feature b/tests/acceptance/features/apiProvisioning-v1/editUser.feature index 1bb13ab403f6..02ebca5d108b 100644 --- a/tests/acceptance/features/apiProvisioning-v1/editUser.feature +++ b/tests/acceptance/features/apiProvisioning-v1/editUser.feature @@ -62,6 +62,16 @@ Feature: edit users And the HTTP status code should be "200" And the email address of user "brand-new-user" should be "brand-new-user@example.com" + Scenario: the administrator can clear an existing user email + Given user "brand-new-user" has been created with default attributes and skeleton files + And the administrator has changed the email of user "brand-new-user" to "brand-new-user@gmail.com" + And the OCS status code should be "100" + And the HTTP status code should be "200" + When the administrator changes the email of user "brand-new-user" to "" using the provisioning API + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And the email address of user "brand-new-user" should be "" + @smokeTest Scenario: a subadmin should be able to edit the user information in their group Given these users have been created with default attributes and skeleton files: diff --git a/tests/acceptance/features/apiProvisioning-v2/editUser.feature b/tests/acceptance/features/apiProvisioning-v2/editUser.feature index 5a6697cecdd5..f4eb9891c910 100644 --- a/tests/acceptance/features/apiProvisioning-v2/editUser.feature +++ b/tests/acceptance/features/apiProvisioning-v2/editUser.feature @@ -62,6 +62,16 @@ Feature: edit users And the HTTP status code should be "200" And the email address of user "brand-new-user" should be "brand-new-user@example.com" + Scenario: the administrator can clear an existing user email + Given user "brand-new-user" has been created with default attributes and skeleton files + And the administrator has changed the email of user "brand-new-user" to "brand-new-user@gmail.com" + And the OCS status code should be "200" + And the HTTP status code should be "200" + When the administrator changes the email of user "brand-new-user" to "" using the provisioning API + Then the OCS status code should be "200" + And the HTTP status code should be "200" + And the email address of user "brand-new-user" should be "" + @smokeTest Scenario: a subadmin should be able to edit the user information in their group Given these users have been created with default attributes and skeleton files: