Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For a request with a coverage no authorized_instances needed #3923

Merged
merged 1 commit into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions source/jormungandr/jormungandr/instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,27 @@ def get_instances(self, name=None, lon=None, lat=None, object_id=None, api='ALL'
# Request without token or bad token makes a request exception and exits with a message
# get_user is cached hence access to database only once when cache expires.
user = authentication.get_user(token=authentication.get_token())

# fetch all the authorized instances (free + private) using cached function has_access()
authorized_instances = self._get_authorized_instances(user, api)
if not authorized_instances:
# user doesn't have access to any of the instances
context = 'User has no access to any instance'
authentication.abort_request(user=user, context=context)

# Filter instances among instances in authorized_instances
valid_instances = []
if name:
valid_instances = [i for i in authorized_instances if i.name == name]
elif lon and lat:
valid_instances = self._all_keys_of_coord_in_instances(authorized_instances, lon, lat)
elif object_id:
valid_instances = self._find_coverage_by_object_id_in_instances(authorized_instances, object_id)
# Requests with a coverage
available_instance = self.instances[name]
if authentication.has_access(available_instance.name, abort=False, user=user, api=api):
valid_instances = [self.instances[name]]
else:
valid_instances = authorized_instances
# Requests without any coverage
# fetch all the authorized instances (free + private) using cached function has_access()
authorized_instances = self._get_authorized_instances(user, api)
if not authorized_instances:
# user doesn't have access to any of the instances
context = 'User has no access to any instance'
authentication.abort_request(user=user, context=context)

if lon and lat:
valid_instances = self._all_keys_of_coord_in_instances(authorized_instances, lon, lat)
elif object_id:
valid_instances = self._find_coverage_by_object_id_in_instances(authorized_instances, object_id)
else:
valid_instances = authorized_instances

if not valid_instances:
# user doesn't have access to any of the instances
Expand Down