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

[stable30] fix: provision api's status codes #48474

Merged
merged 1 commit into from
Oct 30, 2024
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
40 changes: 20 additions & 20 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function addUser(
$group = $this->groupManager->get($groupid);
// Check if group exists
if ($group === null) {
throw new OCSException($this->l10n->t('Sub-admin group does not exist'), 102);
throw new OCSException($this->l10n->t('Sub-admin group does not exist'), 109);
}
// Check if trying to make subadmin of admin group
if ($group->getGID() === 'admin') {
Expand All @@ -508,7 +508,7 @@ public function addUser(
}
if ($password === '') {
if ($email === '') {
throw new OCSException($this->l10n->t('To send a password link to the user an email address is required.'), 108);
throw new OCSException($this->l10n->t('An email address is required, to send a password link to the user.'), 108);
}

$passwordEvent = new GenerateSecurePasswordEvent();
Expand Down Expand Up @@ -1007,7 +1007,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 All @@ -1028,14 +1028,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
$quota = \OCP\Util::computerFileSize($quota);
}
if ($quota === false) {
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 102);
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 101);
}
if ($quota === -1) {
$quota = 'none';
} else {
$maxQuota = (int) $this->config->getAppValue('files', 'max_quota', '-1');
if ($maxQuota !== -1 && $quota > $maxQuota) {
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 102);
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 101);
}
$quota = \OCP\Util::humanFileSize($quota);
}
Expand All @@ -1044,7 +1044,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
if ($quota === 'none') {
$allowUnlimitedQuota = $this->config->getAppValue('files', 'allow_unlimited_quota', '1') === '1';
if (!$allowUnlimitedQuota) {
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 102);
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 101);
}
}
$targetUser->setQuota($quota);
Expand All @@ -1055,33 +1055,33 @@ public function editUser(string $userId, string $key, string $value): DataRespon
case self::USER_FIELD_PASSWORD:
try {
if (strlen($value) > IUserManager::MAX_PASSWORD_LENGTH) {
throw new OCSException($this->l10n->t('Invalid password value'), 102);
throw new OCSException($this->l10n->t('Invalid password value'), 101);
}
if (!$targetUser->canChangePassword()) {
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 103);
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 112);
}
$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:
$languagesCodes = $this->l10nFactory->findAvailableLanguages();
if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
throw new OCSException($this->l10n->t('Invalid language'), 102);
throw new OCSException($this->l10n->t('Invalid language'), 101);
}
$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
break;
case self::USER_FIELD_LOCALE:
if (!$this->l10nFactory->localeExists($value)) {
throw new OCSException($this->l10n->t('Invalid locale'), 102);
throw new OCSException($this->l10n->t('Invalid locale'), 101);
}
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
break;
case self::USER_FIELD_FIRST_DAY_OF_WEEK:
$intValue = (int)$value;
if ($intValue < -1 || $intValue > 6) {
throw new OCSException($this->l10n->t('Invalid first day of week'), 102);
throw new OCSException($this->l10n->t('Invalid first day of week'), 101);
}
if ($intValue === -1) {
$this->config->deleteUserValue($targetUser->getUID(), 'core', AUserData::USER_FIELD_FIRST_DAY_OF_WEEK);
Expand All @@ -1106,14 +1106,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 @@ -1122,13 +1122,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 @@ -1151,7 +1151,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 @@ -1160,7 +1160,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 @@ -1197,12 +1197,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
10 changes: 5 additions & 5 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,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 @@ -1676,13 +1676,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 @@ -1914,7 +1914,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 Expand Up @@ -2001,7 +2001,7 @@ public function testEditUserAdminUserSelfEditChangeValidQuota() {
public function testEditUserAdminUserSelfEditChangeInvalidQuota() {
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
$this->expectExceptionMessage('Invalid quota value: ABC');
$this->expectExceptionCode(102);
$this->expectExceptionCode(101);

$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
$loggedInUser
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 @@ -211,7 +211,7 @@ Feature: provisioning
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | additional_mail |
| value | [email protected] |
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 @@ -222,7 +222,7 @@ Feature: provisioning
And sending "PUT" to "/cloud/users/brand-new-user" with
| key | additional_mail |
| value | [email protected] |
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 @@ -267,17 +267,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 @@ -323,7 +323,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
Loading