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

[stable22] Improve handling of profile fields #37563

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Expand Up @@ -606,6 +606,7 @@ public function getEditableFieldsForUser(string $userId): DataResponse {
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=5, period=60)
*
* @throws OCSException
*/
Expand Down Expand Up @@ -698,6 +699,7 @@ public function editUserMultiValue(
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=50, period=600)
*
* edit users
*
Expand Down
11 changes: 10 additions & 1 deletion apps/settings/js/federationsettingsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
} else {
self._showInputChangeFail(field);
}
}).fail(function(data) {
if (data.status === 429) {
OC.Notification.showTemporary(t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.'))
}
});
},

Expand All @@ -181,7 +185,12 @@
$('#' + field + 'scope').val(scope);

// TODO: user loading/success feedback
this._config.save();
var savingData = this._config.save();
$.when(savingData).fail(function(data) {
if (data.status === 429) {
OC.Notification.showTemporary(t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.'))
}
});
this._setFieldScopeIcon(field, scope);
this._updateVerifyButton(field, scope);
},
Expand Down
12 changes: 10 additions & 2 deletions apps/settings/js/settings/personalInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ window.addEventListener('DOMContentLoaded', function () {
var selectedLocale = $("#localeinput").val(),
user = OC.getCurrentUser();

var errorMessage = t('settings', 'An error occurred while changing your locale. Please reload the page and try again.')

$.ajax({
url: OC.linkToOCS('cloud/users', 2) + user['uid'],
method: 'PUT',
Expand All @@ -259,8 +261,14 @@ window.addEventListener('DOMContentLoaded', function () {
moment.locale(selectedLocale);
},
fail: function() {
OC.Notification.showTemporary(t('settings', 'An error occurred while changing your locale. Please reload the page and try again.'));
}
OC.Notification.showTemporary(errorMessage);
},
error: function(xhr) {
if (xhr.status === 429) {
errorMessage += '\n' + t('settings', 'There were too many requests from your network. Retry later or contact your administrator if this is an error.')
}
OC.Notification.showTemporary(errorMessage)
},
});
};
$("#localeinput").change(updateLocale);
Expand Down
22 changes: 11 additions & 11 deletions apps/settings/js/vue-settings-admin-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-admin-security.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions apps/settings/js/vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions apps/settings/js/vue-settings-personal-info.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions apps/settings/js/vue-settings-personal-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-security.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions apps/settings/js/vue-settings-personal-webauthn.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-settings-personal-webauthn.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions apps/settings/js/vue-vendors-settings-apps-settings-users.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions apps/settings/js/vue-vendors-settings-apps.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-vendors-settings-apps.js.map

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions apps/settings/js/vue-vendors-settings-users.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/settings/js/vue-vendors-settings-users.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/settings/lib/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ protected function canAdminChangeUserPasswords(): bool {
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=50, period=600)
*
* @param string|null $avatarScope
* @param string|null $displayname
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
<script>
import Actions from '@nextcloud/vue/dist/Components/Actions'
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
import { showError } from '@nextcloud/dialogs'
import debounce from 'debounce'

import FederationControl from './FederationControl'
import { VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants'
import { savePrimaryEmail, saveAdditionalEmail, saveNotificationEmail, updateAdditionalEmail, removeAdditionalEmail } from '../../../service/PersonalInfoService'
import { handleError } from '../../../utils/handlers.js'

export default {
name: 'Email',
Expand Down Expand Up @@ -316,8 +316,7 @@ export default {
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(t('settings', errorMessage))
this.logger.error(errorMessage, error)
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
Expand All @@ -330,8 +329,7 @@ export default {
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(t('settings', errorMessage))
this.logger.error(errorMessage, error)
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

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

import HeaderBar from './HeaderBar'
import Email from './Email'
import { savePrimaryEmail, removeAdditionalEmail } from '../../../service/PersonalInfoService'
import { DEFAULT_ADDITIONAL_EMAIL_SCOPE } from '../../../constants/AccountPropertyConstants'
import { handleError } from '../../../utils/handlers.js'

const { additionalEmails, primaryEmail, notificationEmail } = loadState('settings', 'emails', {})
const { displayNameChangeSupported } = loadState('settings', 'accountParameters', {})
Expand Down Expand Up @@ -165,8 +165,7 @@ export default {

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

Expand Down
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 {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)
}