diff --git a/core/admin/mailu/ui/views/users.py b/core/admin/mailu/ui/views/users.py index df0a716d..3b9e9485 100644 --- a/core/admin/mailu/ui/views/users.py +++ b/core/admin/mailu/ui/views/users.py @@ -92,14 +92,12 @@ def user_settings(user_email): user = models.User.query.get(user_email_or_current) or flask.abort(404) form = forms.UserSettingsForm(obj=user) utils.formatCSVField(form.forward_destination) - form.forward_enabled.data = bool(flask.request.form.get('forward_enabled', False)) if form.validate_on_submit(): + user.forward_enabled = bool(flask.request.form.get('forward_enabled', False)) if form.forward_enabled and (form.forward_destination.data in ['', None] or type(form.forward_destination.data) is list): flask.flash('Destination email address is missing', 'error') return flask.redirect( - flask.url_for('.user_settings', user=user.email)) - if not user.forward_enabled and not flask.request.form.get('forward_destination', None): - form.forward_destination.data = "" + flask.url_for('.user_settings', user_email=user_email)) form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",") form.populate_obj(user) models.db.session.commit() @@ -109,8 +107,9 @@ def user_settings(user_email): return flask.redirect( flask.url_for('.user_list', domain_name=user.domain.name)) elif form.is_submitted() and not form.validate(): + flask.flash('Error validating the form', 'error') return flask.redirect( - flask.url_for('.user_settings', user=user.email)) + flask.url_for('.user_settings', user_email=user_email)) return flask.render_template('user/settings.html', form=form, user=user) def _process_password_change(form, user_email): diff --git a/core/admin/mailu/utils.py b/core/admin/mailu/utils.py index 13522d79..2af352db 100644 --- a/core/admin/mailu/utils.py +++ b/core/admin/mailu/utils.py @@ -532,6 +532,7 @@ def isBadOrPwned(form): def formatCSVField(field): if not field.data: + field.data = '' return if isinstance(field.data,str): data = field.data.replace(" ","").split(",")