Activity logging for shots

This commit is contained in:
2016-10-12 15:22:18 +02:00
parent 5dff6bdcbd
commit 2842201974
3 changed files with 64 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
import logging
from attract.node_types.shot import node_type_shot
from pillar.api.nodes import only_for_node_type_decorator
import pillar.api.activities
import pillar.api.utils.authentication
log = logging.getLogger(__name__)
only_for_shot = only_for_node_type_decorator(node_type_shot['name'])
def register_shot_activity(shot, descr):
user_id = pillar.api.utils.authentication.current_user_id()
pillar.api.activities.register_activity(
user_id,
descr,
'node', shot['_id'],
'project', shot['project'],
shot['project'],
node_type=shot['node_type'],
)
@only_for_shot
def activity_after_replacing_shot(shot, original):
"""
Note: this is also used on PATCH, since our custom shot PATCH handler
performs a PUT-internal to run the patched node through Eve for
validation.
"""
# TODO: compare to original, and either mention the things that changed,
# or (if they are equal) don't log an activity at all.
register_shot_activity(shot, 'edited shot "%s"' % shot['name'])
@only_for_shot
def activity_after_creating_shot(shot):
register_shot_activity(shot, 'created a new shot "%s"' % shot['name'])
def activity_after_creating_shots(nodes):
for node in nodes:
activity_after_creating_shot(node)
@only_for_shot
def activity_after_deleting_shot(shot):
register_shot_activity(shot, 'deleted shot "%s"' % shot['name'])
def setup_app(app):
app.on_replaced_nodes += activity_after_replacing_shot
app.on_inserted_nodes += activity_after_creating_shots
app.on_deleted_item_nodes += activity_after_deleting_shot
app.on_deleted_resource_nodes += activity_after_deleting_shot