mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 19:04:18 +00:00
Better and more live updated on corpus follower actions
This commit is contained in:
parent
e4593d5922
commit
8c935820e8
@ -1687,20 +1687,26 @@ def ressource_after_delete(mapper, connection, ressource):
|
|||||||
@db.event.listens_for(CorpusFollowerAssociation, 'after_delete')
|
@db.event.listens_for(CorpusFollowerAssociation, 'after_delete')
|
||||||
def corpus_follower_association_after_delete_handler(mapper, connection, ressource):
|
def corpus_follower_association_after_delete_handler(mapper, connection, ressource):
|
||||||
corpus_owner_hashid = ressource.corpus.user.hashid
|
corpus_owner_hashid = ressource.corpus.user.hashid
|
||||||
corpus_hashid = hashids.encode(ressource.corpus_id)
|
corpus_hashid = ressource.corpus.hashid
|
||||||
follower_hashid = hashids.encode(ressource.follower_id)
|
|
||||||
# Send a PATCH to the corpus owner
|
# Send a PATCH to the corpus owner
|
||||||
jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||||
jsonpatch = [{'op': 'remove', 'path': jsonpatch_path}]
|
jsonpatch = [{'op': 'remove', 'path': jsonpatch_path}]
|
||||||
room = f'/users/{corpus_owner_hashid}'
|
room = f'/users/{corpus_owner_hashid}'
|
||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
# Send a PATCH to the follower
|
# Send a PATCH to the followers (the deleted follower and others with permission "MANAGE_FOLLOWERS")
|
||||||
jsonpatch_path = f'/users/{follower_hashid}/corpus_follower_associations/{ressource.hashid}'
|
followers = [
|
||||||
|
x for x in ressource.corpus.corpus_follower_associations
|
||||||
|
if x.follower_id == ressource.follower_id
|
||||||
|
or x.role.has_permission('MANAGE_FOLLOWERS')
|
||||||
|
]
|
||||||
|
for follower in followers:
|
||||||
|
jsonpatch_path = f'/users/{follower.hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||||
jsonpatch = [{'op': 'remove', 'path': jsonpatch_path}]
|
jsonpatch = [{'op': 'remove', 'path': jsonpatch_path}]
|
||||||
room = f'/users/{follower_hashid}'
|
room = f'/users/{follower.hashid}'
|
||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@db.event.listens_for(Corpus, 'after_insert')
|
@db.event.listens_for(Corpus, 'after_insert')
|
||||||
@db.event.listens_for(CorpusFile, 'after_insert')
|
@db.event.listens_for(CorpusFile, 'after_insert')
|
||||||
@db.event.listens_for(Job, 'after_insert')
|
@db.event.listens_for(Job, 'after_insert')
|
||||||
@ -1722,18 +1728,23 @@ def ressource_after_insert_handler(mapper, connection, ressource):
|
|||||||
@db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
|
@db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
|
||||||
def corpus_follower_association_after_insert_handler(mapper, connection, ressource):
|
def corpus_follower_association_after_insert_handler(mapper, connection, ressource):
|
||||||
corpus_owner_hashid = ressource.corpus.user.hashid
|
corpus_owner_hashid = ressource.corpus.user.hashid
|
||||||
corpus_hashid = hashids.encode(ressource.corpus_id)
|
corpus_hashid = ressource.corpus.hashid
|
||||||
follower_hashid = hashids.encode(ressource.follower_id)
|
|
||||||
value = ressource.to_json_serializeable()
|
value = ressource.to_json_serializeable()
|
||||||
# Send a PATCH to the corpus owner
|
# Send a PATCH to the corpus owner
|
||||||
jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||||
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||||
room = f'/users/{corpus_owner_hashid}'
|
room = f'/users/{corpus_owner_hashid}'
|
||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
# Send a PATCH to the follower
|
# Send a PATCH to the followers (the deleted follower and others with permission "MANAGE_FOLLOWERS")
|
||||||
jsonpatch_path = f'/users/{follower_hashid}/corpus_follower_associations/{ressource.hashid}'
|
followers = [
|
||||||
|
x for x in ressource.corpus.corpus_follower_associations
|
||||||
|
if x.follower_id == ressource.follower_id
|
||||||
|
or x.role.has_permission('MANAGE_FOLLOWERS')
|
||||||
|
]
|
||||||
|
for follower in followers:
|
||||||
|
jsonpatch_path = f'/users/{follower.hashid}/corpus_follower_associations/{ressource.hashid}'
|
||||||
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
|
||||||
room = f'/users/{follower_hashid}'
|
room = f'/users/{follower.hashid}'
|
||||||
socketio.emit('PATCH', jsonpatch, room=room)
|
socketio.emit('PATCH', jsonpatch, room=room)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user