Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
33a54b62
Commit
33a54b62
authored
2 years ago
by
Inga Kirschnick
Browse files
Options
Downloads
Patches
Plain Diff
Corpus first share link
parent
e03b54cf
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/corpora/routes.py
+33
-2
33 additions, 2 deletions
app/corpora/routes.py
app/templates/corpora/corpus.html.j2
+25
-14
25 additions, 14 deletions
app/templates/corpora/corpus.html.j2
app/templates/corpora/corpus_public.html.j2
+1
-1
1 addition, 1 deletion
app/templates/corpora/corpus_public.html.j2
with
59 additions
and
17 deletions
app/corpora/routes.py
+
33
−
2
View file @
33a54b62
from
datetime
import
datetime
,
timedelta
from
flask
import
(
abort
,
current_app
,
...
...
@@ -11,6 +12,7 @@ from flask import (
)
from
flask_login
import
current_user
,
login_required
from
threading
import
Thread
import
jwt
import
os
from
app
import
db
,
hashids
from
app.models
import
Corpus
,
CorpusFile
,
CorpusStatus
,
CorpusFollowerAssociation
,
User
...
...
@@ -57,6 +59,7 @@ def create_corpus():
@bp.route
(
'
/<hashid:corpus_id>
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@login_required
def
corpus
(
corpus_id
):
print
(
corpus_id
)
corpus
=
Corpus
.
query
.
get_or_404
(
corpus_id
)
if
not
(
corpus
.
user
==
current_user
or
current_user
.
is_administrator
()
...
...
@@ -72,11 +75,23 @@ def corpus(corpus_id):
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
:
return
render_template
(
'
corpora/corpus.html.j2
'
,
corpus_settings_form
=
corpus_settings_form
,
corpus
=
corpus
,
token
=
token
,
title
=
'
Corpus
'
)
else
:
...
...
@@ -88,8 +103,23 @@ def corpus(corpus_id):
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>/update')
# @login_required
# def update_corpus(corpus_id):
...
...
@@ -296,7 +326,7 @@ def follow_corpus(corpus_id):
if
not
user
.
is_following_corpus
(
corpus
):
user
.
follow_corpus
(
corpus
)
db
.
session
.
commit
()
#
flash(
'Hallo Inga Kirschnick
')
flash
(
f
'
You are following
{
corpus
.
title
}
now
'
,
category
=
'
corpus
'
)
return
{},
202
@bp.route
(
'
/<hashid:corpus_id>/unfollow
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
@@ -315,6 +345,7 @@ def unfollow_corpus(corpus_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>
'
)
...
...
This diff is collapsed.
Click to expand it.
app/templates/corpora/corpus.html.j2
+
25
−
14
View file @
33a54b62
...
...
@@ -86,21 +86,13 @@
</div>
{% if current_user.can(Permission.ADMINISTRATE) or current_user.hashid == corpus.user.hashid %}
<div class="col s12">
<form method="POST">
{{ corpus_settings_form.hidden_tag() }}
<div class="card">
<div class="card-content">
<span class="card-title" id="files">Corpus settings</span>
<br>
<p></p>
{{ wtf.render_field(corpus_settings_form.is_public) }}
<br>
</div>
<div class="card-action right-align">
{{ wtf.render_field(corpus_settings_form.submit, material_icon='send') }}
</div>
<div class="card">
<div class="card-content">
<a class="action-button btn waves-effect waves-light" id="generate-share-link-button">Generate Share Link</a>
<div id="share-link"></div>
<a class="action-button btn-small waves-effect waves-light hide" id="copy-share-link-button">Copy</a>
</div>
</
form
>
</
div
>
</div>
{% endif %}
<div class="col s12">
...
...
@@ -119,5 +111,24 @@
{{ super() }}
<script>
let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display'));
let generateShareLinkButton = document.querySelector('#generate-share-link-button');
let copyShareLinkButton = document.querySelector('#copy-share-link-button');
let shareLink = document.querySelector('#share-link');
let linkValue = '{{ url_for('corpora.share_corpus', token=token, _external=True) }}';
generateShareLinkButton.addEventListener('click', () => {
let shareLinkElement = document.createElement('input');
shareLinkElement.value = linkValue;
shareLinkElement.setAttribute('readonly', '');
shareLink.appendChild(shareLinkElement);
copyShareLinkButton.classList.remove('hide');
});
copyShareLinkButton.addEventListener('click', () => {
let shareLinkElement = document.querySelector('#share-link input');
shareLinkElement.select();
document.execCommand('copy');
app.flash(`Copied!`, 'success');
});
</script>
{% endblock scripts %}
This diff is collapsed.
Click to expand it.
app/templates/corpora/corpus_public.html.j2
+
1
−
1
View file @
33a54b62
...
...
@@ -7,7 +7,7 @@
<div class="container">
<div class="row">
<div class="col s12">
<h1>{{ title }} </h1>
<h1>{{
corpus.
title }} </h1>
<div class="row">
<div class="col s8 m9 l10">
<a class="btn waves-effect waves-light" id="follow-corpus-request">
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment