3131from simcore_postgres_database .utils_users import generate_alternative_username
3232
3333from ..db .plugin import get_database_engine
34- from ..groups .models import convert_groups_db_to_schema
3534from ..login .storage import AsyncpgStorage , get_plugin_storage
3635from ..security .api import clean_auth_policy_cache
3736from . import _db
4746_logger = logging .getLogger (__name__ )
4847
4948
49+ _GROUPS_SCHEMA_TO_DB = {
50+ "gid" : "gid" ,
51+ "label" : "name" ,
52+ "description" : "description" ,
53+ "thumbnail" : "thumbnail" ,
54+ "accessRights" : "access_rights" ,
55+ "inclusionRules" : "inclusion_rules" ,
56+ }
57+
58+
59+ def _convert_groups_db_to_schema (
60+ db_row : RowProxy , * , prefix : str | None = "" , ** kwargs
61+ ) -> dict :
62+ converted_dict = {
63+ k : db_row [f"{ prefix } { v } " ]
64+ for k , v in _GROUPS_SCHEMA_TO_DB .items ()
65+ if f"{ prefix } { v } " in db_row
66+ }
67+ converted_dict .update (** kwargs )
68+ return converted_dict
69+
70+
5071def _parse_as_user (user_id : Any ) -> UserID :
5172 try :
5273 return TypeAdapter (UserID ).validate_python (user_id )
@@ -64,7 +85,7 @@ async def get_user_profile(
6485
6586 engine = get_database_engine (app )
6687 user_profile : dict [str , Any ] = {}
67- user_primary_group = all_group = {}
88+ user_primary_group = everyone_group = {}
6889 user_standard_groups = []
6990 user_id = _parse_as_user (user_id )
7091
@@ -99,20 +120,20 @@ async def get_user_profile(
99120 assert user_profile ["id" ] == user_id # nosec
100121
101122 if row .groups_type == GroupType .EVERYONE :
102- all_group = convert_groups_db_to_schema (
123+ everyone_group = _convert_groups_db_to_schema (
103124 row ,
104125 prefix = "groups_" ,
105126 accessRights = row ["user_to_groups_access_rights" ],
106127 )
107128 elif row .groups_type == GroupType .PRIMARY :
108- user_primary_group = convert_groups_db_to_schema (
129+ user_primary_group = _convert_groups_db_to_schema (
109130 row ,
110131 prefix = "groups_" ,
111132 accessRights = row ["user_to_groups_access_rights" ],
112133 )
113134 else :
114135 user_standard_groups .append (
115- convert_groups_db_to_schema (
136+ _convert_groups_db_to_schema (
116137 row ,
117138 prefix = "groups_" ,
118139 accessRights = row ["user_to_groups_access_rights" ],
@@ -147,7 +168,7 @@ async def get_user_profile(
147168 groups = { # type: ignore[arg-type]
148169 "me" : user_primary_group ,
149170 "organizations" : user_standard_groups ,
150- "all" : all_group ,
171+ "all" : everyone_group ,
151172 },
152173 privacy = MyProfilePrivacyGet (
153174 hide_fullname = user_profile ["privacy_hide_fullname" ],
0 commit comments