1010)
1111from models_library .api_schemas_webserver .users import MyFunctionPermissionsGet
1212from models_library .functions import (
13+ FunctionAccessRights ,
1314 FunctionClass ,
1415 FunctionID ,
1516 RegisteredProjectFunction ,
4950routes = web .RouteTableDef ()
5051
5152
52- async def _build_function_access_rights_dict (
53+ async def _build_function_access_rights (
5354 app : web .Application ,
5455 user_id : UserID ,
5556 product_name : ProductName ,
5657 function_id : FunctionID ,
57- ) -> dict [ str , Any ] :
58+ ) -> FunctionAccessRights :
5859 access_rights = await _functions_service .get_function_user_permissions (
5960 app = app ,
6061 user_id = user_id ,
6162 product_name = product_name ,
6263 function_id = function_id ,
6364 )
6465
65- return {
66- "access_rights" : access_rights .model_dump (),
67- }
66+ return FunctionAccessRights (
67+ read = access_rights .read ,
68+ write = access_rights .write ,
69+ execute = access_rights .execute ,
70+ )
6871
6972
7073async def _build_project_function_extras_dict (
@@ -84,6 +87,23 @@ async def _build_project_function_extras_dict(
8487 }
8588
8689
90+ async def _build_solver_function_extras_dict (
91+ app : web .Application ,
92+ * ,
93+ function : RegisteredSolverFunction ,
94+ ) -> dict [str , Any ]:
95+ services_metadata = await _services_metadata_service .get_service_metadata (
96+ app ,
97+ key = function .solver_key ,
98+ version = function .solver_version ,
99+ )
100+ return {
101+ "thumbnail" : (
102+ f"{ services_metadata .thumbnail } " if services_metadata .thumbnail else None
103+ ),
104+ }
105+
106+
87107async def _build_function_extras (
88108 app : web .Application , user_id : UserID , * , function : RegisteredFunction
89109) -> dict [str , Any ]:
@@ -104,23 +124,6 @@ async def _build_function_extras(
104124 return extras
105125
106126
107- async def _build_solver_function_extras_dict (
108- app : web .Application ,
109- * ,
110- function : RegisteredSolverFunction ,
111- ) -> dict [str , Any ]:
112- services_metadata = await _services_metadata_service .get_service_metadata (
113- app ,
114- key = function .solver_key ,
115- version = function .solver_version ,
116- )
117- return {
118- "thumbnail" : (
119- f"{ services_metadata .thumbnail } " if services_metadata .thumbnail else None
120- ),
121- }
122-
123-
124127@routes .post (f"/{ VTAG } /functions" , name = "register_function" )
125128@login_required
126129@handle_rest_requests_exceptions
@@ -188,7 +191,7 @@ async def list_functions(request: web.Request) -> web.Response:
188191 for function in functions
189192 if function .function_class == FunctionClass .PROJECT
190193 ]
191- projects_cache = await _projects_service .batch_get_projects (
194+ projects_cache | = await _projects_service .batch_get_projects (
192195 request .app ,
193196 project_uuids = project_uuids ,
194197 )
@@ -200,14 +203,14 @@ async def list_functions(request: web.Request) -> web.Response:
200203 for function in functions
201204 if function .function_class == FunctionClass .SOLVER
202205 ]
203- service_metadata_cache = (
206+ service_metadata_cache | = (
204207 await _services_metadata_service .batch_get_service_metadata (
205208 app = request .app , keys_and_versions = service_keys_and_versions
206209 )
207210 )
208211
209212 for function in functions :
210- access_rights = await _build_function_access_rights_dict (
213+ access_rights = await _build_function_access_rights (
211214 request .app ,
212215 user_id = req_ctx .user_id ,
213216 product_name = req_ctx .product_name ,
@@ -239,7 +242,7 @@ async def list_functions(request: web.Request) -> web.Response:
239242
240243 chunk .append (
241244 TypeAdapter (RegisteredFunctionGet ).validate_python (
242- function .model_dump () | access_rights | extras
245+ function .model_dump () | { " access_rights" : access_rights , ** extras }
243246 )
244247 )
245248
@@ -278,7 +281,7 @@ async def get_function(request: web.Request) -> web.Response:
278281 product_name = req_ctx .product_name ,
279282 )
280283
281- access_rights = await _build_function_access_rights_dict (
284+ access_rights = await _build_function_access_rights (
282285 request .app ,
283286 user_id = req_ctx .user_id ,
284287 product_name = req_ctx .product_name ,
@@ -293,7 +296,7 @@ async def get_function(request: web.Request) -> web.Response:
293296
294297 return envelope_json_response (
295298 TypeAdapter (RegisteredFunctionGet ).validate_python (
296- function .model_dump () | access_rights | extras
299+ function .model_dump () | { " access_rights" : access_rights , ** extras }
297300 )
298301 )
299302
@@ -326,7 +329,7 @@ async def update_function(request: web.Request) -> web.Response:
326329 function = function_update ,
327330 )
328331
329- access_rights = await _build_function_access_rights_dict (
332+ access_rights = await _build_function_access_rights (
330333 request .app ,
331334 user_id = req_ctx .user_id ,
332335 product_name = req_ctx .product_name ,
@@ -341,7 +344,7 @@ async def update_function(request: web.Request) -> web.Response:
341344
342345 return envelope_json_response (
343346 TypeAdapter (RegisteredFunctionGet ).validate_python (
344- function .model_dump () | access_rights | extras
347+ function .model_dump () | { " access_rights" : access_rights , ** extras }
345348 )
346349 )
347350
0 commit comments