Skip to content

Commit 9be2f06

Browse files
committed
fix: provision api's status codes
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
1 parent 6e8c532 commit 9be2f06

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ public function addUser(
488488
$group = $this->groupManager->get($groupid);
489489
// Check if group exists
490490
if ($group === null) {
491-
throw new OCSException($this->l10n->t('Sub-admin group does not exist'), 102);
491+
throw new OCSException($this->l10n->t('Sub-admin group does not exist'), 109);
492492
}
493493
// Check if trying to make subadmin of admin group
494494
if ($group->getGID() === 'admin') {
@@ -508,7 +508,7 @@ public function addUser(
508508
}
509509
if ($password === '') {
510510
if ($email === '') {
511-
throw new OCSException($this->l10n->t('To send a password link to the user an email address is required.'), 108);
511+
throw new OCSException($this->l10n->t('An email address is required, to send a password link to the user.'), 108);
512512
}
513513

514514
$passwordEvent = new GenerateSecurePasswordEvent();
@@ -1011,7 +1011,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10111011
}
10121012
// Check if permitted to edit this field
10131013
if (!in_array($key, $permittedFields)) {
1014-
throw new OCSException('', 103);
1014+
throw new OCSException('', 113);
10151015
}
10161016
// Process the edit
10171017
switch ($key) {
@@ -1032,14 +1032,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10321032
$quota = \OCP\Util::computerFileSize($quota);
10331033
}
10341034
if ($quota === false) {
1035-
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 102);
1035+
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 101);
10361036
}
10371037
if ($quota === -1) {
10381038
$quota = 'none';
10391039
} else {
10401040
$maxQuota = (int)$this->config->getAppValue('files', 'max_quota', '-1');
10411041
if ($maxQuota !== -1 && $quota > $maxQuota) {
1042-
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 102);
1042+
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 101);
10431043
}
10441044
$quota = \OCP\Util::humanFileSize($quota);
10451045
}
@@ -1048,7 +1048,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10481048
if ($quota === 'none') {
10491049
$allowUnlimitedQuota = $this->config->getAppValue('files', 'allow_unlimited_quota', '1') === '1';
10501050
if (!$allowUnlimitedQuota) {
1051-
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 102);
1051+
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 101);
10521052
}
10531053
}
10541054
$targetUser->setQuota($quota);
@@ -1059,33 +1059,33 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10591059
case self::USER_FIELD_PASSWORD:
10601060
try {
10611061
if (strlen($value) > IUserManager::MAX_PASSWORD_LENGTH) {
1062-
throw new OCSException($this->l10n->t('Invalid password value'), 102);
1062+
throw new OCSException($this->l10n->t('Invalid password value'), 101);
10631063
}
10641064
if (!$targetUser->canChangePassword()) {
1065-
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 103);
1065+
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 112);
10661066
}
10671067
$targetUser->setPassword($value);
10681068
} catch (HintException $e) { // password policy error
1069-
throw new OCSException($e->getMessage(), 103);
1069+
throw new OCSException($e->getMessage(), 107);
10701070
}
10711071
break;
10721072
case self::USER_FIELD_LANGUAGE:
10731073
$languagesCodes = $this->l10nFactory->findAvailableLanguages();
10741074
if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
1075-
throw new OCSException($this->l10n->t('Invalid language'), 102);
1075+
throw new OCSException($this->l10n->t('Invalid language'), 101);
10761076
}
10771077
$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
10781078
break;
10791079
case self::USER_FIELD_LOCALE:
10801080
if (!$this->l10nFactory->localeExists($value)) {
1081-
throw new OCSException($this->l10n->t('Invalid locale'), 102);
1081+
throw new OCSException($this->l10n->t('Invalid locale'), 101);
10821082
}
10831083
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
10841084
break;
10851085
case self::USER_FIELD_FIRST_DAY_OF_WEEK:
10861086
$intValue = (int)$value;
10871087
if ($intValue < -1 || $intValue > 6) {
1088-
throw new OCSException($this->l10n->t('Invalid first day of week'), 102);
1088+
throw new OCSException($this->l10n->t('Invalid first day of week'), 101);
10891089
}
10901090
if ($intValue === -1) {
10911091
$this->config->deleteUserValue($targetUser->getUID(), 'core', AUserData::USER_FIELD_FIRST_DAY_OF_WEEK);
@@ -1110,14 +1110,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11101110
}
11111111
}
11121112
if (!$success) {
1113-
throw new OCSException('', 102);
1113+
throw new OCSException('', 101);
11141114
}
11151115
break;
11161116
case IAccountManager::PROPERTY_EMAIL:
11171117
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
11181118
$targetUser->setEMailAddress($value);
11191119
} else {
1120-
throw new OCSException('', 102);
1120+
throw new OCSException('', 101);
11211121
}
11221122
break;
11231123
case IAccountManager::COLLECTION_EMAIL:
@@ -1126,13 +1126,13 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11261126
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
11271127

11281128
if ($mailCollection->getPropertyByValue($value)) {
1129-
throw new OCSException('', 102);
1129+
throw new OCSException('', 101);
11301130
}
11311131

