@@ -288,23 +288,27 @@ def get_instances(self, name=None, lon=None, lat=None, object_id=None, api='ALL'
288
288
# Request without token or bad token makes a request exception and exits with a message
289
289
# get_user is cached hence access to database only once when cache expires.
290
290
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 = []
300
292
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 ]]
306
297
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
308
312
309
313
if not valid_instances :
310
314
# user doesn't have access to any of the instances
0 commit comments