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
f4b30433
Commit
f4b30433
authored
1 year ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add back community update code
parent
c2a6b9d7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/corpora/followers/json_routes.py
+58
-58
58 additions, 58 deletions
app/corpora/followers/json_routes.py
app/corpora/routes.py
+8
-9
8 additions, 9 deletions
app/corpora/routes.py
with
66 additions
and
67 deletions
app/corpora/followers/json_routes.py
+
58
−
58
View file @
f4b30433
...
...
@@ -12,65 +12,65 @@ from ..decorators import corpus_follower_permission_required
from
.
import
bp
#
@bp.route('/<hashid:corpus_id>/followers', methods=['POST'])
#
@corpus_follower_permission_required('MANAGE_FOLLOWERS')
#
@content_negotiation(consumes='application/json', produces='application/json')
#
def create_corpus_followers(corpus_id):
#
usernames = request.json
#
if not (isinstance(usernames, list) or all(isinstance(u, str) for u in usernames)):
#
abort(400)
#
corpus = Corpus.query.get_or_404(corpus_id)
#
for username in usernames:
#
user = User.query.filter_by(username=username, is_public=True).first_or_404()
#
user.follow_corpus(corpus)
#
db.session.commit()
#
response_data = {
#
'message': f'Users are now following "{corpus.title}"',
#
'category': 'corpus'
#
}
#
return response_data, 200
@bp.route
(
'
/<hashid:corpus_id>/followers
'
,
methods
=
[
'
POST
'
])
@corpus_follower_permission_required
(
'
MANAGE_FOLLOWERS
'
)
@content_negotiation
(
consumes
=
'
application/json
'
,
produces
=
'
application/json
'
)
def
create_corpus_followers
(
corpus_id
):
usernames
=
request
.
json
if
not
(
isinstance
(
usernames
,
list
)
or
all
(
isinstance
(
u
,
str
)
for
u
in
usernames
)):
abort
(
400
)
corpus
=
Corpus
.
query
.
get_or_404
(
corpus_id
)
for
username
in
usernames
:
user
=
User
.
query
.
filter_by
(
username
=
username
,
is_public
=
True
).
first_or_404
()
user
.
follow_corpus
(
corpus
)
db
.
session
.
commit
()
response_data
=
{
'
message
'
:
f
'
Users are now following
"
{
corpus
.
title
}
"'
,
'
category
'
:
'
corpus
'
}
return
response_data
,
200
#
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['PUT'])
#
@corpus_follower_permission_required('MANAGE_FOLLOWERS')
#
@content_negotiation(consumes='application/json', produces='application/json')
#
def update_corpus_follower_role(corpus_id, follower_id):
#
role_name = request.json
#
if not isinstance(role_name, str):
#
abort(400)
#
cfr = CorpusFollowerRole.query.filter_by(name=role_name).first()
#
if cfr is None:
#
abort(400)
#
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
#
cfa.role = cfr
#
db.session.commit()
#
response_data = {
#
'message': f'User "{cfa.follower.username}" is now {cfa.role.name}',
#
'category': 'corpus'
#
}
#
return response_data, 200
@bp.route
(
'
/<hashid:corpus_id>/followers/<hashid:follower_id>/role
'
,
methods
=
[
'
PUT
'
])
@corpus_follower_permission_required
(
'
MANAGE_FOLLOWERS
'
)
@content_negotiation
(
consumes
=
'
application/json
'
,
produces
=
'
application/json
'
)
def
update_corpus_follower_role
(
corpus_id
,
follower_id
):
role_name
=
request
.
json
if
not
isinstance
(
role_name
,
str
):
abort
(
400
)
cfr
=
CorpusFollowerRole
.
query
.
filter_by
(
name
=
role_name
).
first
()
if
cfr
is
None
:
abort
(
400
)
cfa
=
CorpusFollowerAssociation
.
query
.
filter_by
(
corpus_id
=
corpus_id
,
follower_id
=
follower_id
).
first_or_404
()
cfa
.
role
=
cfr
db
.
session
.
commit
()
response_data
=
{
'
message
'
:
f
'
User
"
{
cfa
.
follower
.
username
}
"
is now
{
cfa
.
role
.
name
}
'
,
'
category
'
:
'
corpus
'
}
return
response_data
,
200
#
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>', methods=['DELETE'])
#
def delete_corpus_follower(corpus_id, follower_id):
#
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
#
if not (
#
current_user.id == follower_id
#
or current_user == cfa.corpus.user
#
or CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first().role.has_permission('MANAGE_FOLLOWERS')
#
or current_user.is_administrator()):
#
abort(403)
#
if current_user.id == follower_id:
#
flash(f'You are no longer following "{cfa.corpus.title}"', 'corpus')
#
response = make_response()
#
response.status_code = 204
#
else:
#
response_data = {
#
'message': f'"{cfa.follower.username}" is not following "{cfa.corpus.title}" anymore',
#
'category': 'corpus'
#
}
#
response = jsonify(response_data)
#
response.status_code = 200
#
cfa.follower.unfollow_corpus(cfa.corpus)
#
db.session.commit()
#
return response
@bp.route
(
'
/<hashid:corpus_id>/followers/<hashid:follower_id>
'
,
methods
=
[
'
DELETE
'
])
def
delete_corpus_follower
(
corpus_id
,
follower_id
):
cfa
=
CorpusFollowerAssociation
.
query
.
filter_by
(
corpus_id
=
corpus_id
,
follower_id
=
follower_id
).
first_or_404
()
if
not
(
current_user
.
id
==
follower_id
or
current_user
==
cfa
.
corpus
.
user
or
CorpusFollowerAssociation
.
query
.
filter_by
(
corpus_id
=
corpus_id
,
follower_id
=
current_user
.
id
).
first
().
role
.
has_permission
(
'
MANAGE_FOLLOWERS
'
)
or
current_user
.
is_administrator
()):
abort
(
403
)
if
current_user
.
id
==
follower_id
:
flash
(
f
'
You are no longer following
"
{
cfa
.
corpus
.
title
}
"'
,
'
corpus
'
)
response
=
make_response
()
response
.
status_code
=
204
else
:
response_data
=
{
'
message
'
:
f
'"
{
cfa
.
follower
.
username
}
"
is not following
"
{
cfa
.
corpus
.
title
}
"
anymore
'
,
'
category
'
:
'
corpus
'
}
response
=
jsonify
(
response_data
)
response
.
status_code
=
200
cfa
.
follower
.
unfollow_corpus
(
cfa
.
corpus
)
db
.
session
.
commit
()
return
response
This diff is collapsed.
Click to expand it.
app/corpora/routes.py
+
8
−
9
View file @
f4b30433
...
...
@@ -71,7 +71,6 @@ def corpus(corpus_id):
users
=
users
)
if
(
current_user
.
is_following_corpus
(
corpus
)
or
corpus
.
is_public
):
abort
(
403
)
cfas
=
CorpusFollowerAssociation
.
query
.
filter
(
Corpus
.
id
==
corpus_id
,
CorpusFollowerAssociation
.
follower_id
!=
corpus
.
user
.
id
).
all
()
print
(
cfas
)
return
render_template
(
...
...
@@ -99,14 +98,14 @@ def analysis(corpus_id):
)
#
@bp.route('/<hashid:corpus_id>/follow/<token>')
#
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')
#
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
#
abort(403)
@bp.route
(
'
/<hashid:corpus_id>/follow/<token>
'
)
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
'
)
return
redirect
(
url_for
(
'
corpora.corpus
'
,
corpus_id
=
corpus_id
))
abort
(
403
)
@bp.route
(
'
/import
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
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