11321132
$mailCollection->addPropertyWithDefaults($value);
11331133
$this->accountManager->updateAccount($userAccount);
11341134
} else {
1135-
throw new OCSException('', 102);
1135+
throw new OCSException('', 101);
11361136
}
11371137
break;
11381138
case IAccountManager::PROPERTY_PHONE:
@@ -1156,7 +1156,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11561156
$this->knownUserService->deleteByContactUserId($targetUser->getUID());
11571157
}
11581158
} catch (InvalidArgumentException $e) {
1159-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1159+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
11601160
}
11611161
}
11621162
} catch (PropertyDoesNotExistException $e) {
@@ -1165,7 +1165,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11651165
try {
11661166
$this->accountManager->updateAccount($userAccount);
11671167
} catch (InvalidArgumentException $e) {
1168-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1168+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
11691169
}
11701170
break;
11711171
case IAccountManager::PROPERTY_PROFILE_ENABLED:
@@ -1203,12 +1203,12 @@ public function editUser(string $userId, string $key, string $value): DataRespon
12031203
$userProperty->setScope($value);
12041204
$this->accountManager->updateAccount($userAccount);
12051205
} catch (InvalidArgumentException $e) {
1206-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1206+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
12071207
}
12081208
}
12091209
break;
12101210
default:
1211-
throw new OCSException('', 103);
1211+
throw new OCSException('', 113);
12121212
}
12131213
return new DataResponse();
12141214
}

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,7 +1623,7 @@ public function testEditUserRegularUserSelfEditAddAdditionalEmailMainAddress():
16231623
->with($userAccount);
16241624

16251625
$this->expectException(OCSException::class);
1626-
$this->expectExceptionCode(102);
1626+
$this->expectExceptionCode(101);
16271627
$this->api->editUser('UserToEdit', 'additional_mail', 'demo@nextcloud.com')->getData();
16281628
}
16291629

@@ -1682,13 +1682,13 @@ public function testEditUserRegularUserSelfEditAddAdditionalEmailDuplicate(): vo
16821682
->with($userAccount);
16831683

16841684
$this->expectException(OCSException::class);
1685-
$this->expectExceptionCode(102);
1685+
$this->expectExceptionCode(101);
16861686
$this->api->editUser('UserToEdit', 'additional_mail', 'demo1@nextcloud.com')->getData();
16871687
}
16881688

16891689
public function testEditUserRegularUserSelfEditChangeEmailInvalid(): void {
16901690
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
1691-
$this->expectExceptionCode(102);
1691+
$this->expectExceptionCode(101);
16921692

16931693
$loggedInUser = $this->getMockBuilder(IUser::class)
16941694
->disableOriginalConstructor()
@@ -1922,7 +1922,7 @@ public function testEditUserRegularUserSelfEditChangePassword(): void {
19221922

19231923
public function testEditUserRegularUserSelfEditChangeQuota(): void {
19241924
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
1925-
$this->expectExceptionCode(103);
1925+
$this->expectExceptionCode(113);
19261926

19271927
$loggedInUser = $this->getMockBuilder(IUser::class)
19281928
->disableOriginalConstructor()
@@ -2009,7 +2009,7 @@ public function testEditUserAdminUserSelfEditChangeValidQuota(): void {
20092009
public function testEditUserAdminUserSelfEditChangeInvalidQuota(): void {
20102010
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
20112011
$this->expectExceptionMessage('Invalid quota value: ABC');
2012-
$this->expectExceptionCode(102);
2012+
$this->expectExceptionCode(101);
20132013

20142014
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
20152015
$loggedInUser

build/integration/features/provisioning-v1.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Feature: provisioning
214214
And sending "PUT" to "/cloud/users/brand-new-user" with
215215
| key | additional_mail |
216216
| value | no-reply@nextcloud.com |
217-
And the OCS status code should be "102"
217+
And the OCS status code should be "101"
218218
And the HTTP status code should be "200"
219219
And sending "PUT" to "/cloud/users/brand-new-user" with
220220
| key | additional_mail |
@@ -225,7 +225,7 @@ Feature: provisioning
225225
And sending "PUT" to "/cloud/users/brand-new-user" with
226226
| key | additional_mail |
227227
| value | no.reply2@nextcloud.com |
228-
And the OCS status code should be "102"
228+
And the OCS status code should be "101"
229229
And the HTTP status code should be "200"
230230
Then user "brand-new-user" has
231231
| id | brand-new-user |
@@ -270,17 +270,17 @@ Feature: provisioning
270270
When sending "PUT" to "/cloud/users/brand-new-user" with
271271
| key | phoneScope |
272272
| value | invalid |
273-
Then the OCS status code should be "102"
273+
Then the OCS status code should be "101"
274274
And the HTTP status code should be "200"
275275
When sending "PUT" to "/cloud/users/brand-new-user" with
276276
| key | displaynameScope |
277277
| value | v2-private |
278-
Then the OCS status code should be "102"
278+
Then the OCS status code should be "101"
279279
And the HTTP status code should be "200"
280280
When sending "PUT" to "/cloud/users/brand-new-user" with
281281
| key | emailScope |
282282
| value | v2-private |
283-
Then the OCS status code should be "102"
283+
Then the OCS status code should be "101"
284284
And the HTTP status code should be "200"
285285

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

332332
Scenario: Search by phone number

0 commit comments

Comments
 (0)