Improve handling of profile fields

Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit c2d2ae3c59)
This commit is contained in:
Christopher Ng 2023-04-03 17:37:47 -07:00
parent 422c81948f
commit 4d95ddbfd0
14 changed files with 87 additions and 25 deletions

View file

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

View file

@ -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.'))
}
});
},
@ -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);
},

View file

@ -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',
@ -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);

View file

@ -344,6 +344,7 @@ class UsersController extends Controller {
* @NoAdminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UserRateThrottle(limit=50, period=600)
*
* @param string|null $avatarScope
* @param string|null $displayname

View file

@ -80,10 +80,10 @@
<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 '../shared/FederationControl'
import { handleError } from '../../../utils/handlers.js'
import { ACCOUNT_PROPERTY_READABLE_ENUM, VERIFICATION_ENUM } from '../../../constants/AccountPropertyConstants'
import {
@ -338,8 +338,7 @@ export default {
this.showCheckmarkIcon = true
setTimeout(() => { this.showCheckmarkIcon = false }, 2000)
} else {
showError(errorMessage)
this.logger.error(errorMessage, error)
handleError(error, errorMessage)
this.showErrorIcon = true
setTimeout(() => { this.showErrorIcon = false }, 2000)
}

View file

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

View file

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

View file

@ -34,12 +34,12 @@
</template>
<script>
import { showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { savePrimaryAccountProperty } from '../../../service/PersonalInfo/PersonalInfoService'
import { validateBoolean } from '../../../utils/validate'
import { ACCOUNT_PROPERTY_ENUM } from '../../../constants/AccountPropertyConstants'
import { handleError } from '../../../utils/handlers.js'
export default {
name: 'ProfileCheckbox',
@ -88,8 +88,7 @@ export default {
this.initialProfileEnabled = isEnabled
emit('settings:profile-enabled:updated', isEnabled)
} else {
showError(errorMessage)
this.logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},
},

View file

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

View file

@ -41,7 +41,6 @@
<script>
import Actions from '@nextcloud/vue/dist/Components/Actions'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import FederationControlAction from './FederationControlAction'
@ -53,6 +52,7 @@ import {
UNPUBLISHED_READABLE_PROPERTIES,
} from '../../../constants/AccountPropertyConstants'
import { savePrimaryAccountPropertyScope } from '../../../service/PersonalInfo/PersonalInfoService'
import { handleError } from '../../../utils/handlers.js'
const { lookupServerUploadEnabled } = loadState('settings', 'accountParameters', {})
@ -171,8 +171,7 @@ export default {
this.initialScope = scope
} else {
this.$emit('update:scope', this.initialScope)
showError(errorMessage)
this.logger.error(errorMessage, error)
handleError(error, errorMessage)
}
},
},

View file

@ -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)
}

View file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long