mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Update User Card and Share link with specific role
This commit is contained in:
parent
17ec3e292a
commit
e2ddbf26f1
@ -68,11 +68,12 @@ def disable_corpus_is_public(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)
|
||||
corpus = current_user.verify_follow_corpus_token(token)['corpus']
|
||||
role = current_user.verify_follow_corpus_token(token)['role']
|
||||
if not (current_user.is_authenticated and current_user.verify_follow_corpus_token(token)):
|
||||
abort(403)
|
||||
if not current_user.is_following_corpus(corpus) and current_user != corpus.user:
|
||||
current_user.follow_corpus(corpus)
|
||||
current_user.follow_corpus(corpus, role)
|
||||
db.session.commit()
|
||||
flash(f'You are following {corpus.title} now', category='corpus')
|
||||
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
||||
@ -164,20 +165,24 @@ def create_corpus():
|
||||
def corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
exp_date = (datetime.utcnow() + timedelta(days=7)).strftime('%b %d, %Y')
|
||||
roles = [x.name for x in CorpusFollowerRole.query.all()]
|
||||
if corpus.user == current_user or current_user.is_administrator():
|
||||
return render_template(
|
||||
'corpora/corpus.html.j2',
|
||||
corpus=corpus,
|
||||
exp_date=exp_date,
|
||||
roles=roles,
|
||||
title='Corpus'
|
||||
)
|
||||
if current_user.is_following_corpus(corpus) or corpus.is_public:
|
||||
corpus_files = [x.to_json_serializeable() for x in corpus.files]
|
||||
owner = corpus.user.to_json_serializeable()
|
||||
return render_template(
|
||||
'corpora/public_corpus.html.j2',
|
||||
corpus=corpus,
|
||||
corpus_files=corpus_files,
|
||||
title='Corpus'
|
||||
owner=owner,
|
||||
title='Corpus',
|
||||
)
|
||||
abort(403)
|
||||
|
||||
@ -185,10 +190,10 @@ def corpus(corpus_id):
|
||||
@login_required
|
||||
def generate_corpus_share_link(corpus_id):
|
||||
data = request.get_json('data')
|
||||
# permission = data['permission']
|
||||
role = data['role']
|
||||
exp_data = data['expiration']
|
||||
expiration = datetime.strptime(exp_data, '%b %d, %Y')
|
||||
token = current_user.generate_follow_corpus_token(corpus_id, expiration)
|
||||
token = current_user.generate_follow_corpus_token(corpus_id, role, expiration)
|
||||
link = url_for('corpora.follow_corpus', corpus_id=corpus_id, token=token, _external=True)
|
||||
return link
|
||||
|
||||
|
@ -789,13 +789,14 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
def is_following_corpus(self, corpus):
|
||||
return corpus in self.followed_corpora
|
||||
|
||||
def generate_follow_corpus_token(self, corpus_id, expiration=7):
|
||||
def generate_follow_corpus_token(self, corpus_id, role, expiration=7):
|
||||
now = datetime.utcnow()
|
||||
payload = {
|
||||
'exp': expiration,
|
||||
'iat': now,
|
||||
'iss': current_app.config['SERVER_NAME'],
|
||||
'sub': corpus_id
|
||||
'sub': corpus_id,
|
||||
'role': role
|
||||
}
|
||||
return jwt.encode(
|
||||
payload,
|
||||
@ -816,9 +817,10 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
return False
|
||||
corpus_id = payload.get('sub')
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
role = CorpusFollowerRole.query.filter_by(name=payload.get('role')).first()
|
||||
if corpus is None:
|
||||
return False
|
||||
return True
|
||||
return {'corpus': corpus, 'role': role}
|
||||
|
||||
def to_json_serializeable(self, backrefs=False, relationships=False, filter_by_privacy_settings=False):
|
||||
json_serializeable = {
|
||||
|
@ -124,13 +124,12 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
let copyShareLinkButton = this.displayElement.querySelector('#copy-share-link-button');
|
||||
let shareLinkInput = this.displayElement.querySelector('#share-link-input');
|
||||
let shareLinkContainer = this.displayElement.querySelector('#share-link-container');
|
||||
// let permissionSelect = this.displayElement.querySelector('#permission-select');
|
||||
let roleSelect = this.displayElement.querySelector('#role-select');
|
||||
let expirationDate = this.displayElement.querySelector('#expiration');
|
||||
|
||||
|
||||
generateShareLinkButton.addEventListener('click', () => {
|
||||
// Utils.generateCorpusShareLinkRequest(`${this.corpusId}`, permissionSelect.value, expirationDate.value)
|
||||
Utils.generateCorpusShareLinkRequest(`${this.corpusId}`, expirationDate.value)
|
||||
Utils.generateCorpusShareLinkRequest(`${this.corpusId}`, roleSelect.value, expirationDate.value)
|
||||
.then((shareLink) => {
|
||||
shareLinkContainer.classList.remove('hide');
|
||||
shareLinkInput.value = shareLink;
|
||||
|
@ -757,11 +757,9 @@ class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
// static generateCorpusShareLinkRequest(corpusId, permission, expiration) {
|
||||
static generateCorpusShareLinkRequest(corpusId, expiration) {
|
||||
static generateCorpusShareLinkRequest(corpusId, role, expiration) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// const data = {permission: permission, expiration: expiration};
|
||||
const data = {expiration: expiration};
|
||||
const data = {role: role, expiration: expiration};
|
||||
fetch(`/corpora/${corpusId}/generate-corpus-share-link`, {method: 'POST', headers: {Accept: 'text/plain'}, body: JSON.stringify(data)})
|
||||
.then(
|
||||
(response) => {
|
||||
|
@ -96,18 +96,18 @@
|
||||
</div>
|
||||
<br>
|
||||
<p></p>
|
||||
{# <div class="row">
|
||||
<div class="row">
|
||||
<div class="col s4">
|
||||
<div class="input-field">
|
||||
<select id="permission-select">
|
||||
<option value="view" selected>View</option>
|
||||
<option value="contribute">Contribute</option>
|
||||
<option value="administrate">Administrate</option>
|
||||
<select id="role-select">
|
||||
{% for role in roles%}
|
||||
<option value="{{role}}">{{role}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<label>Permission</label>
|
||||
<label>Role</label>
|
||||
</div>
|
||||
</div>
|
||||
</div> #}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col s4">
|
||||
<div class="input-field">
|
||||
|
@ -11,7 +11,7 @@
|
||||
<div class="row">
|
||||
<div class="col s8 m9 l10">
|
||||
{% if current_user.is_following_corpus(corpus) %}
|
||||
<a class="action-button btn waves-effect waves-light" data-action="unfollow-request"><i class="material-icons left">add</i>Unfollow Corpus</a>
|
||||
<a class="action-button btn waves-effect waves-light" data-action="unfollow-request"><i class="material-icons left outlined">close</i>Unfollow Corpus</a>
|
||||
{% endif %}
|
||||
{% if corpus.status.name in ['BUILT', 'STARTING_ANALYSIS_SESSION', 'RUNNING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'] and current_user.is_following_corpus(corpus) %}
|
||||
<a class="btn waves-effect waves-light" href="{{ url_for('corpora.analyse_corpus', corpus_id=corpus.id) }}">Analyze</a>
|
||||
@ -42,10 +42,50 @@
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<span class="card-title" id="files">Corpus files</span>
|
||||
<div class="corpus-file-list no-autoinit" data-user-id="{{ corpus.user.hashid }}" data-corpus-id="{{ corpus.hashid }}"></div>
|
||||
<span class="card-title" id="files">Corpus Owner</span>
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:10%; margin-top:25px;">
|
||||
{% if corpus.user.avatar %}
|
||||
<img src="{{ url_for('users.profile_avatar', user_id=corpus.user.id) }}" alt="user-image" class="circle responsive-img">
|
||||
{% else %}
|
||||
<img src="{{ url_for('static', filename='images/user_avatar.png') }}" alt="user-image" class="circle responsive-img">
|
||||
{% endif %}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<ul>
|
||||
<li><b>{{ owner.username }}</b></li>
|
||||
{% if owner.full_name %}
|
||||
<li>{{ owner.full_name }}</li>
|
||||
{% endif %}
|
||||
{% if owner.show_email %}
|
||||
<li></li><a href="mailto:{{ owner.email }}">{{ owner.email }}</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% if not current_user.is_following_corpus(corpus) %}
|
||||
<br>
|
||||
<p></p>
|
||||
<a class="waves-effect waves-light btn-small">Request Corpus</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if current_user.is_following_corpus(corpus)%}
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<span class="card-title" id="files">Corpus files</span>
|
||||
<div class="corpus-file-list no-autoinit" data-user-id="{{ owner.hashid }}" data-corpus-id="{{ corpus.hashid }}"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user