mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-11 16:40:40 +00:00
Merge branch 'public-corpus' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into public-corpus
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from flask import (
|
||||
abort,
|
||||
current_app,
|
||||
@ -8,7 +8,8 @@ from flask import (
|
||||
redirect,
|
||||
render_template,
|
||||
request,
|
||||
send_from_directory
|
||||
send_from_directory,
|
||||
url_for
|
||||
)
|
||||
from flask_login import current_user, login_required
|
||||
from threading import Thread
|
||||
@ -63,22 +64,20 @@ def disable_corpus_is_public(corpus_id):
|
||||
return '', 204
|
||||
|
||||
|
||||
# @bp.route('/<hashid:corpus_id>/follow/<token>')
|
||||
# @login_required
|
||||
# def follow_corpus(corpus_id, token):
|
||||
# try:
|
||||
# payload = jwt.decode(
|
||||
# token,
|
||||
# current_app.config['SECRET_KEY'],
|
||||
# algorithms=['HS256'],
|
||||
# issuer=current_app.config['SERVER_NAME'],
|
||||
# options={'require': ['iat', 'iss', 'sub']}
|
||||
# )
|
||||
# except jwt.PyJWTError:
|
||||
# return False
|
||||
# corpus_hashid = payload.get('sub')
|
||||
# corpus_id = hashids.decode(corpus_hashid)
|
||||
# return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
@bp.route('/<hashid:corpus_id>/follow/<token>')
|
||||
@login_required
|
||||
def follow_corpus(corpus_id, token):
|
||||
try:
|
||||
payload = jwt.decode(
|
||||
token,
|
||||
current_app.config['SECRET_KEY'],
|
||||
algorithms=['HS256'],
|
||||
issuer=current_app.config['SERVER_NAME'],
|
||||
options={'require': ['iat', 'iss', 'sub']}
|
||||
)
|
||||
except jwt.PyJWTError:
|
||||
return False
|
||||
return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/unfollow', methods=['POST'])
|
||||
@ -176,27 +175,16 @@ def create_corpus():
|
||||
)
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>', methods=['GET', 'POST'])
|
||||
@bp.route('/<hashid:corpus_id>')
|
||||
@login_required
|
||||
def corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
exp_date = (datetime.utcnow() + timedelta(days=7)).strftime('%b %d, %Y')
|
||||
if corpus.user == current_user or current_user.is_administrator():
|
||||
# now = datetime.utcnow()
|
||||
# payload = {
|
||||
# 'exp': now + timedelta(weeks=1),
|
||||
# 'iat': now,
|
||||
# 'iss': current_app.config['SERVER_NAME'],
|
||||
# 'sub': corpus.hashid
|
||||
# }
|
||||
# token = jwt.encode(
|
||||
# payload,
|
||||
# current_app.config['SECRET_KEY'],
|
||||
# algorithm='HS256'
|
||||
# )
|
||||
return render_template(
|
||||
'corpora/corpus.html.j2',
|
||||
corpus=corpus,
|
||||
# token=token,
|
||||
exp_date=exp_date,
|
||||
title='Corpus'
|
||||
)
|
||||
if current_user.is_following_corpus(corpus) or corpus.is_public:
|
||||
@ -209,6 +197,28 @@ def corpus(corpus_id):
|
||||
)
|
||||
abort(403)
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/generate-corpus-share-link', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def generate_corpus_share_link(corpus_id):
|
||||
data = request.get_json('data')
|
||||
permission = data['permission']
|
||||
expiration = data['expiration']
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
now = datetime.utcnow()
|
||||
payload = {
|
||||
'exp': expiration,
|
||||
'iat': now,
|
||||
'iss': current_app.config['SERVER_NAME'],
|
||||
'sub': permission
|
||||
}
|
||||
token = jwt.encode(
|
||||
payload,
|
||||
current_app.config['SECRET_KEY'],
|
||||
algorithm='HS256'
|
||||
)
|
||||
link = url_for('corpora.follow_corpus', corpus_id=corpus_id, token=token, _external=True)
|
||||
return link
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
||||
@login_required
|
||||
|
Reference in New Issue
Block a user