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

[QUAD] Enhancement: Add ftrack user action to deactivate invalid projects #6328

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Copy link

Choose a reason for hiding this comment

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

line too long (105 > 79 characters)

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.