use new options of selection object

This commit is contained in:
Jakub Trllo 2024-03-28 16:07:13 +01:00
parent 27793cef1f
commit 93b9541268
3 changed files with 26 additions and 29 deletions

View file

@ -11,19 +11,17 @@ class ClockifyStart(LauncherAction):
order = 500
clockify_api = ClockifyAPI()
def is_compatible(self, session):
def is_compatible(self, selection):
"""Return whether the action is compatible with the session"""
if "AYON_TASK_NAME" in session:
return True
return False
return selection.is_task_selected
def process(self, session, **kwargs):
def process(self, selection, **kwargs):
self.clockify_api.set_api()
user_id = self.clockify_api.user_id
workspace_id = self.clockify_api.workspace_id
project_name = session["AYON_PROJECT_NAME"]
folder_path = session["AYON_FOLDER_PATH"]
task_name = session["AYON_TASK_NAME"]
project_name = selection.project_name
folder_path = selection.folder_path
task_name = selection.task_name
description = "/".join([folder_path.lstrip("/"), task_name])
# fetch folder entity

View file

@ -19,15 +19,18 @@ class ClockifySync(LauncherAction):
order = 500
clockify_api = ClockifyAPI()
def is_compatible(self, session):
def is_compatible(self, selection):
"""Check if there's some projects to sync"""
if selection.is_project_selected:
return True
try:
next(ayon_api.get_projects())
return True
except StopIteration:
return False
def process(self, session, **kwargs):
def process(self, selection, **kwargs):
self.clockify_api.set_api()
workspace_id = self.clockify_api.workspace_id
user_id = self.clockify_api.user_id
@ -37,10 +40,9 @@ class ClockifySync(LauncherAction):
raise ClockifyPermissionsCheckFailed(
"Current CLockify user is missing permissions for this action!"
)
project_name = session.get("AYON_PROJECT_NAME") or ""
if project_name.strip():
projects_to_sync = [ayon_api.get_project(project_name)]
if selection.is_project_selected:
projects_to_sync = [selection.project_entity]
else:
projects_to_sync = ayon_api.get_projects()