Skip to content

Commit

Permalink
Improve handling of profile fields
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit cd73dbb)
  • Loading branch information
Pytal committed Apr 4, 2023
1 parent cea457b commit c78283b
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 9 deletions.
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
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 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 {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)
}

0 comments on commit c78283b

Please sign in to comment.