Skip to content

Commit

Permalink
Improve exception handling on reader account login
Browse files Browse the repository at this point in the history
- If there's an issue when logging in (e.g. due to invalid credentials), the user will now return a 500, not a 403
  • Loading branch information
MRichards99 committed Oct 2, 2024
1 parent c5325b0 commit 74185f9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions datagateway_api/src/datagateway_api/icat/reader_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ReaderQueryHandler:
# TODO - better names and comments on dicts to explain what they're for
# TODO - add docstrings
entity_filter_check = {"Datafile": "dataset.id", "Dataset": "investigation.id"}
entity_type_check = {"Datafile": "Dataset", "Dataset": "Investigation"}
parent_entity_lookup = {"Datafile": "Dataset", "Dataset": "Investigation"}
# keep a cached reader_client for faster queries
reader_client = None

Expand All @@ -36,10 +36,13 @@ def create_reader_client(self):
"username": reader_config.reader_username,
"password": reader_config.reader_password,
}
ReaderQueryHandler.reader_client.login(
reader_config.reader_mechanism,
login_credentals,
)
try:
ReaderQueryHandler.reader_client.login(
reader_config.reader_mechanism, login_credentals,
)
except ICATSessionError:
log.error("User credentials for reader account aren't valid")
raise PythonICATError("Internal error with reader account configuration")
return ReaderQueryHandler.reader_client

def check_eligibility(self):
Expand Down Expand Up @@ -77,8 +80,7 @@ def is_user_authorised_to_see_entity_id(self, client):
self.where_filter_entity_id,
)
access_query = ICATQuery(
client,
ReaderQueryHandler.entity_type_check[self.entity_type],
client, ReaderQueryHandler.parent_entity_lookup[self.entity_type],
)
id_check = PythonICATWhereFilter("id", self.where_filter_entity_id, "eq")
access_filter_handler = FilterOrderHandler()
Expand Down

0 comments on commit 74185f9

Please sign in to comment.