From fecbb50d390fa763df85fd82bec5ed0605dc4c08 Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Mon, 6 Mar 2023 12:27:24 +0100 Subject: [PATCH] bug fixes and unfollow_corpus update --- app/corpora/routes.py | 22 +++++-------------- .../analyse_corpus.concordance.html.j2 | 2 ++ app/templates/corpora/analyse_corpus.html.j2 | 6 +++++ app/templates/corpora/corpus.html.j2 | 2 +- app/templates/corpora/public_corpus.html.j2 | 2 +- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/corpora/routes.py b/app/corpora/routes.py index a487e834..4a63a03a 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -15,7 +15,7 @@ from flask_login import current_user, login_required from threading import Thread import os from .decorators import corpus_follower_permission_required, corpus_owner_or_admin_required -from app import db +from app import db, hashids from app.models import ( Corpus, CorpusFile, @@ -76,6 +76,7 @@ def add_corpus_followers(corpus_id): @bp.route('//follow/') @login_required 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') @@ -98,20 +99,8 @@ def unfollow_corpus(corpus_id, follower_id): return '', 204 -@bp.route('//unfollow', methods=['POST']) -@login_required -def current_user_unfollow_corpus(corpus_id): - corpus = Corpus.query.get_or_404(corpus_id) - if not current_user.is_following_corpus(corpus): - abort(409) # 'You are not following the corpus' - current_user.unfollow_corpus(corpus) - db.session.commit() - flash(f'You are not following {corpus.title} anymore', category='corpus') - return '', 204 - - @bp.route('//followers//role', methods=['POST']) -@corpus_follower_permission_required('REMOVE_FOLLOWER', 'UPDATE_FOLLOWER') +@corpus_follower_permission_required('UPDATE_FOLLOWER') def add_permission(corpus_id, follower_id): corpus_follower_association = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404() if not (corpus_follower_association.corpus.user == current_user or current_user.is_administrator()): @@ -196,11 +185,12 @@ def corpus(corpus_id): @login_required @corpus_follower_permission_required('GENERATE_SHARE_LINK') def generate_corpus_share_link(corpus_id): + corpus_hashid = hashids.encode(corpus_id) data = request.get_json('data') - role = data['role'] + role_name = data['role'] exp_data = data['expiration'] expiration = datetime.strptime(exp_data, '%b %d, %Y') - token = current_user.generate_follow_corpus_token(corpus_id, role, expiration) + token = current_user.generate_follow_corpus_token(corpus_hashid, role_name, expiration) link = url_for('corpora.follow_corpus', corpus_id=corpus_id, token=token, _external=True) return link diff --git a/app/templates/corpora/analyse_corpus.concordance.html.j2 b/app/templates/corpora/analyse_corpus.concordance.html.j2 index 56baf07d..15682431 100644 --- a/app/templates/corpora/analyse_corpus.concordance.html.j2 +++ b/app/templates/corpora/analyse_corpus.concordance.html.j2 @@ -12,6 +12,8 @@ help Corpus Query Language tutorial | info Tagsets + | + info Examples
arrow_forward diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 69bcfd6e..5abd96df 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -245,6 +245,12 @@
+ +