From 2db4b1019a5f957c8953ba94a261c90d788a066f Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:00:17 +0200 Subject: [PATCH 1/8] do no fill own attribs in graphql --- ayon_api/server_api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 6a47b8c23..2f8f61432 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1194,7 +1194,6 @@ def get_users( all_attrib = user.get("allAttrib") if isinstance(all_attrib, str): user["allAttrib"] = json.loads(all_attrib) - fill_own_attribs(user) yield user def get_user_by_name( From 7bc569916ed882b60801812e4927918fa3642338 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:08:09 +0200 Subject: [PATCH 2/8] added commented way how to fill attributes for future reference --- ayon_api/server_api.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 2f8f61432..c1725e261 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1232,7 +1232,7 @@ def get_user_by_name( def get_user( self, username: Optional[str] = None ) -> Optional[Dict[str, Any]]: - """Get user info using REST endpoit. + """Get user info using REST endpoint. Args: username (Optional[str]): Username. @@ -1243,14 +1243,18 @@ def get_user( """ if username is None: - output = self._get_user_info() - if output is None: + user = self._get_user_info() + if user is None: raise UnauthorizedError("User is not authorized.") - return output + else: + response = self.get(f"users/{username}") + response.raise_for_status() + user = response.data + + # NOTE This would fill all missing attributes with 'None' + # for attr_name in self.get_attributes_for_type("user"): + # user["attrib"].setdefault(attr_name, None) - response = self.get(f"users/{username}") - response.raise_for_status() - user = response.data fill_own_attribs(user) return user From ac4001a860054dc45e6afda4f3b5d629d68f0d6d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:33:49 +0200 Subject: [PATCH 3/8] use default attribute value for None values --- ayon_api/server_api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index c1725e261..82db6cddc 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1186,6 +1186,7 @@ def get_users( for attr, filter_value in filters.items(): query.set_variable_value(attr, filter_value) + attributes = self.get_attributes_for_type("user") for parsed_data in query.continuous_query(self): for user in parsed_data["users"]: access_groups = user.get("accessGroups") @@ -1194,6 +1195,15 @@ def get_users( all_attrib = user.get("allAttrib") if isinstance(all_attrib, str): user["allAttrib"] = json.loads(all_attrib) + if "attrib" in user: + user["ownAttrib"] = user["attrib"].copy() + attrib = user["attrib"] + for key, value in tuple(attrib.items()): + if value is not None: + continue + attr_def = attributes.get(key) + if attr_def is not None: + attrib[key] = attr_def["default"] yield user def get_user_by_name( From 589ac3d151830fe3d5cf07370a00407e7b560717 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:34:01 +0200 Subject: [PATCH 4/8] added more information to comments or docstring --- ayon_api/server_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 82db6cddc..ce0462c22 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1243,6 +1243,8 @@ def get_user( self, username: Optional[str] = None ) -> Optional[Dict[str, Any]]: """Get user info using REST endpoint. + + User contains only explicitly set attributes in 'attrib'. Args: username (Optional[str]): Username. @@ -1261,7 +1263,8 @@ def get_user( response.raise_for_status() user = response.data - # NOTE This would fill all missing attributes with 'None' + # NOTE Server does return only filled attributes right now. + # This would fill all missing attributes with 'None'. # for attr_name in self.get_attributes_for_type("user"): # user["attrib"].setdefault(attr_name, None) From a9a9bdfeb624205a20490c8a2b0e9c5c408ffe36 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:34:21 +0200 Subject: [PATCH 5/8] added check for "ownAttrib" key --- ayon_api/server_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index ce0462c22..5bb3342e8 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -321,7 +321,7 @@ def __repr__(self): def fill_own_attribs(entity): - if not entity or not entity.get("attrib"): + if not entity or not entity.get("attrib") or "ownAttrib" not in entity: return attributes = set(entity["ownAttrib"]) From 4ebad5f2aa7b06d8d55c9a4bc5341571b8c879b4 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:35:11 +0200 Subject: [PATCH 6/8] faster check --- ayon_api/server_api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 5bb3342e8..3edbb9d86 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -321,10 +321,13 @@ def __repr__(self): def fill_own_attribs(entity): - if not entity or not entity.get("attrib") or "ownAttrib" not in entity: + if not entity or not entity.get("attrib"): return - attributes = set(entity["ownAttrib"]) + attributes = entity.get("ownAttrib") + if attributes is None: + return + attributes = set(attributes) own_attrib = {} entity["ownAttrib"] = own_attrib From 3dfa2f04061adbc43af8b8f056280cd4ea994eab Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:38:02 +0200 Subject: [PATCH 7/8] update public api docstring --- ayon_api/_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ayon_api/_api.py b/ayon_api/_api.py index 23e9769aa..0bfe3ee63 100644 --- a/ayon_api/_api.py +++ b/ayon_api/_api.py @@ -766,7 +766,9 @@ def get_user_by_name( def get_user( username: Optional[str] = None, ) -> Optional[Dict[str, Any]]: - """Get user info using REST endpoit. + """Get user info using REST endpoint. + + User contains only explicitly set attributes in 'attrib'. Args: username (Optional[str]): Username. From b6d74b36fb7641abf06140a02116ac3a39bb24f2 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 1 Aug 2025 15:38:45 +0200 Subject: [PATCH 8/8] fix formatting --- ayon_api/server_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 3edbb9d86..c1b3e7f97 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1246,7 +1246,7 @@ def get_user( self, username: Optional[str] = None ) -> Optional[Dict[str, Any]]: """Get user info using REST endpoint. - + User contains only explicitly set attributes in 'attrib'. Args: