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

[stable26] Improve handling of profile fields #37523

Merged
merged 1 commit into from
Apr 4, 2023
Merged
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
2 changes: 2 additions & 0 deletions apps/provisioning_api/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
@@ -634,6 +634,7 @@ public function getEditableFieldsForUser(string $userId): DataResponse {
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=5, period=60)
*
* @throws OCSException
*/
@@ -726,6 +727,7 @@ public function editUserMultiValue(
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=50, period=600)
*
* edit users
*
Original file line number Diff line number Diff line change
@@ -90,11 +90,10 @@ import { NcActions, NcActionButton } from '@nextcloud/vue'
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import AlertOctagon from 'vue-material-design-icons/AlertOctagon.vue'
import Check from 'vue-material-design-icons/Check'
import { showError } from '@nextcloud/dialogs'
import debounce from 'debounce'

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 {
@@ -358,8 +357,7 @@ export default {
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
Original file line number Diff line number Diff line change
@@ -63,15 +63,14 @@

<script>
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'

import Email from './Email.vue'
import HeaderBar from '../shared/HeaderBar.vue'

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 { 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 { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
@@ -186,8 +185,7 @@ export default {

handleResponse(status, errorMessage, error) {
if (status !== 'ok') {
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},

Original file line number Diff line number Diff line change
@@ -51,12 +51,10 @@
</template>

<script>
import { showError } from '@nextcloud/dialogs'

import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { validateLanguage } from '../../../utils/validate.js'
import logger from '../../../logger.js'
import { handleError } from '../../../utils/handlers.js'

export default {
name: 'Language',
@@ -133,8 +131,7 @@ export default {
// Ensure that local state reflects server state
this.initialLanguage = language
} else {
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},

Original file line number Diff line number Diff line change
@@ -58,14 +58,13 @@
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import moment from '@nextcloud/moment'
import Web from 'vue-material-design-icons/Web'

import { ACCOUNT_SETTING_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { validateLocale } from '../../../utils/validate.js'
import logger from '../../../logger.js'
import { handleError } from '../../../utils/handlers.js'

export default {
name: 'Locale',
@@ -155,8 +154,7 @@ export default {
this.initialLocale = locale
} else {
this.$emit('update:locale', this.initialLocale)
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},

Original file line number Diff line number Diff line change
@@ -32,13 +32,12 @@
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'

import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants.js'
import logger from '../../../logger.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import { handleError } from '../../../utils/handlers.js'

export default {
name: 'ProfileCheckbox',
@@ -82,8 +81,7 @@ export default {
if (status === 'ok') {
emit('settings:profile-enabled:updated', isProfileEnabled)
} else {
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
this.loading = false
},
Original file line number Diff line number Diff line change
@@ -36,15 +36,14 @@
</template>

<script>
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'

import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'

import { saveProfileParameterVisibility } from '../../../service/ProfileService.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)

@@ -136,8 +135,7 @@ export default {
// Ensure that local state reflects server state
this.initialVisibility = visibility
} else {
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},

Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@

<script>
import debounce from 'debounce'
import { showError } from '@nextcloud/dialogs'

import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
import AlertOctagon from 'vue-material-design-icons/AlertOctagon'
@@ -80,7 +79,7 @@ import Check from 'vue-material-design-icons/Check'
import HeaderBar from '../shared/HeaderBar.vue'

import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService.js'
import logger from '../../../logger.js'
import { handleError } from '../../../utils/handlers.js'

export default {
name: 'AccountPropertySection',
@@ -196,8 +195,7 @@ export default {
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
this.$emit('update:value', this.initialValue)
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@
<script>
import NcActions from '@nextcloud/vue/dist/Components/NcActions'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'

import FederationControlAction from './FederationControlAction.vue'

@@ -56,7 +55,7 @@ import {
UNPUBLISHED_READABLE_PROPERTIES,
} from '../../../constants/AccountPropertyConstants.js'
import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService.js'
import logger from '../../../logger.js'
import { handleError } from '../../../utils/handlers.js'

const {
federationEnabled,
@@ -188,8 +187,7 @@ export default {
this.initialScope = scope
} else {
this.$emit('update:scope', this.initialScope)
showError(errorMessage)
logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},
},
48 changes: 48 additions & 0 deletions apps/settings/src/utils/handlers.js
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions core/Controller/ProfileApiController.php
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ public function __construct(
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=40, period=600)
*/
public function setVisibility(string $targetUserId, string $paramId, string $visibility): DataResponse {
$requestingUser = $this->userSession->getUser();
4 changes: 2 additions & 2 deletions dist/settings-vue-settings-personal-info.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-personal-info.js.map

Large diffs are not rendered by default.