Skip to content
28 changes: 28 additions & 0 deletions ayon_server/activities/event_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ def install(cls, event_stream: type["EventStream"]):
"""
cls.topics = {
"entity.folder.status_changed": cls.handle_status_changed,
"entity.folder.attrib_changed": cls.handle_attrib_changed,
"entity.task.status_changed": cls.handle_status_changed,
"entity.task.attrib_changed": cls.handle_attrib_changed,
"entity.version.status_changed": cls.handle_status_changed,
"entity.version.attrib_changed": cls.handle_attrib_changed,
"entity.product.status_changed": cls.handle_status_changed,
"entity.product.attrib_changed": cls.handle_attrib_changed,
"entity.task.assignees_changed": cls.handle_assignees_changed,
"entity.version.created": cls.handle_version_created,
}
Expand Down Expand Up @@ -75,6 +79,30 @@ async def handle_status_changed(cls, event: "EventModel"):
},
)

@classmethod
async def handle_attrib_changed(cls, event: "EventModel"):
entity_type = event.topic.split(".")[1]
entity_class = get_entity_class(entity_type)
assert event.project is not None, "Project is required for activities"
entity = await entity_class.load(event.project, event.summary["entityId"])

old_value = event.payload.get("oldValue")
new_value = event.payload.get("newValue")

origin_link = f"[{entity.name}]({entity_type}:{entity.id})"
body = f"{origin_link} attrib changed from {old_value} to {new_value}"

await create_activity(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to assignee activities, split the event to individual attributes, throw away calculated attributes (available since #995 ) and create an activity for each attribute. with data like:

{
   "key": "priority",
   "oldValue": "low",
   "newValue": "high",
}

(i'd use generic name "key" rather than "attrib" or "attrib name" since we can then add a simple index that will cover data->'key' that could be useful for more activity types)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated according to the comments

entity,
activity_type="attrib.change",
body=body,
user_name=event.user,
data={
"oldValue": old_value,
"newValue": new_value,
},
)

@classmethod
async def handle_assignees_changed(cls, event: "EventModel"):
assert event.project is not None
Expand Down
1 change: 1 addition & 0 deletions ayon_server/activities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"assignee.remove",
"version.publish",
"version.review",
"attrib.change",
]

ActivityReferenceType = Literal[
Expand Down