This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
[QUAD] Enhancement: Add ftrack user action to deactivate invalid projects #6328
Open
ccaillot
wants to merge
2
commits into
ynput:develop
Choose a base branch
from
quadproduction:enhancement/add_ftrack_user_action_to_deactivate_invalid_projects
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
openpype/modules/ftrack/event_handlers_user/action_deactivate_obsolete_projects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)