Improve handling of profile fields

Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
Christopher Ng 2023-03-30 17:11:41 -07:00
Родитель 636c2415cc
Коммит 7bc8b543be
13 изменённых файлов: 70 добавлений и 36 удалений

Просмотреть файл

@ -631,6 +631,7 @@ class UsersController extends AUserData {
* @NoAdminRequired * @NoAdminRequired
* @NoSubAdminRequired * @NoSubAdminRequired
* @PasswordConfirmationRequired * @PasswordConfirmationRequired
* @UserRateThrottle(limit=5, period=60)
* *
* @throws OCSException * @throws OCSException
*/ */
@ -723,6 +724,7 @@ class UsersController extends AUserData {
* @NoAdminRequired * @NoAdminRequired
* @NoSubAdminRequired * @NoSubAdminRequired
* @PasswordConfirmationRequired * @PasswordConfirmationRequired
* @UserRateThrottle(limit=50, period=600)
* *
* edit users * edit users
* *

Просмотреть файл

@ -90,11 +90,10 @@ import { NcActions, NcActionButton } from '@nextcloud/vue'
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue' import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue' import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
import Check from 'vue-material-design-icons/Check.vue' import Check from 'vue-material-design-icons/Check.vue'
import { showError } from '@nextcloud/dialogs'
import debounce from 'debounce' import debounce from 'debounce'
import FederationControl from '../shared/FederationControl.vue' import FederationControl from '../shared/FederationControl.vue'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants.js' import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { import {
@ -358,8 +357,7 @@ export default {
this.showCheckmarkIcon = true this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000) setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else { } else {
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
this.showErrorIcon = true this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000) setTimeout(() => { this.showErrorIcon = false }, 2000)
} }

Просмотреть файл

