Skip to content

Commit be0d468

Browse files
committed
add functions to add and remove epersons to/from groups
1 parent 0f96546 commit be0d468

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

dspace_rest_client/client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,66 @@ def get_epersons_in_group(self, group_uuid, page=0, size=20):
17741774

17751775
return epersons
17761776

1777+
def add_eperson_to_group(self, group_uuid, eperson_uuid):
1778+
"""
1779+
Add an EPerson to a group
1780+
@param group_uuid: UUID of the group
1781+
@param eperson_uuid: UUID of the EPerson to add
1782+
@return: Boolean indicating success or failure
1783+
"""
1784+
url = f"{self.API_ENDPOINT}/eperson/groups/{group_uuid}/epersons"
1785+
headers = {"Content-Type": "text/uri-list"}
1786+
data = f"{self.API_ENDPOINT}/eperson/epersons/{eperson_uuid}"
1787+
response = self.api_post(url, headers=headers, data=data)
1788+
if response.status_code == 204:
1789+
return True
1790+
elif response.status_code == 401:
1791+
logging.error("You are not authenticated")
1792+
return False
1793+
elif response.status_code == 403:
1794+
logging.error("You are not logged in with sufficient permissions")
1795+
return False
1796+
elif response.status_code == 422:
1797+
logging.error("The specified group or EPerson is not found")
1798+
return False
1799+
else:
1800+
logging.error(
1801+
"Failed to add EPerson %s to group %s: %s",
1802+
eperson_uuid,
1803+
group_uuid,
1804+
response.text,
1805+
)
1806+
return False
1807+
1808+
def remove_eperson_from_group(self, group_uuid, eperson_uuid):
1809+
"""
1810+
Remove an EPerson from a group
1811+
@param group_uuid: UUID of the group
1812+
@param eperson_uuid: UUID of the EPerson to remove
1813+
@return: Boolean indicating success or failure
1814+
"""
1815+
url = f"{self.API_ENDPOINT}/eperson/groups/{group_uuid}/epersons/{eperson_uuid}"
1816+
response = self.api_delete(url)
1817+
if response.status_code == 204:
1818+
return True
1819+
elif response.status_code == 401:
1820+
logging.error("You are not authenticated")
1821+
return False
1822+
elif response.status_code == 403:
1823+
logging.error("You are not logged in with sufficient permissions")
1824+
return False
1825+
elif response.status_code == 422:
1826+
logging.error("The specified group or EPerson is not found")
1827+
return False
1828+
else:
1829+
logging.error(
1830+
"Failed to remove EPerson %s from group %s: %s",
1831+
eperson_uuid,
1832+
group_uuid,
1833+
response.text,
1834+
)
1835+
return False
1836+
17771837
def start_workflow(self, workspace_item):
17781838
url = f"{self.API_ENDPOINT}/workflow/workflowitems"
17791839
res = parse_json(self.api_post_uri(url, params=None, uri_list=workspace_item))

0 commit comments

Comments
 (0)