Merge branch 'public-corpus' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into public-corpus

This commit is contained in:
Patrick Jentsch 2023-03-06 15:04:11 +01:00
commit cb830a6f9b
5 changed files with 16 additions and 18 deletions

View File

@ -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,
@ -67,6 +67,7 @@ def add_corpus_followers(corpus_id):
@bp.route('/<hashid:corpus_id>/follow/<token>')
@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')
@ -89,20 +90,8 @@ def unfollow_corpus(corpus_id, follower_id):
return '', 204
@bp.route('/<hashid:corpus_id>/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('/<hashid:corpus_id>/followers/<hashid:follower_id>/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()):
@ -187,11 +176,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

View File

@ -12,6 +12,8 @@
<a class="modal-trigger" href="#cql-tutorial-modal" style="margin-left: 40px;"><i class="material-icons" style="font-size: inherit;">help</i> Corpus Query Language tutorial</a>
<span> | </span>
<a class="modal-trigger" href="#tagsets-modal"><i class="material-icons" style="font-size: inherit;">info</i> Tagsets</a>
<span> | </span>
<a class="modal-trigger" href="#example-modal"><i class="material-icons" style="font-size: inherit;">info</i> Examples</a>
</div>
<div class="input-field col s12 m3">
<i class="material-icons prefix">arrow_forward</i>

View File

@ -245,6 +245,12 @@
</div>
</div>
<div class="modal" id="example-modal">
<div class="modal-content">
<h4>Examples</h4>
</div>
</div>
<div class="modal" id="concordance-query-builder">
<div class="modal-content">
<div>

View File

@ -166,7 +166,7 @@
<i class="material-icons prefix">badge</i>
<select id="share-link-modal-corpus-follower-role-select">
{% for corpus_follower_role in corpus_follower_roles %}
<option value="{{ corpus_follower_role.hashid }}">{{ corpus_follower_role.name }}</option>
<option value="{{ corpus_follower_role.name }}">{{ corpus_follower_role.name }}</option>
{% endfor %}
</select>
<label>Role</label>

View File

@ -111,7 +111,7 @@
let unfollowRequestElement = document.querySelector('.action-button[data-action="unfollow-request"]');
unfollowRequestElement.addEventListener('click', () => {
return new Promise((resolve, reject) => {
fetch('{{ url_for("corpora.current_user_unfollow_corpus", corpus_id=corpus.id) }}', {method: 'POST', headers: {Accept: 'application/json'}})
fetch('{{ url_for("corpora.unfollow_corpus", corpus_id=corpus.id, follower_id=current_user.id) }}', {method: 'POST', headers: {Accept: 'application/json'}})
.then(
(response) => {
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}