diff --git a/app/admin/forms.py b/app/admin/forms.py index c47280f9..43c48e51 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -167,26 +167,16 @@ class AddUserForm(FlaskForm): class EditUserForm(FlaskForm): - about = TextAreaField(_l('Bio'), validators=[Optional(), Length(min=3, max=5000)]) - email = StringField(_l('Email address'), validators=[Optional(), Length(max=255)]) - matrix_user_id = StringField(_l('Matrix User ID'), validators=[Optional(), Length(max=255)]) - profile_file = FileField(_l('Avatar image')) - banner_file = FileField(_l('Top banner image')) bot = BooleanField(_l('This profile is a bot')) verified = BooleanField(_l('Email address is verified')) banned = BooleanField(_l('Banned')) - newsletter = BooleanField(_l('Subscribe to email newsletter')) - ignore_bots = BooleanField(_l('Hide posts by bots')) - nsfw = BooleanField(_l('Show NSFW posts')) - nsfl = BooleanField(_l('Show NSFL posts')) - searchable = BooleanField(_l('Show profile in user list')) - indexable = BooleanField(_l('Allow search engines to index this profile')) - manually_approves_followers = BooleanField(_l('Manually approve followers')) role_options = [(2, _l('User')), (3, _l('Staff')), (4, _l('Admin')), ] role = SelectField(_l('Role'), choices=role_options, default=2, coerce=int) + remove_avatar = BooleanField(_l('Remove avatar')) + remove_banner = BooleanField(_l('Remove banner')) submit = SubmitField(_l('Save')) diff --git a/app/admin/routes.py b/app/admin/routes.py index 776d1169..2ecc2c54 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -535,46 +535,20 @@ def admin_user_edit(user_id): form = EditUserForm() user = User.query.get_or_404(user_id) if form.validate_on_submit(): - user.about = form.about.data - user.email = form.email.data - user.about_html = markdown_to_html(form.about.data) - user.matrix_user_id = form.matrix_user_id.data user.bot = form.bot.data user.verified = form.verified.data user.banned = form.banned.data - profile_file = request.files['profile_file'] - if profile_file and profile_file.filename != '': - # remove old avatar - if user.avatar_id: - file = File.query.get(user.avatar_id) - file.delete_from_disk() - user.avatar_id = None - db.session.delete(file) + if form.remove_avatar.data and user.avatar_id: + file = File.query.get(user.avatar_id) + file.delete_from_disk() + user.avatar_id = None + db.session.delete(file) - # add new avatar - file = save_icon_file(profile_file, 'users') - if file: - user.avatar = file - banner_file = request.files['banner_file'] - if banner_file and banner_file.filename != '': - # remove old cover - if user.cover_id: - file = File.query.get(user.cover_id) - file.delete_from_disk() - user.cover_id = None - db.session.delete(file) - - # add new cover - file = save_banner_file(banner_file, 'users') - if file: - user.cover = file - user.newsletter = form.newsletter.data - user.ignore_bots = form.ignore_bots.data - user.show_nsfw = form.nsfw.data - user.show_nsfl = form.nsfl.data - user.searchable = form.searchable.data - user.indexable = form.indexable.data - user.ap_manually_approves_followers = form.manually_approves_followers.data + if form.remove_banner.data and user.cover_id: + file = File.query.get(user.cover_id) + file.delete_from_disk() + user.cover_id = None + db.session.delete(file) # Update user roles. The UI only lets the user choose 1 role but the DB structure allows for multiple roles per user. db.session.execute(text('DELETE FROM user_role WHERE user_id = :user_id'), {'user_id': user.id}) @@ -589,19 +563,9 @@ def admin_user_edit(user_id): else: if not user.is_local(): flash(_('This is a remote user - most settings here will be regularly overwritten with data from the original server.'), 'warning') - form.about.data = user.about - form.email.data = user.email - form.matrix_user_id.data = user.matrix_user_id - form.newsletter.data = user.newsletter form.bot.data = user.bot form.verified.data = user.verified form.banned.data = user.banned - form.ignore_bots.data = user.ignore_bots - form.nsfw.data = user.show_nsfw - form.nsfl.data = user.show_nsfl - form.searchable.data = user.searchable - form.indexable.data = user.indexable - form.manually_approves_followers.data = user.ap_manually_approves_followers if user.roles and user.roles.count() > 0: form.role.data = user.roles[0].id diff --git a/app/templates/admin/edit_user.html b/app/templates/admin/edit_user.html index 9e2d7b8c..1bf6b475 100644 --- a/app/templates/admin/edit_user.html +++ b/app/templates/admin/edit_user.html @@ -17,29 +17,26 @@

{{ _('Edit %(user_name)s (%(display_name)s)', user_name=user.user_name, display_name=user.display_name()) }}

{{ form.csrf_token() }} - {{ render_field(form.about) }} - {{ render_field(form.email) }} - {{ render_field(form.matrix_user_id) }} + {{ user.about_html|safe if user.about_html }} +

Email: {{ user.email }}

+

Matrix: {{ user.matrix_user_id if user.matrix_user_id }}

{% if user.avatar_id %} {% endif %} - {{ render_field(form.profile_file) }} - Provide a square image that looks good when small. {% if user.cover_id %} {% endif %} - {{ render_field(form.banner_file) }} - Provide a wide image - letterbox orientation. {{ render_field(form.bot) }} {{ render_field(form.verified) }} {{ render_field(form.banned) }} - {{ render_field(form.newsletter) }} - {{ render_field(form.nsfw) }} - {{ render_field(form.nsfl) }} - {{ render_field(form.searchable) }} - {{ render_field(form.indexable) }} - {{ render_field(form.manually_approves_followers) }} +

receive newsletter: {{ user.newsletter }}

+

view nsfw: {{ user.nsfw }}

+

view nsfl: {{ user.nsfl }}

+

searchable: {{ user.searchable }}

+

indexable: {{ user.indexable }}

{{ render_field(form.role) }} + {{ render_field(form.remove_avatar) }} + {{ render_field(form.remove_banner) }} {{ render_field(form.submit) }}