Skip to content

Commit 7bc8b54

Browse files
committed
Improve handling of profile fields
Signed-off-by: Christopher Ng <[email protected]>
1 parent 636c241 commit 7bc8b54

File tree

13 files changed

+70
-36
lines changed

13 files changed

+70
-36
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ public function getEditableFieldsForUser(string $userId): DataResponse {
631631
* @NoAdminRequired
632632
* @NoSubAdminRequired
633633
* @PasswordConfirmationRequired
634+
* @UserRateThrottle(limit=5, period=60)
634635
*
635636
* @throws OCSException
636637
*/
@@ -723,6 +724,7 @@ public function editUserMultiValue(
723724
* @NoAdminRequired
724725
* @NoSubAdminRequired
725726
* @PasswordConfirmationRequired
727+
* @UserRateThrottle(limit=50, period=600)
726728
*
727729
* edit users
728730
*

apps/settings/src/components/PersonalInfo/EmailSection/Email.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ import { NcActions, NcActionButton } from '@nextcloud/vue'
9090
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
9191
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
9292
import Check from 'vue-material-design-icons/Check.vue'
93-
import { showError } from '@nextcloud/dialogs'
9493
import debounce from 'debounce'
9594
9695
import FederationControl from '../shared/FederationControl.vue'
97-
import logger from '../../../logger.js'
96+
import { handleError } from '../../../utils/handlers.js'
9897
9998
import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants.js'
10099
import {
@@ -358,8 +357,7 @@ export default {
358357
this.showCheckmarkIcon = true
359358
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
360359
} else {
361-
showError(errorMessage)
362-
logger.error(errorMessage, error)
360+
handleError(error, errorMessage)
363361
this.showErrorIcon = true
364362
setTimeout(() => { this.showErrorIcon = false }, 2000)
365363
}

apps/settings/src/components/PersonalInfo/EmailSection/EmailSection.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@
6363

6464
<script>
6565
import { loadState } from '@nextcloud/initial-state'
66-
import { showError } from '@nextcloud/dialogs'
6766
6867
import Email from './Email.vue'
6968
import HeaderBar from '../shared/HeaderBar.vue'
7069
7170
import { ACCOUNT_PROPERTY_READABLE_ENUM, DEFAULT_ADDITIONAL_EMAIL_SCOPE, NAME_READABLE_ENUM } from '../../../constants/AccountPropertyConstants.js'
7271
import { savePrimaryEmail, savePrimaryEmailScope, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService.js'
7372
import { validateEmail } from '../../../utils/validate.js'
74-
import logger from '../../../logger.js'
73+
import { handleError } from '../../../utils/handlers.js'
7574
7675
const { emailMap: { additionalEmails, primaryEmail, notificationEmail } } = loadState('settings', 'personalInfoParameters', {})
7776
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
@@ -186,8 +185,7 @@ export default {
186185
187186
handleResponse(status, errorMessage, error) {
188187
if (status !== 'ok') {
189-
showError(errorMessage)
190-
logger.error(errorMessage, error)
188+
handleError(error, errorMessage)
191189
}
192190
},
193191

apps/settings/src/components/PersonalInfo/LanguageSection/Language.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@
5151
</template>
5252

5353
<script>
54-
import { showError } from '@nextcloud/dialogs'
55-
5654
import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
5755
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
5856
import { validateLanguage } from '../../../utils/validate.js'
59-
import logger from '../../../logger.js'
57+
import { handleError } from '../../../utils/handlers.js'
6058
6159
export default {
6260
name: 'Language',
@@ -133,8 +131,7 @@ export default {
133131
// Ensure that local state reflects server state
134132
this.initialLanguage = language
135133
} else {
136-
showError(errorMessage)
137-
logger.error(errorMessage, error)
134+
handleError(error, errorMessage)
138135
}
139136
},
140137

apps/settings/src/components/PersonalInfo/LocaleSection/Locale.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@
5858
</template>
5959

6060
<script>
61-
import { showError } from '@nextcloud/dialogs'
6261
import moment from '@nextcloud/moment'
6362
import Web from 'vue-material-design-icons/Web.vue'
6463
6564
import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
6665
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
6766
import { validateLocale } from '../../../utils/validate.js'
68-
import logger from '../../../logger.js'
67+
import { handleError } from '../../../utils/handlers.js'
6968
7069
export default {
7170
name: 'Locale',
@@ -155,8 +154,7 @@ export default {
155154
this.initialLocale = locale
156155
} else {
157156
this.$emit('update:locale', this.initialLocale)
158-
showError(errorMessage)
159-
logger.error(errorMessage, error)
157+
handleError(error, errorMessage)
160158
}
161159
},
162160

apps/settings/src/components/PersonalInfo/ProfileSection/ProfileCheckbox.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
</template>
3333

3434
<script>
35-
import { showError } from '@nextcloud/dialogs'
3635
import { emit } from '@nextcloud/event-bus'
3736
3837
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
3938
import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
40-
import logger from '../../../logger.js'
4139
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
40+
import { handleError } from '../../../utils/handlers.js'
4241
4342
export default {
4443
name: 'ProfileCheckbox',
@@ -82,8 +81,7 @@ export default {
8281
if (status === 'ok') {
8382
emit('settings:profile-enabled:updated', isProfileEnabled)
8483
} else {
85-
showError(errorMessage)
86-
logger.error(errorMessage, error)
84+
handleError(error, errorMessage)
8785
}
8886
this.loading = false
8987
},

apps/settings/src/components/PersonalInfo/ProfileVisibilitySection/VisibilityDropdown.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@
3636
</template>
3737

3838
<script>
39-
import { showError } from '@nextcloud/dialogs'
4039
import { loadState } from '@nextcloud/initial-state'
4140
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
4241
4342
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
4443
4544
import { saveProfileParameterVisibility } from '../../../service/ProfileService.js'
4645
import { VISIBILITY_PROPERTY_ENUM } from '../../../constants/ProfileConstants.js'
47-
import logger from '../../../logger.js'
46+
import { handleError } from '../../../utils/handlers.js'
4847
4948
const { profileEnabled } = loadState('settings', 'personalInfoParameters', false)
5049
@@ -136,8 +135,7 @@ export default {
136135
// Ensure that local state reflects server state
137136
this.initialVisibility = visibility
138137
} else {
139-
showError(errorMessage)
140-
logger.error(errorMessage, error)
138+
handleError(error, errorMessage)
141139
}
142140
},
143141

apps/settings/src/components/PersonalInfo/shared/AccountPropertySection.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171

7272
<script>
7373
import debounce from 'debounce'
74-
import { showError } from '@nextcloud/dialogs'
7574
7675
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
7776
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
@@ -80,7 +79,7 @@ import Check from 'vue-material-design-icons/Check.vue'
8079
import HeaderBar from '../shared/HeaderBar.vue'
8180
8281
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
83-
import logger from '../../../logger.js'
82+
import { handleError } from '../../../utils/handlers.js'
8483
8584
export default {
8685
name: 'AccountPropertySection',
@@ -196,8 +195,7 @@ export default {
196195
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
197196
} else {
198197
this.$emit('update:value', this.initialValue)
199-
showError(errorMessage)
200-
logger.error(errorMessage, error)
198+
handleError(error, errorMessage)
201199
this.showErrorIcon = true
202200
setTimeout(() => { this.showErrorIcon = false }, 2000)
203201
}

apps/settings/src/components/PersonalInfo/shared/FederationControl.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
<script>
4343
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
4444
import { loadState } from '@nextcloud/initial-state'
45-
import { showError } from '@nextcloud/dialogs'
4645
4746
import FederationControlAction from './FederationControlAction.vue'
4847
@@ -56,7 +55,7 @@ import {
5655
UNPUBLISHED_READABLE_PROPERTIES,
5756
} from '../../../constants/AccountPropertyConstants.js'
5857
import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService.js'
59-
import logger from '../../../logger.js'
58+
import { handleError } from '../../../utils/handlers.js'
6059
6160
const {
6261
federationEnabled,
@@ -188,8 +187,7 @@ export default {
188187
this.initialScope = scope
189188
} else {
190189
this.$emit('update:scope', this.initialScope)
191-
showError(errorMessage)
192-
logger.error(errorMessage, error)
190+
handleError(error, errorMessage)
193191
}
194192
},
195193
},
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @copyright 2023 Christopher Ng <[email protected]>
3+
*
4+
* @author Christopher Ng <[email protected]>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import { showError } from '@nextcloud/dialogs'
24+
import { translate as t } from '@nextcloud/l10n'
25+
26+
import logger from '../logger.js'
27+
28+
/**
29+
* @param {import('axios').AxiosError} error the error
30+
* @param {string?} message the message to display
31+
*/
32+
export const handleError = (error, message) => {
33+
let fullMessage = ''
34+
35+
if (message) {
36+
fullMessage += message
37+
}
38+
39+
if (error.response?.status === 429) {
40+
if (fullMessage) {
41+
fullMessage += '\n'
42+
}
43+
fullMessage += t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.')
44+
}
45+
46+
showError(fullMessage)
47+
logger.error(fullMessage || t('Error'), error)
48+
}

0 commit comments

Comments
 (0)