@@ -273,6 +273,64 @@ def get_or_create_user(self, payload):
273273
274274 raise Exception (f"{ response .status_code } { response .text } " )
275275
276+ def set_user_group_reassignment_auth (self , user_id , groupreassign , manage_api_key ):
277+ """
278+ Set group reassignment authorization for a user via Manage API.
279+
280+ This method updates the grpreassignauth field for a user's maxuser record,
281+ which controls which security groups the user can reassign to other users.
282+
283+ Args:
284+ user_id (str): The unique identifier of the user.
285+ groupreassign (list): List of group objects in format [{"groupname": "GROUP1"}, {"groupname": "GROUP2"}, ...]
286+ manage_api_key (dict): API key record with 'apikey' field for authentication.
287+
288+ Returns:
289+ dict: Updated user record.
290+
291+ Raises:
292+ Exception: If the update fails.
293+ """
294+ if not groupreassign or len (groupreassign ) == 0 :
295+ self .logger .debug (f"No group reassignment authorization to set for user { user_id } " )
296+ return
297+
298+ self .logger .info (f"Setting group reassignment authorization for user { user_id } with { len (groupreassign )} groups" )
299+
300+ # Use Manage API to update the user's grpreassignauth
301+ url = f"{ self .manage_api_url_internal } /maximo/api/os/masapiuser/{ user_id } "
302+ querystring = {
303+ "lean" : 1 ,
304+ "ccm" : 1
305+ }
306+ headers = {
307+ "Content-Type" : "application/json" ,
308+ "apikey" : manage_api_key ["apikey" ]
309+ }
310+
311+ payload = {
312+ "maxuser" : [
313+ {
314+ "grpreassignauth" : groupreassign
315+ }
316+ ]
317+ }
318+
319+ response = requests .patch (
320+ url ,
321+ json = payload ,
322+ headers = headers ,
323+ params = querystring ,
324+ cert = self .manage_internal_client_pem_file_path ,
325+ verify = self .manage_internal_ca_pem_file_path
326+ )
327+
328+ if response .status_code == 200 :
329+ self .logger .info (f"Successfully set group reassignment authorization for user { user_id } " )
330+ return response .json ()
331+
332+ raise Exception (f"Failed to set group reassignment authorization: { response .status_code } { response .text } " )
333+
276334 def update_user (self , payload ):
277335 """
278336 Update an existing user's details.
@@ -972,7 +1030,7 @@ def get_all_manage_groups(self):
9721030 params = querystring ,
9731031 # verify=self.manage_internal_ca_pem_file_path,
9741032 cert = self .manage_internal_client_pem_file_path ,
975- verify = False
1033+ verify = self . manage_internal_ca_pem_file_path
9761034 )
9771035
9781036 if response .status_code != 200 :
@@ -1434,8 +1492,7 @@ def create_initial_user_for_saas(self, user, user_type, groupreassign=None):
14341492 {
14351493 "groupname" : "USERMANAGEMENT"
14361494 }
1437- ],
1438- "grpreassignauth" : groupreassign
1495+ ]
14391496 }
14401497 is_workspace_admin = True
14411498 application_role = "ADMIN"
@@ -1499,6 +1556,8 @@ def create_initial_user_for_saas(self, user, user_type, groupreassign=None):
14991556 maxadmin_manage_api_key = self .create_or_get_manage_api_key_for_user (MASUserUtils .MAXADMIN , temporary = True )
15001557 for manage_security_group in manage_security_groups :
15011558 self .add_user_to_manage_group (user_id , manage_security_group , maxadmin_manage_api_key )
1559+ if Version (self .mas_version ) >= Version ('9.1' ) and user_type == "PRIMARY" and groupreassign is not None :
1560+ self .set_user_group_reassignment_auth (user_id , groupreassign , maxadmin_manage_api_key )
15021561
15031562 # # Grant authorization to reassign users to/from ALL security groups (PRIMARY users only)
15041563 # if user_type == "PRIMARY":
0 commit comments