From b8bcb159a285a796494c56e14d0a757ff037e299 Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Wed, 7 Jun 2023 15:13:47 +0200 Subject: [PATCH] Hide Community Update code --- app/corpora/followers/json_routes.py | 116 +++++++++--------- app/corpora/json_routes.py | 98 +++++++-------- app/corpora/routes.py | 37 +++--- app/main/routes.py | 24 ++-- app/models.py | 2 +- app/static/js/ResourceLists/CorpusList.js | 19 +-- app/templates/_sidenav.html.j2 | 10 +- app/templates/admin/user.html.j2 | 2 +- app/templates/corpora/corpus.html.j2 | 32 ++--- app/templates/users/settings/settings.html.j2 | 16 +-- app/users/json_routes.py | 88 ++++++------- app/users/routes.py | 58 ++++----- 12 files changed, 252 insertions(+), 250 deletions(-) diff --git a/app/corpora/followers/json_routes.py b/app/corpora/followers/json_routes.py index 87299862..db6bb635 100644 --- a/app/corpora/followers/json_routes.py +++ b/app/corpora/followers/json_routes.py @@ -12,65 +12,65 @@ from ..decorators import corpus_follower_permission_required from . import bp -@bp.route('//followers', methods=['POST']) -@corpus_follower_permission_required('MANAGE_FOLLOWERS') -@content_negotiation(consumes='application/json', produces='application/json') -def create_corpus_followers(corpus_id): - usernames = request.json - if not (isinstance(usernames, list) or all(isinstance(u, str) for u in usernames)): - abort(400) - corpus = Corpus.query.get_or_404(corpus_id) - for username in usernames: - user = User.query.filter_by(username=username, is_public=True).first_or_404() - user.follow_corpus(corpus) - db.session.commit() - response_data = { - 'message': f'Users are now following "{corpus.title}"', - 'category': 'corpus' - } - return response_data, 200 +# @bp.route('//followers', methods=['POST']) +# @corpus_follower_permission_required('MANAGE_FOLLOWERS') +# @content_negotiation(consumes='application/json', produces='application/json') +# def create_corpus_followers(corpus_id): +# usernames = request.json +# if not (isinstance(usernames, list) or all(isinstance(u, str) for u in usernames)): +# abort(400) +# corpus = Corpus.query.get_or_404(corpus_id) +# for username in usernames: +# user = User.query.filter_by(username=username, is_public=True).first_or_404() +# user.follow_corpus(corpus) +# db.session.commit() +# response_data = { +# 'message': f'Users are now following "{corpus.title}"', +# 'category': 'corpus' +# } +# return response_data, 200 -@bp.route('//followers//role', methods=['PUT']) -@corpus_follower_permission_required('MANAGE_FOLLOWERS') -@content_negotiation(consumes='application/json', produces='application/json') -def update_corpus_follower_role(corpus_id, follower_id): - role_name = request.json - if not isinstance(role_name, str): - abort(400) - cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() - if cfr is None: - abort(400) - cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404() - cfa.role = cfr - db.session.commit() - response_data = { - 'message': f'User "{cfa.follower.username}" is now {cfa.role.name}', - 'category': 'corpus' - } - return response_data, 200 +# @bp.route('//followers//role', methods=['PUT']) +# @corpus_follower_permission_required('MANAGE_FOLLOWERS') +# @content_negotiation(consumes='application/json', produces='application/json') +# def update_corpus_follower_role(corpus_id, follower_id): +# role_name = request.json +# if not isinstance(role_name, str): +# abort(400) +# cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() +# if cfr is None: +# abort(400) +# cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404() +# cfa.role = cfr +# db.session.commit() +# response_data = { +# 'message': f'User "{cfa.follower.username}" is now {cfa.role.name}', +# 'category': 'corpus' +# } +# return response_data, 200 -@bp.route('//followers/', methods=['DELETE']) -def delete_corpus_follower(corpus_id, follower_id): - cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404() - if not ( - current_user.id == follower_id - or current_user == cfa.corpus.user - or CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first().role.has_permission('MANAGE_FOLLOWERS') - or current_user.is_administrator()): - abort(403) - if current_user.id == follower_id: - flash(f'You are no longer following "{cfa.corpus.title}"', 'corpus') - response = make_response() - response.status_code = 204 - else: - response_data = { - 'message': f'"{cfa.follower.username}" is not following "{cfa.corpus.title}" anymore', - 'category': 'corpus' - } - response = jsonify(response_data) - response.status_code = 200 - cfa.follower.unfollow_corpus(cfa.corpus) - db.session.commit() - return response +# @bp.route('//followers/', methods=['DELETE']) +# def delete_corpus_follower(corpus_id, follower_id): +# cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404() +# if not ( +# current_user.id == follower_id +# or current_user == cfa.corpus.user +# or CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first().role.has_permission('MANAGE_FOLLOWERS') +# or current_user.is_administrator()): +# abort(403) +# if current_user.id == follower_id: +# flash(f'You are no longer following "{cfa.corpus.title}"', 'corpus') +# response = make_response() +# response.status_code = 204 +# else: +# response_data = { +# 'message': f'"{cfa.follower.username}" is not following "{cfa.corpus.title}" anymore', +# 'category': 'corpus' +# } +# response = jsonify(response_data) +# response.status_code = 200 +# cfa.follower.unfollow_corpus(cfa.corpus) +# db.session.commit() +# return response diff --git a/app/corpora/json_routes.py b/app/corpora/json_routes.py index 908f1604..6005fc48 100644 --- a/app/corpora/json_routes.py +++ b/app/corpora/json_routes.py @@ -57,55 +57,55 @@ def build_corpus(corpus_id): return response_data, 202 -@bp.route('//generate-share-link', methods=['POST']) -@corpus_follower_permission_required('MANAGE_FOLLOWERS') -@content_negotiation(consumes='application/json', produces='application/json') -def generate_corpus_share_link(corpus_id): - data = request.json - if not isinstance(data, dict): - abort(400) - expiration = data.get('expiration') - if not isinstance(expiration, str): - abort(400) - role_name = data.get('role') - if not isinstance(role_name, str): - abort(400) - expiration_date = datetime.strptime(expiration, '%b %d, %Y') - cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() - if cfr is None: - abort(400) - corpus = Corpus.query.get_or_404(corpus_id) - token = current_user.generate_follow_corpus_token(corpus.hashid, role_name, expiration_date) - corpus_share_link = url_for( - 'corpora.follow_corpus', - corpus_id=corpus_id, - token=token, - _external=True - ) - response_data = { - 'message': 'Corpus share link generated', - 'category': 'corpus', - 'corpusShareLink': corpus_share_link - } - return response_data, 200 +# @bp.route('//generate-share-link', methods=['POST']) +# @corpus_follower_permission_required('MANAGE_FOLLOWERS') +# @content_negotiation(consumes='application/json', produces='application/json') +# def generate_corpus_share_link(corpus_id): +# data = request.json +# if not isinstance(data, dict): +# abort(400) +# expiration = data.get('expiration') +# if not isinstance(expiration, str): +# abort(400) +# role_name = data.get('role') +# if not isinstance(role_name, str): +# abort(400) +# expiration_date = datetime.strptime(expiration, '%b %d, %Y') +# cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() +# if cfr is None: +# abort(400) +# corpus = Corpus.query.get_or_404(corpus_id) +# token = current_user.generate_follow_corpus_token(corpus.hashid, role_name, expiration_date) +# corpus_share_link = url_for( +# 'corpora.follow_corpus', +# corpus_id=corpus_id, +# token=token, +# _external=True +# ) +# response_data = { +# 'message': 'Corpus share link generated', +# 'category': 'corpus', +# 'corpusShareLink': corpus_share_link +# } +# return response_data, 200 -@bp.route('//is_public', methods=['PUT']) -@corpus_owner_or_admin_required -@content_negotiation(consumes='application/json', produces='application/json') -def update_corpus_is_public(corpus_id): - is_public = request.json - if not isinstance(is_public, bool): - abort(400) - corpus = Corpus.query.get_or_404(corpus_id) - corpus.is_public = is_public - db.session.commit() - response_data = { - 'message': ( - f'Corpus "{corpus.title}" is now' - f' {"public" if is_public else "private"}' - ), - 'category': 'corpus' - } - return response_data, 200 +# @bp.route('//is_public', methods=['PUT']) +# @corpus_owner_or_admin_required +# @content_negotiation(consumes='application/json', produces='application/json') +# def update_corpus_is_public(corpus_id): +# is_public = request.json +# if not isinstance(is_public, bool): +# abort(400) +# corpus = Corpus.query.get_or_404(corpus_id) +# corpus.is_public = is_public +# db.session.commit() +# response_data = { +# 'message': ( +# f'Corpus "{corpus.title}" is now' +# f' {"public" if is_public else "private"}' +# ), +# 'category': 'corpus' +# } +# return response_data, 200 diff --git a/app/corpora/routes.py b/app/corpora/routes.py index 7d9b30d6..b1b9142d 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -71,16 +71,17 @@ def corpus(corpus_id): users = users ) if (current_user.is_following_corpus(corpus) or corpus.is_public): - cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all() - return render_template( - 'corpora/public_corpus.html.j2', - title=corpus.title, - corpus=corpus, - cfrs=cfrs, - cfr=cfr, - cfas=cfas, - users = users - ) + abort(404) + # cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all() + # return render_template( + # 'corpora/public_corpus.html.j2', + # title=corpus.title, + # corpus=corpus, + # cfrs=cfrs, + # cfr=cfr, + # cfas=cfas, + # users = users + # ) abort(403) @@ -97,14 +98,14 @@ def analysis(corpus_id): ) -@bp.route('//follow/') -def follow_corpus(corpus_id, token): - corpus = Corpus.query.get_or_404(corpus_id) - if current_user.follow_corpus_by_token(token): - db.session.commit() - flash(f'You are following "{corpus.title}" now', category='corpus') - return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) - abort(403) +# @bp.route('//follow/') +# def follow_corpus(corpus_id, token): +# corpus = Corpus.query.get_or_404(corpus_id) +# if current_user.follow_corpus_by_token(token): +# db.session.commit() +# flash(f'You are following "{corpus.title}" now', category='corpus') +# return redirect(url_for('corpora.corpus', corpus_id=corpus_id)) +# abort(403) @bp.route('/import', methods=['GET', 'POST']) diff --git a/app/main/routes.py b/app/main/routes.py index 080616ec..3be92196 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -78,15 +78,15 @@ def terms_of_use(): ) -@bp.route('/social-area') -@register_breadcrumb(bp, '.social_area', 'groupSocial Area') -@login_required -def social_area(): - corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() - users = User.query.filter(User.is_public == True, User.id != current_user.id).all() - return render_template( - 'main/social_area.html.j2', - title='Social Area', - corpora=corpora, - users=users - ) +# @bp.route('/social-area') +# @register_breadcrumb(bp, '.social_area', 'groupSocial Area') +# @login_required +# def social_area(): +# corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() +# users = User.query.filter(User.is_public == True, User.id != current_user.id).all() +# return render_template( +# 'main/social_area.html.j2', +# title='Social Area', +# corpora=corpora, +# users=users +# ) diff --git a/app/models.py b/app/models.py index 5b8a4694..a7cc77e9 100644 --- a/app/models.py +++ b/app/models.py @@ -853,7 +853,7 @@ class User(HashidMixin, UserMixin, db.Model): json_serializeable = { 'id': self.hashid, 'confirmed': self.confirmed, - 'avatar': url_for('users.user_avatar', user_id=self.id), + # 'avatar': url_for('users.user_avatar', user_id=self.id), 'email': self.email, 'last_seen': ( None if self.last_seen is None diff --git a/app/static/js/ResourceLists/CorpusList.js b/app/static/js/ResourceLists/CorpusList.js index deebb356..985ff1d1 100644 --- a/app/static/js/ResourceLists/CorpusList.js +++ b/app/static/js/ResourceLists/CorpusList.js @@ -225,15 +225,16 @@ class CorpusList extends ResourceList { break; } case 'delete': { + // Saved for future use: + //

Do you really want to unfollow this Corpora?

+ //
    let modalElement = Utils.HTMLToElement( ` @@ -121,7 +121,7 @@ {{ super() }} {% if current_user == corpus.user or current_user.is_administrator() %} -