@@ -324,7 +324,10 @@ def fill_own_attribs(entity):
324324 if not entity or not entity .get ("attrib" ):
325325 return
326326
327- attributes = set (entity ["ownAttrib" ])
327+ attributes = entity .get ("ownAttrib" )
328+ if attributes is None :
329+ return
330+ attributes = set (attributes )
328331
329332 own_attrib = {}
330333 entity ["ownAttrib" ] = own_attrib
@@ -1186,6 +1189,7 @@ def get_users(
11861189 for attr , filter_value in filters .items ():
11871190 query .set_variable_value (attr , filter_value )
11881191
1192+ attributes = self .get_attributes_for_type ("user" )
11891193 for parsed_data in query .continuous_query (self ):
11901194 for user in parsed_data ["users" ]:
11911195 access_groups = user .get ("accessGroups" )
@@ -1194,7 +1198,15 @@ def get_users(
11941198 all_attrib = user .get ("allAttrib" )
11951199 if isinstance (all_attrib , str ):
11961200 user ["allAttrib" ] = json .loads (all_attrib )
1197- fill_own_attribs (user )
1201+ if "attrib" in user :
1202+ user ["ownAttrib" ] = user ["attrib" ].copy ()
1203+ attrib = user ["attrib" ]
1204+ for key , value in tuple (attrib .items ()):
1205+ if value is not None :
1206+ continue
1207+ attr_def = attributes .get (key )
1208+ if attr_def is not None :
1209+ attrib [key ] = attr_def ["default" ]
11981210 yield user
11991211
12001212 def get_user_by_name (
@@ -1233,7 +1245,9 @@ def get_user_by_name(
12331245 def get_user (
12341246 self , username : Optional [str ] = None
12351247 ) -> Optional [Dict [str , Any ]]:
1236- """Get user info using REST endpoit.
1248+ """Get user info using REST endpoint.
1249+
1250+ User contains only explicitly set attributes in 'attrib'.
12371251
12381252 Args:
12391253 username (Optional[str]): Username.
@@ -1244,14 +1258,19 @@ def get_user(
12441258
12451259 """
12461260 if username is None :
1247- output = self ._get_user_info ()
1248- if output is None :
1261+ user = self ._get_user_info ()
1262+ if user is None :
12491263 raise UnauthorizedError ("User is not authorized." )
1250- return output
1264+ else :
1265+ response = self .get (f"users/{ username } " )
1266+ response .raise_for_status ()
1267+ user = response .data
1268+
1269+ # NOTE Server does return only filled attributes right now.
1270+ # This would fill all missing attributes with 'None'.
1271+ # for attr_name in self.get_attributes_for_type("user"):
1272+ # user["attrib"].setdefault(attr_name, None)
12511273
1252- response = self .get (f"users/{ username } " )
1253- response .raise_for_status ()
1254- user = response .data
12551274 fill_own_attribs (user )
12561275 return user
12571276
0 commit comments