@@ -1677,7 +1677,62 @@ def add_subgroup(self, parent_uuid, child_uuid):
16771677 headers = {"Content-Type" : "text/uri-list" }
16781678 data = f"{ self .API_ENDPOINT } /eperson/groups/{ child_uuid } "
16791679 response = self .api_post (url , headers = headers , data = data )
1680- return response .status_code == 204
1680+ if response .status_code == 204 :
1681+ return True
1682+ elif response .status_code == 401 :
1683+ logging .error ("You are not authenticated" )
1684+ return False
1685+ elif response .status_code == 403 :
1686+ logging .error ("You are not logged in with sufficient permissions" )
1687+ return False
1688+ elif response .status_code == 404 :
1689+ logging .error ("The parent group doesn't exist" )
1690+ return False
1691+ elif response .status_code == 422 :
1692+ logging .error (
1693+ "The specified group is not found, or if adding the group would create a cyclic reference"
1694+ )
1695+ return False
1696+ else :
1697+ logging .error (
1698+ "Failed to add subgroup %s to group %s: %s" ,
1699+ child_uuid ,
1700+ parent_uuid ,
1701+ response .text ,
1702+ )
1703+ return False
1704+
1705+ def remove_subgroup (self , parent_uuid , child_uuid ):
1706+ """
1707+ Remove a subgroup from a parent group
1708+ @param parent_uuid: UUID of the parent group
1709+ @param child_uuid: UUID of the subgroup to remove
1710+ @return: Boolean indicating success or failure
1711+ """
1712+ url = f"{ self .API_ENDPOINT } /eperson/groups/{ parent_uuid } /subgroups/{ child_uuid } "
1713+ response = self .api_delete (url )
1714+ if response .status_code == 204 :
1715+ return True
1716+ if response .status_code == 401 :
1717+ logging .error ("You are not authenticated" )
1718+ return False
1719+ elif response .status_code == 403 :
1720+ logging .error ("You are not logged in with sufficient permissions" )
1721+ return False
1722+ elif response .status_code == 404 :
1723+ logging .error ("The parent group doesn't exist" )
1724+ return False
1725+ elif response .status_code == 422 :
1726+ logging .error ("The specified group is not found" )
1727+ return False
1728+ else :
1729+ logging .error (
1730+ "Failed to remove subgroup %s from group %s: %s" ,
1731+ child_uuid ,
1732+ parent_uuid ,
1733+ response .text ,
1734+ )
1735+ return False
16811736
16821737 def start_workflow (self , workspace_item ):
16831738 url = f"{ self .API_ENDPOINT } /workflow/workflowitems"
0 commit comments