Skip to content

Commit

Permalink
fix: provision api's status codes
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Oct 2, 2024
1 parent afe1cdf commit a783bee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
}
// Check if permitted to edit this field
if (!in_array($key, $permittedFields)) {
throw new OCSException('', 103);
throw new OCSException('', 113);
}
// Process the edit
switch ($key) {
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
}
$targetUser->setPassword($value);
} catch (HintException $e) { // password policy error
throw new OCSException($e->getMessage(), 103);
throw new OCSException($e->getMessage(), 107);
}
break;
case self::USER_FIELD_LANGUAGE:
Expand Down Expand Up @@ -1069,14 +1069,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
}
}
if (!$success) {
throw new OCSException('', 102);
throw new OCSException('', 101);
}
break;
case IAccountManager::PROPERTY_EMAIL:
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
$targetUser->setEMailAddress($value);
} else {
throw new OCSException('', 102);
throw new OCSException('', 101);
}
break;
case IAccountManager::COLLECTION_EMAIL:
Expand All @@ -1085,13 +1085,13 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);

if ($mailCollection->getPropertyByValue($value)) {
throw new OCSException('', 102);
throw new OCSException('', 101);
}

$mailCollection->addPropertyWithDefaults($value);
$this->accountManager->updateAccount($userAccount);
} else {
throw new OCSException('', 102);
throw new OCSException('', 101);
}
break;
case IAccountManager::PROPERTY_PHONE:
Expand All @@ -1113,7 +1113,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$this->knownUserService->deleteByContactUserId($targetUser->getUID());
}
} catch (InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);
throw new OCSException('Invalid ' . $e->getMessage(), 101);
}
}
} catch (PropertyDoesNotExistException $e) {
Expand All @@ -1122,7 +1122,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
try {
$this->accountManager->updateAccount($userAccount);
} catch (InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);
throw new OCSException('Invalid ' . $e->getMessage(), 101);
}
break;
case IAccountManager::PROPERTY_PROFILE_ENABLED:
Expand Down Expand Up @@ -1158,12 +1158,12 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$userProperty->setScope($value);
$this->accountManager->updateAccount($userAccount);
} catch (InvalidArgumentException $e) {
throw new OCSException('Invalid ' . $e->getMessage(), 102);
throw new OCSException('Invalid ' . $e->getMessage(), 101);
}
}
break;
default:
throw new OCSException('', 103);
throw new OCSException('', 113);
}
return new DataResponse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ public function testEditUserRegularUserSelfEditAddAdditionalEmailMainAddress():
->with($userAccount);

$this->expectException(OCSException::class);
$this->expectExceptionCode(102);
$this->expectExceptionCode(101);
$this->api->editUser('UserToEdit', 'additional_mail', '[email protected]')->getData();
}

Expand Down Expand Up @@ -1709,13 +1709,13 @@ public function testEditUserRegularUserSelfEditAddAdditionalEmailDuplicate(): vo
->with($userAccount);

$this->expectException(OCSException::class);
$this->expectExceptionCode(102);
$this->expectExceptionCode(101);
$this->api->editUser('UserToEdit', 'additional_mail', '[email protected]')->getData();
}

public function testEditUserRegularUserSelfEditChangeEmailInvalid() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(102);
$this->expectExceptionCode(101);

$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -1947,7 +1947,7 @@ public function testEditUserRegularUserSelfEditChangePassword() {

public function testEditUserRegularUserSelfEditChangeQuota() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionCode(103);
$this->expectExceptionCode(113);

$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
Expand Down
12 changes: 6 additions & 6 deletions build/integration/features/provisioning-v1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Feature: provisioning
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | additional_mail |
| value | no-reply@nextcloud.com |
And the OCS status code should be "102"
And the OCS status code should be "101"
And the HTTP status code should be "200"
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | additional_mail |
Expand All @@ -219,7 +219,7 @@ Feature: provisioning
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | additional_mail |
| value | no.reply2@nextcloud.com |
And the OCS status code should be "102"
And the OCS status code should be "101"
And the HTTP status code should be "200"
Then user "brand-new-user" has
| id | brand-new-user |
Expand Down Expand Up @@ -264,17 +264,17 @@ Feature: provisioning
When sending "PUT" to "/cloud/users/brand-new-user" with
| key | phoneScope |
| value | invalid |
Then the OCS status code should be "102"
Then the OCS status code should be "101"
And the HTTP status code should be "200"
When sending "PUT" to "/cloud/users/brand-new-user" with
| key | displaynameScope |
| value | v2-private |
Then the OCS status code should be "102"
Then the OCS status code should be "101"
And the HTTP status code should be "200"
When sending "PUT" to "/cloud/users/brand-new-user" with
| key | emailScope |
| value | v2-private |
Then the OCS status code should be "102"
Then the OCS status code should be "101"
And the HTTP status code should be "200"

Scenario: Edit a user account multi-value property scopes with invalid or unsupported value
Expand Down Expand Up @@ -320,7 +320,7 @@ Feature: provisioning
When sending "PUT" to "/cloud/users/brand-new-user" with
| key | phoneScope |
| value | v2-private |
Then the OCS status code should be "103"
Then the OCS status code should be "113"
And the HTTP status code should be "200"

Scenario: Search by phone number
Expand Down

0 comments on commit a783bee

Please sign in to comment.