From 65ee3a82177beecae3a0b0590c1bd7143ca57413 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 6 Mar 2019 18:21:17 +0100 Subject: [PATCH] added interface, fixed role list, autorization check before register --- pype/ftrack/actions/action_clockify_sync.py | 84 +++++++++++++++++---- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/pype/ftrack/actions/action_clockify_sync.py b/pype/ftrack/actions/action_clockify_sync.py index afb3173e4a..f3b1a49329 100644 --- a/pype/ftrack/actions/action_clockify_sync.py +++ b/pype/ftrack/actions/action_clockify_sync.py @@ -3,7 +3,7 @@ import argparse import logging import json import ftrack_api -from pype.ftrack import BaseAction +from pype.ftrack import BaseAction, MissingPermision from pype.clockify import ClockifyAPI @@ -19,16 +19,16 @@ class SyncClocify(BaseAction): #: priority priority = 100 #: roles that are allowed to register this action - role_list = ['Pypecub', 'Administrator'] + role_list = ['Pypeclub', 'Administrator'] #: icon icon = 'https://clockify.me/assets/images/clockify-logo-white.svg' #: CLockifyApi clockapi = ClockifyAPI() - def discover(self, session, entities, event): - ''' Validation ''' - - return True + def register(self): + if self.validate_auth_rights() is False: + raise MissingPermision + super().register() def validate_auth_rights(self): test_project = '__test__' @@ -39,16 +39,57 @@ class SyncClocify(BaseAction): self.clockapi.delete_project(test_project) return True - def launch(self, session, entities, event): - authorization = self.validate_auth_rights() - if authorization is False: - return { - 'success': False, - 'message': ( - 'You don\'t have permission to modify Clockify' - ' workspace {}'.format(self.clockapi.workspace) - ) + def discover(self, session, entities, event): + ''' Validation ''' + + return True + + def interface(self, session, entities, event): + if not event['data'].get('values', {}): + title = 'Select projects to sync' + + projects = session.query('Project').all() + + items = [] + all_projects_label = { + 'type': 'label', + 'value': 'All projects' } + all_projects_value = { + 'name': '__all__', + 'type': 'boolean', + 'value': False + } + line = { + 'type': 'label', + 'value': '___' + } + items.append(all_projects_label) + items.append(all_projects_value) + items.append(line) + for project in projects: + label = project['full_name'] + item_label = { + 'type': 'label', + 'value': label + } + item_value = { + 'name': project['id'], + 'type': 'boolean', + 'value': False + } + items.append(item_label) + items.append(item_value) + + return { + 'items': items, + 'title': title + } + + def launch(self, session, entities, event): + values = event['data'].get('values', {}) + if not values: + return # JOB SETTINGS userId = event['source']['user']['id'] @@ -63,8 +104,19 @@ class SyncClocify(BaseAction): }) session.commit() try: + if values.get('__all__', False) is True: + projects_to_sync = session.query('Project').all() + else: + projects_to_sync = [] + project_query = 'Project where id is "{}"' + for project_id, sync in values.items(): + if sync is True: + projects_to_sync.append(session.query( + project_query.format(project_id) + ).one()) + projects_info = {} - for project in session.query('Project').all(): + for project in projects_to_sync: task_types = [] for task_type in project['project_schema']['_task_type_schema'][ 'types'