mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-11 16:40:40 +00:00
Remove public share mechanisms until legal matters are clarified
This commit is contained in:
@ -78,9 +78,6 @@ class UpdateCorpusFileForm(CorpusFileBaseForm):
|
||||
kwargs['prefix'] = 'update-corpus-file-form'
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
class ChangeCorpusSettingsForm(FlaskForm):
|
||||
is_public = BooleanField('Public Corpus')
|
||||
submit = SubmitField()
|
||||
|
||||
class ImportCorpusForm(FlaskForm):
|
||||
pass
|
||||
|
@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from flask import (
|
||||
abort,
|
||||
current_app,
|
||||
@ -15,19 +15,121 @@ from threading import Thread
|
||||
import jwt
|
||||
import os
|
||||
from app import db, hashids
|
||||
from app.models import Corpus, CorpusFile, CorpusStatus, CorpusFollowerAssociation, User
|
||||
from app.models import Corpus, CorpusFile, CorpusStatus, User
|
||||
from . import bp
|
||||
from .forms import ChangeCorpusSettingsForm, CreateCorpusFileForm, CreateCorpusForm, UpdateCorpusFileForm
|
||||
from .forms import (
|
||||
CreateCorpusFileForm,
|
||||
CreateCorpusForm,
|
||||
UpdateCorpusFileForm
|
||||
)
|
||||
|
||||
|
||||
@bp.route('')
|
||||
# @bp.route('/share/<token>', methods=['GET', 'POST'])
|
||||
# def share_corpus(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>/enable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def corpora():
|
||||
query = Corpus.query.filter(
|
||||
(Corpus.user_id == current_user.id) | (Corpus.is_public == True)
|
||||
def enable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = True
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/disable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def disable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = False
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
||||
|
||||
# @bp.route('/<hashid:corpus_id>/follow', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def follow_corpus(corpus_id):
|
||||
# corpus = Corpus.query.get_or_404(corpus_id)
|
||||
# user_hashid = request.args.get('user_id')
|
||||
# if user_hashid is None:
|
||||
# user = current_user
|
||||
# else:
|
||||
# if not current_user.is_administrator():
|
||||
# abort(403)
|
||||
# else:
|
||||
# user_id = hashids.decode(user_hashid)
|
||||
# user = User.query.get_or_404(user_id)
|
||||
# if not user.is_following_corpus(corpus):
|
||||
# user.follow_corpus(corpus)
|
||||
# db.session.commit()
|
||||
# flash(f'You are following {corpus.title} now', category='corpus')
|
||||
# return {}, 202
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/unfollow', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def unfollow_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
user_hashid = request.args.get('user_id')
|
||||
if user_hashid is None:
|
||||
user = current_user
|
||||
elif current_user.is_administrator():
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get_or_404(user_id)
|
||||
else:
|
||||
abort(403)
|
||||
if user.is_following_corpus(corpus):
|
||||
user.unfollow_corpus(corpus)
|
||||
db.session.commit()
|
||||
flash(f'You are not following {corpus.title} anymore', category='corpus')
|
||||
return {}, 202
|
||||
|
||||
|
||||
# @bp.route('/add_permission/<hashid:corpus_id>/<hashid:user_id>/<int:permission>')
|
||||
# def add_permission(corpus_id, user_id, permission):
|
||||
# a = CorpusFollowerAssociation.query.filter_by(followed_corpus_id=corpus_id, following_user_id=user_id).first_or_404()
|
||||
# a.add_permission(permission)
|
||||
# db.session.commit()
|
||||
# return 'ok'
|
||||
|
||||
|
||||
# @bp.route('/remove_permission/<hashid:corpus_id>/<hashid:user_id>/<int:permission>')
|
||||
# def remove_permission(corpus_id, user_id, permission):
|
||||
# a = CorpusFollowerAssociation.query.filter_by(followed_corpus_id=corpus_id, following_user_id=user_id).first_or_404()
|
||||
# a.remove_permission(permission)
|
||||
# db.session.commit()
|
||||
# return 'ok'
|
||||
|
||||
|
||||
@bp.route('/public')
|
||||
@login_required
|
||||
def public_corpora():
|
||||
corpora = [
|
||||
c.to_json_serializeable()
|
||||
for c in Corpus.query.filter(Corpus.is_public == True).all()
|
||||
]
|
||||
return render_template(
|
||||
'corpora/public_corpora.html.j2',
|
||||
corpora=corpora,
|
||||
title='Corpora'
|
||||
)
|
||||
corpora = [c.to_json_serializeable() for c in query.all()]
|
||||
return render_template('corpora/corpora.html.j2', corpora=corpora, title='Corpora')
|
||||
|
||||
|
||||
@bp.route('/create', methods=['GET', 'POST'])
|
||||
@ -60,83 +162,33 @@ def create_corpus():
|
||||
@login_required
|
||||
def corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user
|
||||
or current_user.is_administrator()
|
||||
or current_user.is_following_corpus(corpus)
|
||||
or corpus.is_public):
|
||||
abort(403)
|
||||
corpus_settings_form = ChangeCorpusSettingsForm(
|
||||
data=corpus.to_json_serializeable(),
|
||||
prefix='corpus-settings-form'
|
||||
)
|
||||
if corpus_settings_form.validate_on_submit():
|
||||
corpus.is_public = corpus_settings_form.is_public.data
|
||||
db.session.commit()
|
||||
flash('Your changes have been saved')
|
||||
return redirect(url_for('.corpus', corpus_id=corpus.id))
|
||||
now = datetime.utcnow()
|
||||
payload = {
|
||||
'iat': now,
|
||||
'iss': current_app.config['SERVER_NAME'],
|
||||
'sub': corpus.hashid
|
||||
}
|
||||
token = jwt.encode(
|
||||
payload,
|
||||
current_app.config['SECRET_KEY'],
|
||||
algorithm='HS256'
|
||||
)
|
||||
if corpus.user == current_user:
|
||||
if corpus.user == current_user or current_user.is_administrator():
|
||||
# now = datetime.utcnow()
|
||||
# payload = {
|
||||
# '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,
|
||||
# token=token,
|
||||
title='Corpus'
|
||||
)
|
||||
else:
|
||||
if current_user.is_following_corpus(corpus) or corpus.is_public:
|
||||
corpus_files = [x.to_json_serializeable() for x in corpus.files]
|
||||
return render_template(
|
||||
'corpora/corpus_public.html.j2',
|
||||
'corpora/public_corpus.html.j2',
|
||||
corpus=corpus,
|
||||
corpus_files=corpus_files,
|
||||
title='Corpus'
|
||||
)
|
||||
|
||||
@bp.route('/share/<token>', methods=['GET', 'POST'])
|
||||
def share_corpus(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>/enable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def enable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = True
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/disable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def disable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = False
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
abort(403)
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
||||
@ -165,8 +217,7 @@ def analyse_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user
|
||||
or current_user.is_administrator()
|
||||
or current_user.is_following_corpus(corpus)
|
||||
or corpus.is_public):
|
||||
or current_user.is_following_corpus(corpus)):
|
||||
abort(403)
|
||||
return render_template(
|
||||
'corpora/analyse_corpus.html.j2',
|
||||
@ -315,57 +366,3 @@ def import_corpus():
|
||||
@login_required
|
||||
def export_corpus(corpus_id):
|
||||
abort(503)
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/follow', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def follow_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
user_hashid = request.args.get('user_id')
|
||||
if user_hashid is None:
|
||||
user = current_user
|
||||
else:
|
||||
if not current_user.is_administrator():
|
||||
abort(403)
|
||||
else:
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get_or_404(user_id)
|
||||
if not user.is_following_corpus(corpus):
|
||||
user.follow_corpus(corpus)
|
||||
db.session.commit()
|
||||
flash(f'You are following {corpus.title} now', category='corpus')
|
||||
return {}, 202
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/unfollow', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def unfollow_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
user_hashid = request.args.get('user_id')
|
||||
if user_hashid is None:
|
||||
user = current_user
|
||||
else:
|
||||
if not current_user.is_administrator():
|
||||
abort(403)
|
||||
else:
|
||||
user_id = hashids.decode(user_hashid)
|
||||
user = User.query.get_or_404(user_id)
|
||||
if user.is_following_corpus(corpus):
|
||||
user.unfollow_corpus(corpus)
|
||||
db.session.commit()
|
||||
flash(f'You are not following {corpus.title} anymore', category='corpus')
|
||||
return {}, 202
|
||||
|
||||
@bp.route('/add_permission/<hashid:corpus_id>/<hashid:user_id>/<int:permission>')
|
||||
def add_permission(corpus_id, user_id, permission):
|
||||
a = CorpusFollowerAssociation.query.filter_by(followed_corpus_id=corpus_id, following_user_id=user_id).first_or_404()
|
||||
a.add_permission(permission)
|
||||
db.session.commit()
|
||||
return 'ok'
|
||||
|
||||
|
||||
@bp.route('/remove_permission/<hashid:corpus_id>/<hashid:user_id>/<int:permission>')
|
||||
def remove_permission(corpus_id, user_id, permission):
|
||||
a = CorpusFollowerAssociation.query.filter_by(followed_corpus_id=corpus_id, following_user_id=user_id).first_or_404()
|
||||
a.remove_permission(permission)
|
||||
db.session.commit()
|
||||
return 'ok'
|
||||
|
||||
|
Reference in New Issue
Block a user