Skip to content

Commit dee345f

Browse files
hamza221backportbot[bot]
authored andcommitted
fix: provision api's status codes
Signed-off-by: Hamza Mahjoubi <[email protected]> [skip ci]
1 parent 2bc1165 commit dee345f

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
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();
@@ -1007,7 +1007,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10071007
}
10081008
// Check if permitted to edit this field
10091009
if (!in_array($key, $permittedFields)) {
1010-
throw new OCSException('', 103);
1010+
throw new OCSException('', 113);
10111011
}
10121012
// Process the edit
10131013
switch ($key) {
@@ -1028,14 +1028,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10281028
$quota = \OCP\Util::computerFileSize($quota);
10291029
}
10301030
if ($quota === false) {
1031-
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 102);
1031+
throw new OCSException($this->l10n->t('Invalid quota value: %1$s', [$value]), 101);
10321032
}
10331033
if ($quota === -1) {
10341034
$quota = 'none';
10351035
} else {
10361036
$maxQuota = (int) $this->config->getAppValue('files', 'max_quota', '-1');
10371037
if ($maxQuota !== -1 && $quota > $maxQuota) {
1038-
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 102);
1038+
throw new OCSException($this->l10n->t('Invalid quota value. %1$s is exceeding the maximum quota', [$value]), 101);
10391039
}
10401040
$quota = \OCP\Util::humanFileSize($quota);
10411041
}
@@ -1044,7 +1044,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10441044
if ($quota === 'none') {
10451045
$allowUnlimitedQuota = $this->config->getAppValue('files', 'allow_unlimited_quota', '1') === '1';
10461046
if (!$allowUnlimitedQuota) {
1047-
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 102);
1047+
throw new OCSException($this->l10n->t('Unlimited quota is forbidden on this instance'), 101);
10481048
}
10491049
}
10501050
$targetUser->setQuota($quota);
@@ -1055,33 +1055,33 @@ public function editUser(string $userId, string $key, string $value): DataRespon
10551055
case self::USER_FIELD_PASSWORD:
10561056
try {
10571057
if (strlen($value) > IUserManager::MAX_PASSWORD_LENGTH) {
1058-
throw new OCSException($this->l10n->t('Invalid password value'), 102);
1058+
throw new OCSException($this->l10n->t('Invalid password value'), 101);
10591059
}
10601060
if (!$targetUser->canChangePassword()) {
1061-
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 103);
1061+
throw new OCSException($this->l10n->t('Setting the password is not supported by the users backend'), 112);
10621062
}
10631063
$targetUser->setPassword($value);
10641064
} catch (HintException $e) { // password policy error
1065-
throw new OCSException($e->getMessage(), 103);
1065+
throw new OCSException($e->getMessage(), 107);
10661066
}
10671067
break;
10681068
case self::USER_FIELD_LANGUAGE:
10691069
$languagesCodes = $this->l10nFactory->findAvailableLanguages();
10701070
if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
1071-
throw new OCSException($this->l10n->t('Invalid language'), 102);
1071+
throw new OCSException($this->l10n->t('Invalid language'), 101);
10721072
}
10731073
$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
10741074
break;
10751075
case self::USER_FIELD_LOCALE:
10761076
if (!$this->l10nFactory->localeExists($value)) {
1077-
throw new OCSException($this->l10n->t('Invalid locale'), 102);
1077+
throw new OCSException($this->l10n->t('Invalid locale'), 101);
10781078
}
10791079
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
10801080
break;
10811081
case self::USER_FIELD_FIRST_DAY_OF_WEEK:
10821082
$intValue = (int)$value;
10831083
if ($intValue < -1 || $intValue > 6) {
1084-
throw new OCSException($this->l10n->t('Invalid first day of week'), 102);
1084+
throw new OCSException($this->l10n->t('Invalid first day of week'), 101);
10851085
}
10861086
if ($intValue === -1) {
10871087
$this->config->deleteUserValue($targetUser->getUID(), 'core', AUserData::USER_FIELD_FIRST_DAY_OF_WEEK);
@@ -1106,14 +1106,14 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11061106
}
11071107
}
11081108
if (!$success) {
1109-
throw new OCSException('', 102);
1109+
throw new OCSException('', 101);
11101110
}
11111111
break;
11121112
case IAccountManager::PROPERTY_EMAIL:
11131113
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
11141114
$targetUser->setEMailAddress($value);
11151115
} else {
1116-
throw new OCSException('', 102);
1116+
throw new OCSException('', 101);
11171117
}
11181118
break;
11191119
case IAccountManager::COLLECTION_EMAIL:
@@ -1122,13 +1122,13 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11221122
$mailCollection = $userAccount->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
11231123

11241124
if ($mailCollection->getPropertyByValue($value)) {
1125-
throw new OCSException('', 102);
1125+
throw new OCSException('', 101);
11261126
}
11271127

11281128
$mailCollection->addPropertyWithDefaults($value);
11291129
$this->accountManager->updateAccount($userAccount);
11301130
} else {
1131-
throw new OCSException('', 102);
1131+
throw new OCSException('', 101);
11321132
}
11331133
break;
11341134
case IAccountManager::PROPERTY_PHONE:
@@ -1151,7 +1151,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11511151
$this->knownUserService->deleteByContactUserId($targetUser->getUID());
11521152
}
11531153
} catch (InvalidArgumentException $e) {
1154-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1154+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
11551155
}
11561156
}
11571157
} catch (PropertyDoesNotExistException $e) {
@@ -1160,7 +1160,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11601160
try {
11611161
$this->accountManager->updateAccount($userAccount);
11621162
} catch (InvalidArgumentException $e) {
1163-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1163+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
11641164
}
11651165
break;
11661166
case IAccountManager::PROPERTY_PROFILE_ENABLED:
@@ -1197,12 +1197,12 @@ public function editUser(string $userId, string $key, string $value): DataRespon
11971197
$userProperty->setScope($value);
11981198
$this->accountManager->updateAccount($userAccount);
11991199
} catch (InvalidArgumentException $e) {
1200-
throw new OCSException('Invalid ' . $e->getMessage(), 102);
1200+
throw new OCSException('Invalid ' . $e->getMessage(), 101);
12011201
}
12021202
}
12031203
break;
12041204
default:
1205-
throw new OCSException('', 103);
1205+
throw new OCSException('', 113);
12061206
}
12071207
return new DataResponse();
12081208
}

apps/provisioning_api/tests/Controller/UsersControllerTest.php

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

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

@@ -1676,13 +1676,13 @@ public function testEditUserRegularUserSelfEditAddAdditionalEmailDuplicate(): vo
16761676
->with($userAccount);
16771677

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

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

16871687
$loggedInUser = $this->getMockBuilder(IUser::class)
16881688
->disableOriginalConstructor()
@@ -1914,7 +1914,7 @@ public function testEditUserRegularUserSelfEditChangePassword() {
19141914

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

19191919
$loggedInUser = $this->getMockBuilder(IUser::class)
19201920
->disableOriginalConstructor()
@@ -2001,7 +2001,7 @@ public function testEditUserAdminUserSelfEditChangeValidQuota() {
20012001
public function testEditUserAdminUserSelfEditChangeInvalidQuota() {
20022002
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
20032003
$this->expectExceptionMessage('Invalid quota value: ABC');
2004-
$this->expectExceptionCode(102);
2004+
$this->expectExceptionCode(101);
20052005

20062006
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
20072007
$loggedInUser

0 commit comments

Comments
 (0)