Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Enhancement: Add ftrack user action to deactivate invalid projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyprien CAILLOT committed Sep 11, 2024
1 parent d9731d0 commit 3ab0856
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from pymongo import UpdateOne

from openpype.client import get_projects
from openpype.pipeline import AvalonMongoDB
from openpype_modules.ftrack.lib import BaseAction, statics_icon


class DeactivateObsoleteProjects(BaseAction):
"""Deactivate projects on OP that no longer exist on Ftrack
or that doesn't have an FtrackId
"""

identifier = "deactivate.obsolete.projects"
show_identifier = "deactivate.obsolete.projects"
label = "OpenPype Admin"
variant = "- Deactivate Obsolete Projects"
description = "Deactivate projects on OP that no longer exist on Ftrack or have an invalid FtrackId."
icon = statics_icon("ftrack", "action_icons", "HideProjects.svg")

def __init__(self, session):
self.dbcon = AvalonMongoDB()
super().__init__(session)

def _discover(self, _event):
return {
"items": [{
"label": self.label,
"variant": self.variant,
"description": self.description,
"actionIdentifier": self.discover_identifier,
"icon": self.icon,
}]
}

def _launch(self, event):
self.trigger_action(self.show_identifier, event)

def register(self):
# Register default action callbacks
super(DeactivateObsoleteProjects, self).register()

# # Add show identifier
show_subscription = (
"topic=ftrack.action.launch"
" and data.actionIdentifier={}"
" and source.user.username={}"
).format(
self.show_identifier,
self.session.api_user
)
self.session.event_hub.subscribe(
show_subscription,
self.deactivate_obsolete_projects
)

def deactivate_obsolete_projects(self, event):
ftrack_projects = self.session.query("Project").all()
ftrack_projects_ids = [project["id"] for project in ftrack_projects]
mongo_projects = get_projects()

projects_to_deactivate = []
for project in mongo_projects:
if "ftrackId" not in project["data"].keys():
projects_to_deactivate.append(project)
elif project["data"]["ftrackId"] not in ftrack_projects_ids:
projects_to_deactivate.append(project)

for project in projects_to_deactivate:
filter_dict = {"_id": project["_id"]}
change_data = {"$set": {"data.active": False}}
self.dbcon.Session["AVALON_PROJECT"] = project["name"]
self.dbcon.bulk_write([UpdateOne(filter_dict, change_data)])
self.log.debug(f"No FtrackId for project {project['name']}"
" or project deleted from Ftrack."
" Project has been deactivated.")


def register(session):
DeactivateObsoleteProjects(session).register()
1 change: 1 addition & 0 deletions openpype/resources/ftrack/action_icons/HideProjects.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3ab0856

Please sign in to comment.