2020from models_library .users import UserID
2121from simcore_postgres_database .errors import UniqueViolation
2222from simcore_postgres_database .models .users import users
23+ from simcore_postgres_database .utils import as_postgres_sql_query_str
2324from simcore_postgres_database .utils_products import execute_get_or_create_product_group
2425from simcore_postgres_database .utils_repos import (
2526 pass_or_acquire_connection ,
@@ -491,8 +492,8 @@ async def list_users_in_group(
491492 group_id : GroupID ,
492493) -> list [GroupMember ]:
493494 async with pass_or_acquire_connection (get_asyncpg_engine (app ), connection ) as conn :
494- # GET GROUP & caller access
495- result = await conn . execute (
495+ # GET GROUP & caller access-rights (if non PRIMARY)
496+ query = (
496497 sa .select (
497498 * _GROUP_COLUMNS ,
498499 user_to_groups .c .access_rights ,
@@ -503,29 +504,36 @@ async def list_users_in_group(
503504 ).join (users , users .c .id == user_to_groups .c .uid )
504505 )
505506 .where (
506- ((user_to_groups .c .uid == user_id ) & (user_to_groups .c .gid == group_id ))
507- | (
508- (groups .c .type == GroupType .PRIMARY )
509- & users .c .role .in_ ([r for r in UserRole if r > UserRole .GUEST ])
507+ (user_to_groups .c .gid == group_id )
508+ & (
509+ (user_to_groups .c .uid == user_id )
510+ | (
511+ (groups .c .type == GroupType .PRIMARY )
512+ & users .c .role .in_ ([r for r in UserRole if r > UserRole .GUEST ])
513+ )
510514 )
511515 )
512516 )
517+
518+ print (as_postgres_sql_query_str (query ))
519+
520+ result = await conn .execute (query )
513521 group_row = result .first ()
514522 if not group_row :
515523 raise GroupNotFoundError (gid = group_id )
516524
517525 # Drop access-rights if primary group
518- if group_row .type != GroupType .PRIMARY :
519- _check_group_permissions (
520- group_row , caller_id = user_id , group_id = group_id , permission = "read"
521- )
526+ if group_row .type == GroupType .PRIMARY :
522527 query = sa .select (
523528 * _group_user_cols (user_id ),
524- user_to_groups .c .access_rights ,
525529 )
526530 else :
531+ _check_group_permissions (
532+ group_row , caller_id = user_id , group_id = group_id , permission = "read"
533+ )
527534 query = sa .select (
528535 * _group_user_cols (user_id ),
536+ user_to_groups .c .access_rights ,
529537 )
530538
531539 # GET users
0 commit comments