Skip to content

Commit

Permalink
Refactor draft record check
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Aug 16, 2023
1 parent 7d7cb60 commit 343f874
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/galaxy/files/sources/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,16 @@ def _get_download_file_url(self, record_id: str, filename: str, user_context: Op
return download_file_content_url

def _is_draft_record(self, record_id: str, user_context: OptionalUserContext = None):
try:
self._get_draft_record(record_id, user_context)
return True
except Exception as e:
if "404" in str(e):
return False
raise e
request_url = self._get_draft_record_url(record_id)
headers = self._get_request_headers(user_context)
response = requests.get(request_url, headers=headers)
return response.status_code == 200

def _get_draft_record_url(self, record_id: str):
return f"{self.records_url}/{record_id}/draft"

def _get_draft_record(self, record_id: str, user_context: OptionalUserContext = None):
request_url = f"{self.records_url}/{record_id}/draft"
request_url = self._get_draft_record_url(record_id)
draft_record = self._get_response(user_context, request_url)
return draft_record

Expand Down

0 comments on commit 343f874

Please sign in to comment.