|
5 | 5 | ServiceGetV2,
|
6 | 6 | ServiceUpdateV2,
|
7 | 7 | )
|
| 8 | +from models_library.groups import GroupID |
8 | 9 | from models_library.products import ProductName
|
9 | 10 | from models_library.rest_pagination import PageLimitInt
|
10 | 11 | from models_library.services_access import ServiceGroupAccessRightsV2
|
@@ -363,62 +364,67 @@ async def batch_get_my_services(
|
363 | 364 |
|
364 | 365 | my_services = []
|
365 | 366 | for service_key, service_version in ids:
|
366 |
| - access_rights = services_access_rights.get((service_key, service_version), []) |
367 |
| - |
368 |
| - my_access_rights = { |
369 |
| - "execute": False, |
370 |
| - "write": False, |
371 |
| - } |
372 | 367 |
|
| 368 | + # Evaluate user's access-rights to this service key:version |
| 369 | + access_rights = services_access_rights.get((service_key, service_version), []) |
| 370 | + my_access_rights = ServiceGroupAccessRightsV2(execute=False, write=False) |
373 | 371 | for ar in access_rights:
|
374 | 372 | if ar.gid in my_group_ids:
|
375 |
| - my_access_rights["execute"] |= ar.execute_access |
376 |
| - my_access_rights["write"] |= ar.write_access |
| 373 | + my_access_rights.execute |= ar.execute_access |
| 374 | + my_access_rights.write |= ar.write_access |
377 | 375 |
|
| 376 | + # Get service metadata |
378 | 377 | service_db = await repo.get_service(
|
379 | 378 | product_name=product_name,
|
380 | 379 | key=service_key,
|
381 | 380 | version=service_version,
|
382 | 381 | )
|
383 | 382 | assert service_db # nosec
|
384 | 383 |
|
385 |
| - owner = service_db.owner |
| 384 | + # Find service owner |
| 385 | + owner: GroupID | None = service_db.owner |
386 | 386 | if not owner:
|
387 |
| - # TODO: raise error to indicate that no owner is registered for a given service |
| 387 | + # NOTE can be more than one. Just get first. |
388 | 388 | owner = next(
|
389 | 389 | ar.gid for ar in access_rights if ar.write_access and ar.execute_access
|
390 | 390 | )
|
391 | 391 |
|
| 392 | + # TODO: raise error to indicate that no owner is registered for a given service |
392 | 393 | assert owner is not None # nosec
|
393 | 394 |
|
394 |
| - compatibility_map = {} |
395 |
| - if my_access_rights != {"execute": False, "write": False}: |
| 395 | + # Evaluate `compatibility` |
| 396 | + compatibility: Compatibility | None = None |
| 397 | + if my_access_rights.execute or my_access_rights.write: |
| 398 | + # TODO: add cache to this section that evals compatibility_map based on service_key |
| 399 | + |
| 400 | + # NOTE: that the service history might be different for each user |
| 401 | + # since access rights are defined on a k:v basis |
396 | 402 | history = await repo.get_service_history(
|
397 | 403 | product_name=product_name, user_id=user_id, key=service_key
|
398 | 404 | )
|
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, |
405 |
| - ) |
| 405 | + assert history # nosec |
| 406 | + |
| 407 | + compatibility_map = await evaluate_service_compatibility_map( |
| 408 | + repo, |
| 409 | + product_name=product_name, |
| 410 | + user_id=user_id, |
| 411 | + service_release_history=history, |
| 412 | + ) |
| 413 | + compatibility = compatibility_map.get(service_db.version) |
406 | 414 |
|
407 | 415 | my_services.append(
|
408 | 416 | MyServiceGet(
|
409 | 417 | key=service_db.key,
|
410 |
| - release=ServiceRelease.model_construct( |
| 418 | + release=ServiceRelease( |
411 | 419 | version=service_db.version,
|
412 | 420 | version_display=service_db.version_display,
|
413 | 421 | released=service_db.created,
|
414 | 422 | retired=service_db.deprecated,
|
415 |
| - compatibility=compatibility_map.get(service_db.version), |
| 423 | + compatibility=compatibility, |
416 | 424 | ),
|
417 | 425 | owner=owner,
|
418 | 426 | my_access_rights=my_access_rights,
|
419 | 427 | )
|
420 | 428 | )
|
421 | 429 |
|
422 |
| - # TODO: else error |
423 |
| - |
424 | 430 | return my_services
|
0 commit comments