Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the email address to be cleared via the Provisioning API #37427

Merged
merged 1 commit into from
May 22, 2020
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
5 changes: 3 additions & 2 deletions apps/provisioning_api/lib/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
25 changes: 25 additions & 0 deletions apps/provisioning_api/tests/UsersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,31 @@ public function testEditUserRegularUserSelfEditChangeEmailValid() {
$this->assertEquals($expected, $this->api->editUser(['userid' => 'UserToEdit', '_put' => ['key' => 'email', 'value' => '[email protected]']]));
}

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
Expand Down
8 changes: 8 additions & 0 deletions changelog/unreleased/37424-2
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/acceptance/features/apiProvisioning-v1/editUser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"

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 "[email protected]"
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:
Expand Down
10 changes: 10 additions & 0 deletions tests/acceptance/features/apiProvisioning-v2/editUser.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"

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 "[email protected]"
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:
Expand Down