Skip to content

Commit 4103b34

Browse files
feat: add functions set permissions endpoint
1 parent 3472e17 commit 4103b34

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

packages/models-library/src/models_library/api_schemas_webserver/functions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,9 @@ class ProjectFunctionToRegister(ProjectFunction, InputSchema): ...
149149

150150

151151
class RegisteredFunctionUpdate(FunctionUpdate, InputSchema): ...
152+
153+
154+
class FunctionGroupUpdate(InputSchema):
155+
read: bool
156+
write: bool
157+
execute: bool

services/web/server/src/simcore_service_webserver/functions/_controller/_functions_rest.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from aiohttp import web
44
from models_library.api_schemas_webserver.functions import (
55
Function,
6+
FunctionGroupUpdate,
67
FunctionToRegister,
78
RegisteredFunction,
89
RegisteredFunctionGet,
@@ -12,6 +13,7 @@
1213
from models_library.functions import (
1314
FunctionAccessRights,
1415
FunctionClass,
16+
FunctionGroupAccessRights,
1517
FunctionID,
1618
RegisteredProjectFunction,
1719
RegisteredSolverFunction,
@@ -41,6 +43,7 @@
4143
from ._functions_rest_exceptions import handle_rest_requests_exceptions
4244
from ._functions_rest_schemas import (
4345
FunctionGetQueryParams,
46+
FunctionGroupPathParams,
4447
FunctionPathParams,
4548
FunctionsListQueryParams,
4649
)
@@ -356,6 +359,43 @@ async def delete_function(request: web.Request) -> web.Response:
356359
return web.json_response(status=status.HTTP_204_NO_CONTENT)
357360

358361

362+
#
363+
# /functions/{function_id}/groups/*
364+
#
365+
366+
367+
@routes.put(
368+
f"/{VTAG}/functions/{{function_id}}/groups/{{group_id}}",
369+
name="update_function_group",
370+
)
371+
@login_required
372+
@permission_required("function.write")
373+
@handle_rest_requests_exceptions
374+
async def update_function_group(request: web.Request) -> web.Response:
375+
path_params = parse_request_path_parameters_as(FunctionGroupPathParams, request)
376+
function_id = path_params.function_id
377+
group_id = path_params.group_id
378+
379+
req_ctx = AuthenticatedRequestContext.model_validate(request)
380+
381+
function_group_update = FunctionGroupUpdate.model_validate(await request.json())
382+
383+
await _functions_service.set_function_group_permissions(
384+
request.app,
385+
user_id=req_ctx.user_id,
386+
product_name=req_ctx.product_name,
387+
function_id=function_id,
388+
permissions=FunctionGroupAccessRights(
389+
group_id=group_id,
390+
read=function_group_update.read,
391+
write=function_group_update.write,
392+
execute=function_group_update.execute,
393+
),
394+
)
395+
396+
return web.json_response(status=status.HTTP_202_ACCEPTED)
397+
398+
359399
#
360400
# /me/* endpoints
361401
#

services/web/server/src/simcore_service_webserver/functions/_controller/_functions_rest_schemas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from models_library.functions import FunctionID
2+
from models_library.groups import GroupID
23
from models_library.rest_pagination import PageQueryParameters
34
from pydantic import BaseModel, ConfigDict
45

@@ -12,6 +13,10 @@ class FunctionPathParams(BaseModel):
1213
model_config = ConfigDict(populate_by_name=True, extra="forbid")
1314

1415

16+
class FunctionGroupPathParams(FunctionPathParams):
17+
group_id: GroupID
18+
19+
1520
class _FunctionQueryParams(BaseModel):
1621
include_extras: bool = False
1722

0 commit comments

Comments
 (0)