mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
* WIP clockify fix * WIP disable wp validation, make sync work * fix launcher start timer action * fix finish time entry * fix start and stop timers, cleanup, add TODO * show task name and type in description, add TODO * change rate limiter constants * black formatting * remove task type from data * cleanup debug prints * fix hound comments * remove unused import * move ids to property, fix user validation * remove f-strings, rollback description parsing * attempt to fix ftrack actions * check if sync action got some projects * get api data on process * remove unused variable * remove ratelimiter dependency * add response validation * a bit cleanup * Update openpype/modules/clockify/clockify_module.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * Update openpype/modules/clockify/clockify_api.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * Update openpype/modules/clockify/clockify_api.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * Update openpype/modules/clockify/clockify_api.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * Update openpype/modules/clockify/ftrack/server/action_clockify_sync_server.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * replace dunders with underscores * remove excessive variables * update set_user_id * continue check_running if no timer found * bring back come py2 compatibility * cleanup * get values directly from clockapi * hound * get task type to fill the tag field correctly * add logger, catch some json errors * remove check running timer, add project_id verification module * add current task_id check * remove package entries * make method private, fix typo * get task_type for the idle-restarted timer * remove trailing whitespace * show correct idle countdown values * finx indentation * Update openpype/modules/clockify/clockify_api.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * Update openpype/modules/clockify/clockify_module.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> * revert lock file * remove unused constants and redundant code * import clockify_api inside the method * do not query asset docs double time, add comments * add permissions check fail Exception * rename clockapi to clockify_api * formatting * removed unused variables --------- Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Co-authored-by: Jakub Trllo <jakub.trllo@gmail.com>
76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
from openpype.client import get_projects, get_project
|
|
from openpype_modules.clockify.clockify_api import ClockifyAPI
|
|
from openpype.pipeline import LauncherAction
|
|
|
|
|
|
class ClockifyPermissionsCheckFailed(Exception):
|
|
"""Timer start failed due to user permissions check.
|
|
Message should be self explanatory as traceback won't be shown.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class ClockifySync(LauncherAction):
|
|
name = "sync_to_clockify"
|
|
label = "Sync to Clockify"
|
|
icon = "app_icons/clockify-white.png"
|
|
order = 500
|
|
clockify_api = ClockifyAPI()
|
|
|
|
def is_compatible(self, session):
|
|
"""Check if there's some projects to sync"""
|
|
try:
|
|
next(get_projects())
|
|
return True
|
|
except StopIteration:
|
|
return False
|
|
|
|
def process(self, session, **kwargs):
|
|
self.clockify_api.set_api()
|
|
workspace_id = self.clockify_api.workspace_id
|
|
user_id = self.clockify_api.user_id
|
|
if not self.clockify_api.validate_workspace_permissions(
|
|
workspace_id, user_id
|
|
):
|
|
raise ClockifyPermissionsCheckFailed(
|
|
"Current CLockify user is missing permissions for this action!"
|
|
)
|
|
project_name = session.get("AVALON_PROJECT") or ""
|
|
|
|
projects_to_sync = []
|
|
if project_name.strip():
|
|
projects_to_sync = [get_project(project_name)]
|
|
else:
|
|
projects_to_sync = get_projects()
|
|
|
|
projects_info = {}
|
|
for project in projects_to_sync:
|
|
task_types = project["config"]["tasks"].keys()
|
|
projects_info[project["name"]] = task_types
|
|
|
|
clockify_projects = self.clockify_api.get_projects(workspace_id)
|
|
for project_name, task_types in projects_info.items():
|
|
if project_name in clockify_projects:
|
|
continue
|
|
|
|
response = self.clockify_api.add_project(
|
|
project_name, workspace_id
|
|
)
|
|
if "id" not in response:
|
|
self.log.error(
|
|
"Project {} can't be created".format(project_name)
|
|
)
|
|
continue
|
|
|
|
clockify_workspace_tags = self.clockify_api.get_tags(workspace_id)
|
|
for task_type in task_types:
|
|
if task_type not in clockify_workspace_tags:
|
|
response = self.clockify_api.add_tag(
|
|
task_type, workspace_id
|
|
)
|
|
if "id" not in response:
|
|
self.log.error(
|
|
"Task {} can't be created".format(task_type)
|
|
)
|
|
continue
|