Skip to content

Commit fed2574

Browse files
authored
Merge pull request #3923 from hove-io/fix_get_instance_with_name
For a request with a coverage no authorized_instances needed
2 parents 4d869fa + 5bdc2ac commit fed2574

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

source/jormungandr/jormungandr/instance_manager.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,27 @@ def get_instances(self, name=None, lon=None, lat=None, object_id=None, api='ALL'
288288
# Request without token or bad token makes a request exception and exits with a message
289289
# get_user is cached hence access to database only once when cache expires.
290290
user = authentication.get_user(token=authentication.get_token())
291-
292-
# fetch all the authorized instances (free + private) using cached function has_access()
293-
authorized_instances = self._get_authorized_instances(user, api)
294-
if not authorized_instances:
295-
# user doesn't have access to any of the instances
296-
context = 'User has no access to any instance'
297-
authentication.abort_request(user=user, context=context)
298-
299-
# Filter instances among instances in authorized_instances
291+
valid_instances = []
300292
if name:
301-
valid_instances = [i for i in authorized_instances if i.name == name]
302-
elif lon and lat:
303-
valid_instances = self._all_keys_of_coord_in_instances(authorized_instances, lon, lat)
304-
elif object_id:
305-
valid_instances = self._find_coverage_by_object_id_in_instances(authorized_instances, object_id)
293+
# Requests with a coverage
294+
available_instance = self.instances[name]
295+
if authentication.has_access(available_instance.name, abort=False, user=user, api=api):
296+
valid_instances = [self.instances[name]]
306297
else:
307-
valid_instances = authorized_instances
298+
# Requests without any coverage
299+
# fetch all the authorized instances (free + private) using cached function has_access()
300+
authorized_instances = self._get_authorized_instances(user, api)
301+
if not authorized_instances:
302+
# user doesn't have access to any of the instances
303+
context = 'User has no access to any instance'
304+
authentication.abort_request(user=user, context=context)
305+
306+
if lon and lat:
307+
valid_instances = self._all_keys_of_coord_in_instances(authorized_instances, lon, lat)
308+
elif object_id:
309+
valid_instances = self._find_coverage_by_object_id_in_instances(authorized_instances, object_id)
310+
else:
311+
valid_instances = authorized_instances
308312

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

0 commit comments

Comments
 (0)