mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 17:10:41 +00:00
cleanup CorpusFollowerPermissions
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
from flask import abort, request
|
||||
from flask_login import current_user
|
||||
from app import db
|
||||
from app.decorators import content_negotiation
|
||||
from app.models import (
|
||||
@ -8,12 +7,12 @@ from app.models import (
|
||||
CorpusFollowerRole,
|
||||
User
|
||||
)
|
||||
from ..decorators import corpus_owner_or_admin_required
|
||||
from ..decorators import corpus_follower_permission_required
|
||||
from . import bp
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/followers', methods=['POST'])
|
||||
@corpus_owner_or_admin_required
|
||||
@corpus_follower_permission_required('ADD_FOLLOWER')
|
||||
@content_negotiation(consumes='application/json', produces='application/json')
|
||||
def create_corpus_followers(corpus_id):
|
||||
usernames = request.json
|
||||
@ -32,7 +31,7 @@ def create_corpus_followers(corpus_id):
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['PUT'])
|
||||
@corpus_owner_or_admin_required
|
||||
@corpus_follower_permission_required('UPDATE_FOLLOWER')
|
||||
@content_negotiation(consumes='application/json', produces='application/json')
|
||||
def update_corpus_follower_role(corpus_id, follower_id):
|
||||
role_name = request.json
|
||||
@ -52,19 +51,17 @@ def update_corpus_follower_role(corpus_id, follower_id):
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>', methods=['DELETE'])
|
||||
@corpus_follower_permission_required('REMOVE_FOLLOWER')
|
||||
@content_negotiation(produces='application/json')
|
||||
def delete_corpus_follower(corpus_id, follower_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
follower = User.query.get_or_404(follower_id)
|
||||
if not (corpus.user == current_user or follower == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
if not follower.is_following_corpus(corpus):
|
||||
abort(409)
|
||||
follower.unfollow_corpus(corpus)
|
||||
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
||||
cfa.follower.unfollow_corpus(cfa.corpus)
|
||||
db.session.commit()
|
||||
response_data = {
|
||||
'message': \
|
||||
f'"{follower.username}" is not following "{corpus.title}" anymore',
|
||||
'message': (
|
||||
f'"{cfa.follower.username}" is not following '
|
||||
f'"{cfa.corpus.title}" anymore'
|
||||
),
|
||||
'category': 'corpus'
|
||||
}
|
||||
return response_data, 200
|
||||
|
Reference in New Issue
Block a user