17
17
CatalogForbiddenError ,
18
18
CatalogItemNotFoundError ,
19
19
)
20
+ from simcore_service_catalog .db .repositories .groups import GroupsRepository
20
21
21
22
from ..db .repositories .services import ServicesRepository
22
23
from ..models .services_db import (
@@ -341,7 +342,7 @@ async def check_for_service(
341
342
342
343
async def batch_get_my_services (
343
344
repo : ServicesRepository ,
344
- director_api : DirectorApi ,
345
+ groups_repo : GroupsRepository ,
345
346
* ,
346
347
product_name : ProductName ,
347
348
user_id : UserID ,
@@ -357,45 +358,67 @@ async def batch_get_my_services(
357
358
key_versions = ids , product_name = product_name
358
359
)
359
360
361
+ user_groups = await groups_repo .list_user_groups (user_id = user_id )
362
+ my_group_ids = {g .gid for g in user_groups }
363
+
360
364
my_services = []
361
365
for service_key , service_version in ids :
362
366
access_rights = services_access_rights .get ((service_key , service_version ), [])
367
+
363
368
my_access_rights = {
364
- "read " : any ( ar . execute_access for ar in access_rights ) ,
365
- "write" : any ( ar . write_access for ar in access_rights ) ,
369
+ "execute " : False ,
370
+ "write" : False ,
366
371
}
367
372
368
- service = await repo .get_service_with_history (
373
+ for ar in access_rights :
374
+ if ar .gid in my_group_ids :
375
+ my_access_rights ["execute" ] |= ar .execute_access
376
+ my_access_rights ["write" ] |= ar .write_access
377
+
378
+ service_db = await repo .get_service (
369
379
product_name = product_name ,
370
- user_id = user_id ,
371
380
key = service_key ,
372
381
version = service_version ,
373
382
)
383
+ assert service_db # nosec
374
384
375
- if service :
376
- service_manifest = await manifest . get_service (
377
- key = service_key ,
378
- version = service_version ,
379
- director_client = director_api ,
385
+ owner = service_db . owner
386
+ if not owner :
387
+ # TODO: raise error to indicate that no owner is registered for a given service
388
+ owner = next (
389
+ ar . gid for ar in access_rights if ar . write_access and ar . execute_access
380
390
)
381
391
382
- compatibility_map = await evaluate_service_compatibility_map (
383
- repo ,
384
- product_name = product_name ,
385
- user_id = user_id ,
386
- service_release_history = service .history ,
387
- )
392
+ assert owner is not None # nosec
388
393
389
- my_services .append (
390
- MyServiceGet (
391
- ** _db_to_api_model (
392
- service_db = service ,
393
- access_rights_db = access_rights ,
394
- service_manifest = service_manifest ,
395
- compatibility_map = compatibility_map ,
396
- ).model_dump (),
397
- my_access_rights = my_access_rights ,
394
+ compatibility_map = {}
395
+ if my_access_rights != {"execute" : False , "write" : False }:
396
+ history = await repo .get_service_history (
397
+ product_name = product_name , user_id = user_id , key = service_key
398
+ )
399
+ if history :
400
+ compatibility_map = await evaluate_service_compatibility_map (
401
+ repo ,
402
+ product_name = product_name ,
403
+ user_id = user_id ,
404
+ service_release_history = history ,
398
405
)
406
+
407
+ my_services .append (
408
+ MyServiceGet (
409
+ key = service_db .key ,
410
+ release = ServiceRelease .model_construct (
411
+ version = service_db .version ,
412
+ version_display = service_db .version_display ,
413
+ released = service_db .created ,
414
+ retired = service_db .deprecated ,
415
+ compatibility = compatibility_map .get (service_db .version ),
416
+ ),
417
+ owner = owner ,
418
+ my_access_rights = my_access_rights ,
399
419
)
420
+ )
421
+
422
+ # TODO: else error
400
423
401
424
return my_services
0 commit comments