diff --git a/ayon_api/entity_hub.py b/ayon_api/entity_hub.py index 356caea63..ead6b4078 100644 --- a/ayon_api/entity_hub.py +++ b/ayon_api/entity_hub.py @@ -49,66 +49,22 @@ class EntityHub(object): Args: project_name (str): Name of project where changes will happen. connection (ServerAPI): Connection to server with logged user. - allow_data_changes (bool): This option gives ability to change 'data' - key on entities. This is not recommended as 'data' may be used for - secure information and would also slow down server queries. Content - of 'data' key can't be received only GraphQl. """ - def __init__( - self, project_name, connection=None, allow_data_changes=None - ): + def __init__(self, project_name, connection=None): if not connection: connection = get_server_api_connection() - major, minor, _, _, _ = connection.server_version_tuple - path_start_with_slash = True - if (major, minor) < (0, 6): - path_start_with_slash = False - - if allow_data_changes is None: - allow_data_changes = connection.graphql_allows_data_in_query self._connection = connection - self._path_start_with_slash = path_start_with_slash self._project_name = project_name self._entities_by_id = {} self._entities_by_parent_id = collections.defaultdict(list) self._project_entity = UNKNOWN_VALUE - self._allow_data_changes = allow_data_changes - self._path_reset_queue = None - @property - def allow_data_changes(self): - """Entity hub allows changes of 'data' key on entities. - - Data are private and not all users may have access to them. - - Older version of AYON server allowed to get 'data' for entity only - using REST api calls, which means to query each entity on-by-one - from server. - - Returns: - bool: Data changes are allowed. - - """ - return self._allow_data_changes - - @property - def path_start_with_slash(self): - """Folder path should start with slash. - - This changed in 0.6.x server version. - - Returns: - bool: Path starts with slash. - - """ - return self._path_start_with_slash - @property def project_name(self): """Project name which is maintained by hub. @@ -898,8 +854,7 @@ def _get_folder_fields(self) -> Set[str]: self._connection.get_default_fields_for_type("folder") ) folder_fields.add("hasProducts") - if self._allow_data_changes: - folder_fields.add("data") + folder_fields.add("data") return folder_fields def _get_task_fields(self) -> Set[str]: @@ -1717,10 +1672,7 @@ def _get_default_changes(self): """ changes = {} - if ( - self._entity_hub.allow_data_changes - and self._data is not UNKNOWN_VALUE - ): + if self._data is not UNKNOWN_VALUE: data_changes = self._data.get_changes() if data_changes: changes["data"] = data_changes @@ -3149,10 +3101,8 @@ def get_path(self, dynamic_value=True): if parent.entity_type == "folder": parent_path = parent.path path = "/".join([parent_path, self.name]) - elif self._entity_hub.path_start_with_slash: - path = "/{}".format(self.name) else: - path = self.name + path = "/{}".format(self.name) self._path = path return self._path @@ -3260,10 +3210,7 @@ def to_create_body_data(self): if self.thumbnail_id is not UNKNOWN_VALUE: output["thumbnailId"] = self.thumbnail_id - if ( - self._entity_hub.allow_data_changes - and self._data is not UNKNOWN_VALUE - ): + if self._data is not UNKNOWN_VALUE: output["data"] = self._data.get_new_entity_value() return output @@ -3451,10 +3398,7 @@ def to_create_body_data(self): if self.assignees: output["assignees"] = self.assignees - if ( - self._entity_hub.allow_data_changes - and self._data is not UNKNOWN_VALUE - ): + if self._data is not UNKNOWN_VALUE: output["data"] = self._data.get_new_entity_value() return output @@ -3561,10 +3505,7 @@ def to_create_body_data(self): if self.tags: output["tags"] = self.tags - if ( - self._entity_hub.allow_data_changes - and self._data is not UNKNOWN_VALUE - ): + if self._data is not UNKNOWN_VALUE: output["data"] = self._data.get_new_entity_value() return output @@ -3693,9 +3634,6 @@ def to_create_body_data(self): if self.status: output["status"] = self.status - if ( - self._entity_hub.allow_data_changes - and self._data is not UNKNOWN_VALUE - ): + if self._data is not UNKNOWN_VALUE: output["data"] = self._data.get_new_entity_value() return output diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 55608100b..bfdda4ca4 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -52,7 +52,6 @@ DEFAULT_EVENT_FIELDS, DEFAULT_ACTIVITY_FIELDS, DEFAULT_USER_FIELDS, - DEFAULT_LINK_FIELDS, ) from .graphql import GraphQlQuery, INTROSPECTION_QUERY from .graphql_queries import ( @@ -520,7 +519,6 @@ def __init__( self._server_version = None self._server_version_tuple = None - self._graphql_allows_data_in_query = None self._graphql_allows_traits_in_representations: Optional[bool] = None self._session = None @@ -1097,27 +1095,6 @@ def get_server_version_tuple(self) -> Tuple[int, int, int, str, str]: get_server_version_tuple ) - @property - def graphql_allows_data_in_query(self) -> bool: - """GraphQl query can support 'data' field. - - This applies only to project hierarchy entities 'project', 'folder', - 'task', 'product', 'version' and 'representation'. Others like 'user' - still require to use rest api to access 'data'. - - Returns: - bool: True if server supports 'data' field in GraphQl query. - - """ - if self._graphql_allows_data_in_query is None: - major, minor, patch, _, _ = self.server_version_tuple - graphql_allows_data_in_query = True - if (major, minor, patch) < (0, 5, 5): - graphql_allows_data_in_query = False - self._graphql_allows_data_in_query = graphql_allows_data_in_query - return self._graphql_allows_data_in_query - - @property def graphql_allows_traits_in_representations(self) -> bool: """Check server support for representation traits.""" @@ -1687,21 +1664,6 @@ def update_event( ) if value is not None } - # 'progress' and 'retries' are available since 0.5.x server version - major, minor, _, _, _ = self.server_version_tuple - if (major, minor) < (0, 5): - args = [] - if progress is not None: - args.append("progress") - if retries is not None: - args.append("retries") - fields = ", ".join(f"'{f}'" for f in args) - ending = "s" if len(args) > 1 else "" - raise ValueError( - f"Your server version '{self.server_version}' does not" - f" support update of {fields} field{ending} on event." - " The fields are supported since server version '0.5'." - ) response = self.patch( f"events/{event_id}", @@ -2761,36 +2723,24 @@ def get_default_fields_for_type(self, entity_type: str) -> Set[str]: if entity_type == "project": entity_type_defaults = set(DEFAULT_PROJECT_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "folder": entity_type_defaults = set(DEFAULT_FOLDER_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "task": entity_type_defaults = set(DEFAULT_TASK_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "product": entity_type_defaults = set(DEFAULT_PRODUCT_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "version": entity_type_defaults = set(DEFAULT_VERSION_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "representation": entity_type_defaults = ( DEFAULT_REPRESENTATION_FIELDS | REPRESENTATION_FILES_FIELDS ) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") if not self.graphql_allows_traits_in_representations: entity_type_defaults.discard("traits") @@ -2806,8 +2756,6 @@ def get_default_fields_for_type(self, entity_type: str) -> Set[str]: elif entity_type == "workfile": entity_type_defaults = set(DEFAULT_WORKFILE_INFO_FIELDS) - if not self.graphql_allows_data_in_query: - entity_type_defaults.discard("data") elif entity_type == "user": entity_type_defaults = set(DEFAULT_USER_FIELDS) @@ -4968,15 +4916,10 @@ def get_folders( fields = set(fields) self._prepare_fields("folder", fields) - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") - if own_attributes and not use_rest: + if own_attributes: fields.add("ownAttrib") query = folders_graphql_query(fields) @@ -4988,10 +4931,7 @@ def get_folders( if active is not None and active is not folder["active"]: continue - if use_rest: - folder = self.get_rest_folder(project_name, folder["id"]) - else: - self._convert_entity_data(folder) + self._convert_entity_data(folder) if own_attributes: fill_own_attribs(folder) @@ -5363,11 +5303,6 @@ def get_tasks( fields = set(fields) self._prepare_fields("task", fields, own_attributes) - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") @@ -5380,10 +5315,7 @@ def get_tasks( if active is not None and active is not task["active"]: continue - if use_rest: - task = self.get_rest_task(project_name, task["id"]) - else: - self._convert_entity_data(task) + self._convert_entity_data(task) if own_attributes: fill_own_attribs(task) @@ -5525,11 +5457,6 @@ def get_tasks_by_folder_paths( fields = set(fields) self._prepare_fields("task", fields, own_attributes) - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") @@ -5548,10 +5475,7 @@ def get_tasks_by_folder_paths( if active is not None and active is not task["active"]: continue - if use_rest: - task = self.get_rest_task(project_name, task["id"]) - else: - self._convert_entity_data(task) + self._convert_entity_data(task) if own_attributes: fill_own_attribs(task) @@ -5801,15 +5725,11 @@ def _filter_product( project_name: str, product: "ProductDict", active: "Union[bool, None]", - use_rest: bool, ) -> Optional["ProductDict"]: if active is not None and product["active"] is not active: return None - if use_rest: - product = self.get_rest_product(project_name, product["id"]) - else: - self._convert_entity_data(product) + self._convert_entity_data(product) return product @@ -5902,11 +5822,6 @@ def get_products( else: fields = self.get_default_fields_for_type("product") - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") @@ -5964,7 +5879,7 @@ def get_products( products_by_folder_id = collections.defaultdict(list) for product in products: filtered_product = self._filter_product( - project_name, product, active, use_rest + project_name, product, active ) if filtered_product is not None: folder_id = filtered_product["folderId"] @@ -5978,7 +5893,7 @@ def get_products( else: for product in products: filtered_product = self._filter_product( - project_name, product, active, use_rest + project_name, product, active ) if filtered_product is not None: yield filtered_product @@ -6325,11 +6240,6 @@ def get_versions( # Make sure fields have minimum required fields fields |= {"id", "version"} - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") @@ -6402,12 +6312,7 @@ def get_versions( if not hero and version["version"] < 0: continue - if use_rest: - version = self.get_rest_version( - project_name, version["id"] - ) - else: - self._convert_entity_data(version) + self._convert_entity_data(version) yield version @@ -6969,11 +6874,6 @@ def get_representations( fields = set(fields) self._prepare_fields("representation", fields) - use_rest = False - if "data" in fields and not self.graphql_allows_data_in_query: - use_rest = True - fields = {"id"} - if active is not None: fields.add("active") @@ -7055,12 +6955,7 @@ def get_representations( if active is not None and active is not repre["active"]: continue - if use_rest: - repre = self.get_rest_representation( - project_name, repre["id"] - ) - else: - self._convert_entity_data(repre) + self._convert_entity_data(repre) self._representation_conversion(repre) @@ -8441,22 +8336,8 @@ def create_link( kwargs = { "input": input_id, "output": output_id, + "linkType": full_link_type_name, } - major, minor, patch, rel, _ = self.server_version_tuple - rel_regex = re.compile(r"rc\.[0-5]") - if ( - ((major, minor, patch) == (1, 0, 0) and rel_regex.match(rel)) - or (major, minor, patch) < (1, 0, 0) - ): - kwargs["link"] = full_link_type_name - if link_name: - raise UnsupportedServerVersion( - "Link name is not supported" - f" for version of AYON server {self.server_version}" - ) - else: - kwargs["linkType"] = full_link_type_name - if link_name: kwargs["name"] = link_name @@ -8618,23 +8499,6 @@ def get_entities_links( return output link_fields = {"id", "links"} - # Backwards compatibility for server version 1.0.0-rc.5 and lower - # --------- - major, minor, patch, rel, _ = self.server_version_tuple - rel_regex = re.compile(r"rc\.[0-5]") - if ( - ((major, minor, patch) == (1, 0, 0) and rel_regex.match(rel)) - or (major, minor, patch) < (1, 0, 0) - ): - fields = set(DEFAULT_LINK_FIELDS) - fields.discard("name") - link_fields.discard("links") - link_fields |= { - f"links.{field}" - for field in fields - } - # --------- - query = query_func(link_fields) for attr, filter_value in filters.items(): query.set_variable_value(attr, filter_value)