mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-11 08:30:41 +00:00
Update settings page
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
from flask_login import current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import (
|
||||
BooleanField,
|
||||
FileField,
|
||||
PasswordField,
|
||||
SelectField,
|
||||
@ -67,9 +66,6 @@ class EditAccountForm(FlaskForm):
|
||||
|
||||
|
||||
class EditProfileForm(FlaskForm):
|
||||
show_email = BooleanField('Email')
|
||||
show_last_seen = BooleanField('Last seen')
|
||||
show_member_since = BooleanField('Member since')
|
||||
avatar = FileField(
|
||||
'Image File',
|
||||
[FileSizeLimit(max_size_in_mb=2)]
|
||||
|
@ -7,6 +7,7 @@ from app.decorators import content_negotiation
|
||||
from app.models import Avatar, User, ProfilePrivacySettings
|
||||
from . import bp
|
||||
|
||||
|
||||
@bp.route('/<hashid:user_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
@content_negotiation(produces='application/json')
|
||||
@ -32,6 +33,7 @@ def delete_user(user_id):
|
||||
}
|
||||
return response_data, 202
|
||||
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatar', methods=['DELETE'])
|
||||
@content_negotiation(produces='application/json')
|
||||
def delete_profile_avatar(user_id):
|
||||
@ -53,7 +55,8 @@ def delete_profile_avatar(user_id):
|
||||
}
|
||||
return response_data, 202
|
||||
|
||||
@bp.route('/<hashid:user_id>/is_public', methods=['PUT'])
|
||||
|
||||
@bp.route('/<hashid:user_id>/is-public', methods=['PUT'])
|
||||
@login_required
|
||||
@content_negotiation(consumes='application/json', produces='application/json')
|
||||
def update_user_is_public(user_id):
|
||||
@ -73,26 +76,25 @@ def update_user_is_public(user_id):
|
||||
return response_data, 200
|
||||
|
||||
|
||||
# @bp.route('/<hashid:user_id>/profile-privacy-settings', methods=['PUT'])
|
||||
# @login_required
|
||||
# @content_negotiation(consumes='application/json', produces='application/json')
|
||||
# def update_profile_privacy_settings(user_id):
|
||||
# profile_privacy_settings = request.json
|
||||
# if not isinstance(profile_privacy_settings, list):
|
||||
# abort(400)
|
||||
# for profile_privacy_setting in profile_privacy_settings:
|
||||
# if not isinstance(profile_privacy_setting, str):
|
||||
# abort(400)
|
||||
# if not profile_privacy_setting in ProfilePrivacySettings.__members__:
|
||||
# abort(400)
|
||||
# user = User.query.get_or_404(user_id)
|
||||
# user.is_public = is_public
|
||||
# db.session.commit()
|
||||
# response_data = {
|
||||
# 'message': (
|
||||
# f'User "{user.username}" is now'
|
||||
# f' {"public" if is_public else "private"}'
|
||||
# ),
|
||||
# 'category': 'corpus'
|
||||
# }
|
||||
# return response_data, 200
|
||||
@bp.route('/<hashid:user_id>/profile-privacy-settings/<string:profile_privacy_setting_name>', methods=['PUT'])
|
||||
@login_required
|
||||
@content_negotiation(consumes='application/json', produces='application/json')
|
||||
def add_profile_privacy_settings(user_id, profile_privacy_setting_name):
|
||||
user = User.query.get_or_404(user_id)
|
||||
enabled = request.json
|
||||
if not isinstance(enabled, bool):
|
||||
abort(400)
|
||||
try:
|
||||
profile_privacy_setting = ProfilePrivacySettings[profile_privacy_setting_name]
|
||||
except KeyError:
|
||||
abort(404)
|
||||
if enabled:
|
||||
user.add_profile_privacy_setting(profile_privacy_setting)
|
||||
else:
|
||||
user.remove_profile_privacy_setting(profile_privacy_setting)
|
||||
db.session.commit()
|
||||
response_data = {
|
||||
'message': 'Profile privacy settings updated',
|
||||
'category': 'corpus'
|
||||
}
|
||||
return response_data, 200
|
||||
|
@ -33,18 +33,6 @@ def settings():
|
||||
# endregion handle edit profile settings forms
|
||||
# region handle edit public profile information form
|
||||
if edit_profile_form.validate_on_submit():
|
||||
if edit_profile_form.show_email.data:
|
||||
user.add_profile_privacy_setting('SHOW_EMAIL')
|
||||
else:
|
||||
user.remove_profile_privacy_setting('SHOW_EMAIL')
|
||||
if edit_profile_form.show_last_seen.data:
|
||||
user.add_profile_privacy_setting('SHOW_LAST_SEEN')
|
||||
else:
|
||||
user.remove_profile_privacy_setting('SHOW_LAST_SEEN')
|
||||
if edit_profile_form.show_member_since.data:
|
||||
user.add_profile_privacy_setting('SHOW_MEMBER_SINCE')
|
||||
else:
|
||||
user.remove_profile_privacy_setting('SHOW_MEMBER_SINCE')
|
||||
if edit_profile_form.avatar.data:
|
||||
try:
|
||||
Avatar.create(
|
||||
|
Reference in New Issue
Block a user