mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-11 08:30:41 +00:00
move settings related json routes to users package
This commit is contained in:
@ -2,5 +2,4 @@ from flask import Blueprint
|
||||
|
||||
|
||||
bp = Blueprint('settings', __name__)
|
||||
from . import routes, json_routes
|
||||
|
||||
from . import routes
|
||||
|
@ -1,71 +0,0 @@
|
||||
from flask import abort, current_app, request
|
||||
from flask_login import current_user, login_required, logout_user
|
||||
from threading import Thread
|
||||
import os
|
||||
from app import db
|
||||
from app.decorators import content_negotiation
|
||||
from app.models import Avatar, User, ProfilePrivacySettings
|
||||
from . import bp
|
||||
|
||||
|
||||
@bp.route('/<hashid:user_id>/avatar', methods=['DELETE'])
|
||||
@content_negotiation(produces='application/json')
|
||||
def delete_profile_avatar(user_id):
|
||||
def _delete_avatar(app, avatar_id):
|
||||
with app.app_context():
|
||||
avatar = Avatar.query.get(avatar_id)
|
||||
avatar.delete()
|
||||
db.session.commit()
|
||||
user = User.query.get_or_404(user_id)
|
||||
if user.avatar is None:
|
||||
abort(404)
|
||||
thread = Thread(
|
||||
target=_delete_avatar,
|
||||
args=(current_app._get_current_object(), user.avatar.id)
|
||||
)
|
||||
thread.start()
|
||||
response_data = {
|
||||
'message': f'Avatar marked for deletion'
|
||||
}
|
||||
return response_data, 202
|
||||
|
||||
|
||||
@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):
|
||||
is_public = request.json
|
||||
if not isinstance(is_public, bool):
|
||||
abort(400)
|
||||
user = User.query.get_or_404(user_id)
|
||||
user.is_public = is_public
|
||||
db.session.commit()
|
||||
response_data = {
|
||||
'message': 'Profile privacy settings updated',
|
||||
'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
|
@ -1,6 +0,0 @@
|
||||
from flask import request, url_for
|
||||
from app.models import User
|
||||
|
||||
|
||||
def user_endpoint_arguments_constructor():
|
||||
return {'user_id': request.view_args['user_id']}
|
Reference in New Issue
Block a user