Skip to content

Commit e002ce5

Browse files
committed
add function to get the access status of an item
1 parent 4829ba9 commit e002ce5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

dspace_rest_client/client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,34 @@ def get_item_relationships(self, item):
15931593
logging.error(f"Error retrieving relationships for item {item.uuid}: {e}")
15941594
return None
15951595

1596+
def get_item_access_status(self, item):
1597+
"""
1598+
Get the access status of a given item
1599+
@param item: Item object
1600+
@return: Access status as a dictionary or None if an error occurs
1601+
"""
1602+
if not isinstance(item, Item):
1603+
logging.error("Need a valid item")
1604+
return None
1605+
1606+
url = f"{self.API_ENDPOINT}/core/items/{item.uuid}/accessStatus"
1607+
try:
1608+
response = self.api_get(url)
1609+
if response.status_code == 200:
1610+
return response.json()
1611+
elif response.status_code == 400:
1612+
logging.error(f"Bad Request: Invalid parameter for item {item.uuid}")
1613+
elif response.status_code == 404:
1614+
logging.error(f"Item not found: {item.uuid}")
1615+
else:
1616+
logging.error(
1617+
f"Unexpected response for item {item.uuid}: {response.status_code}"
1618+
)
1619+
return None
1620+
except Exception as e:
1621+
logging.error(f"Error retrieving access status for item {item.uuid}: {e}")
1622+
return None
1623+
15961624
def create_user(self, user, token=None, embeds=None):
15971625
"""
15981626
Create a user

0 commit comments

Comments
 (0)