@ -63,7 +63,6 @@
<script> <script>
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import Email from './Email.vue' import Email from './Email.vue'
import HeaderBar from '../shared/HeaderBar.vue' import HeaderBar from '../shared/HeaderBar.vue'
@ -71,7 +70,7 @@ import HeaderBar from '../shared/HeaderBar.vue'
import { ACCOUNT_PROPERTY_READABLE_ENUM, DEFAULT_ADDITIONAL_EMAIL_SCOPE, NAME_READABLE_ENUM } from '../../../constants/AccountPropertyConstants.js' import { ACCOUNT_PROPERTY_READABLE_ENUM, DEFAULT_ADDITIONAL_EMAIL_SCOPE, NAME_READABLE_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryEmail, savePrimaryEmailScope, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService.js' import { savePrimaryEmail, savePrimaryEmailScope, removeAdditionalEmail } from '../../../service/PersonalInfo/EmailService.js'
import { validateEmail } from '../../../utils/validate.js' import { validateEmail } from '../../../utils/validate.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
const { emailMap: { additionalEmails, primaryEmail, notificationEmail } } = loadState('settings', 'personalInfoParameters', {}) const { emailMap: { additionalEmails, primaryEmail, notificationEmail } } = loadState('settings', 'personalInfoParameters', {})
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {}) const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
@ -186,8 +185,7 @@ export default {
handleResponse(status, errorMessage, error) { handleResponse(status, errorMessage, error) {
if (status !== 'ok') { if (status !== 'ok') {
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
}, },

Просмотреть файл

@ -51,12 +51,10 @@
</template> </template>
<script> <script>
import { showError } from '@nextcloud/dialogs'
import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js' import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js' import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { validateLanguage } from '../../../utils/validate.js' import { validateLanguage } from '../../../utils/validate.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
export default { export default {
name: 'Language', name: 'Language',
@ -133,8 +131,7 @@ export default {
// Ensure that local state reflects server state // Ensure that local state reflects server state
this.initialLanguage = language this.initialLanguage = language
} else { } else {
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
}, },

Просмотреть файл

@ -58,14 +58,13 @@
</template> </template>
<script> <script>
import { showError } from '@nextcloud/dialogs'
import moment from '@nextcloud/moment' import moment from '@nextcloud/moment'
import Web from 'vue-material-design-icons/Web.vue' import Web from 'vue-material-design-icons/Web.vue'
import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js' import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js' import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { validateLocale } from '../../../utils/validate.js' import { validateLocale } from '../../../utils/validate.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
export default { export default {
name: 'Locale', name: 'Locale',
@ -155,8 +154,7 @@ export default {
this.initialLocale = locale this.initialLocale = locale
} else { } else {
this.$emit('update:locale', this.initialLocale) this.$emit('update:locale', this.initialLocale)
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
}, },

Просмотреть файл

@ -32,13 +32,12 @@
</template> </template>
<script> <script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus' import { emit } from '@nextcloud/event-bus'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js' import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js' import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import logger from '../../../logger.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js' import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import { handleError } from '../../../utils/handlers.js'
export default { export default {
name: 'ProfileCheckbox', name: 'ProfileCheckbox',
@ -82,8 +81,7 @@ export default {
if (status === 'ok') { if (status === 'ok') {
emit('settings:profile-enabled:updated', isProfileEnabled) emit('settings:profile-enabled:updated', isProfileEnabled)
} else { } else {
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
this.loading = false this.loading = false
}, },

Просмотреть файл

@ -36,7 +36,6 @@
</template> </template>
<script> <script>
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import { subscribe, unsubscribe } from '@nextcloud/event-bus' import { subscribe, unsubscribe } from '@nextcloud/event-bus'
@ -44,7 +43,7 @@ import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
import { saveProfileParameterVisibility } from '../../../service/ProfileService.js' import { saveProfileParameterVisibility } from '../../../service/ProfileService.js'
import { VISIBILITY_PROPERTY_ENUM } from '../../../constants/ProfileConstants.js' import { VISIBILITY_PROPERTY_ENUM } from '../../../constants/ProfileConstants.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
const { profileEnabled } = loadState('settings', 'personalInfoParameters', false) const { profileEnabled } = loadState('settings', 'personalInfoParameters', false)
@ -136,8 +135,7 @@ export default {
// Ensure that local state reflects server state // Ensure that local state reflects server state
this.initialVisibility = visibility this.initialVisibility = visibility
} else { } else {
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
}, },

Просмотреть файл

@ -71,7 +71,6 @@
<script> <script>
import debounce from 'debounce' import debounce from 'debounce'
import { showError } from '@nextcloud/dialogs'
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue' import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue' import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
@ -80,7 +79,7 @@ import Check from 'vue-material-design-icons/Check.vue'
import HeaderBar from '../shared/HeaderBar.vue' import HeaderBar from '../shared/HeaderBar.vue'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js' import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
export default { export default {
name: 'AccountPropertySection', name: 'AccountPropertySection',
@ -196,8 +195,7 @@ export default {
setTimeout(() => { this.showCheckmarkIcon = false }, 2000) setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else { } else {
this.$emit('update:value', this.initialValue) this.$emit('update:value', this.initialValue)
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
this.showErrorIcon = true this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000) setTimeout(() => { this.showErrorIcon = false }, 2000)
} }

Просмотреть файл

@ -42,7 +42,6 @@
<script> <script>
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js' import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import FederationControlAction from './FederationControlAction.vue' import FederationControlAction from './FederationControlAction.vue'
@ -56,7 +55,7 @@ import {
UNPUBLISHED_READABLE_PROPERTIES, UNPUBLISHED_READABLE_PROPERTIES,
} from '../../../constants/AccountPropertyConstants.js' } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService.js' import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService.js'
import logger from '../../../logger.js' import { handleError } from '../../../utils/handlers.js'
const { const {
federationEnabled, federationEnabled,
@ -188,8 +187,7 @@ export default {
this.initialScope = scope this.initialScope = scope
} else { } else {
this.$emit('update:scope', this.initialScope) this.$emit('update:scope', this.initialScope)
showError(errorMessage) handleError(error, errorMessage)
logger.error(errorMessage, error)
} }
}, },
}, },

Просмотреть файл

@ -0,0 +1,48 @@
/**
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
*
* @author Christopher Ng <chrng8@gmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import logger from '../logger.js'
/**
* @param {import('axios').AxiosError} error the error
* @param {string?} message the message to display
*/
export const handleError = (error, message) => {
let fullMessage = ''
if (message) {
fullMessage += message
}
if (error.response?.status === 429) {
if (fullMessage) {
fullMessage += '\n'
}
fullMessage += t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.')
}
showError(fullMessage)
logger.error(fullMessage || t('Error'), error)
}

Просмотреть файл

@ -61,6 +61,7 @@ class ProfileApiController extends OCSController {
* @NoAdminRequired * @NoAdminRequired
* @NoSubAdminRequired * @NoSubAdminRequired
* @PasswordConfirmationRequired * @PasswordConfirmationRequired
* @UserRateThrottle(limit=40, period=600)
*/ */
public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse { public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse {
$requestingUser = $this->userSession->getUser(); $requestingUser = $this->userSession->getUser();

4
dist/settings-vue-settings-personal-info.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны