Skip to content

Commit b2e7145

Browse files
committed
changed rest
1 parent b5df9cd commit b2e7145

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

api/specs/web-server/_projects_groups.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
ProjectPathParams,
1414
)
1515
from simcore_service_webserver.projects._controller.groups_rest import (
16+
ProjectShareAccepted,
1617
_ProjectsGroupsBodyParams,
1718
_ProjectsGroupsPathParams,
19+
_ProjectShare,
1820
)
1921
from simcore_service_webserver.projects._groups_service import ProjectGroupGet
2022

@@ -26,12 +28,17 @@
2628

2729
@router.post(
2830
"/projects/{project_id}:share",
29-
response_model=Envelope[ProjectGroupGet],
30-
status_code=status.HTTP_204_NO_CONTENT,
31+
response_model=Envelope[ProjectShareAccepted],
32+
status_code=status.HTTP_202_ACCEPTED,
33+
responses={
34+
status.HTTP_202_ACCEPTED: {
35+
"description": "The request to share the project has been accepted, but the actual sharing process has to be confirmd."
36+
}
37+
},
3138
)
3239
async def share_project(
3340
_path: Annotated[ProjectPathParams, Depends()],
34-
_body: _ProjectsGroupsBodyParams,
41+
_body: _ProjectShare,
3542
): ...
3643

3744

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
AnyUrl,
99
BaseModel,
1010
ConfigDict,
11+
EmailStr,
1112
Field,
13+
HttpUrl,
1214
TypeAdapter,
1315
ValidationError,
1416
field_validator,
@@ -383,3 +385,17 @@ class GroupUserUpdate(InputSchema):
383385
}
384386
}
385387
)
388+
389+
390+
class ProjectShare(InputSchema):
391+
sharee_email: EmailStr
392+
393+
# sharing access
394+
read: bool
395+
write: bool
396+
delete: bool
397+
398+
399+
class ProjectShareAccepted(OutputSchema):
400+
sharee_email: EmailStr
401+
confirmation_link: HttpUrl

services/web/server/src/simcore_service_webserver/projects/_controller/groups_rest.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import logging
22

33
from aiohttp import web
4-
from models_library.api_schemas_webserver._base import InputSchema
4+
from models_library.api_schemas_webserver.groups import (
5+
ProjectShare,
6+
ProjectShareAccepted,
7+
)
58
from models_library.basic_types import IDStr
69
from models_library.groups import GroupID
710
from models_library.projects import ProjectID
8-
from pydantic import BaseModel, ConfigDict, EmailStr, HttpUrl
11+
from pydantic import BaseModel, ConfigDict
912
from servicelib.aiohttp import status
1013
from servicelib.aiohttp.requests_validation import (
1114
parse_request_body_as,
1215
parse_request_path_parameters_as,
1316
)
1417
from servicelib.logging_utils import log_context
18+
from simcore_service_webserver.login._login_service import envelope_response
1519

1620
from ..._meta import api_version_prefix as VTAG
1721
from ...application_settings_utils import requires_dev_feature_enabled
@@ -30,18 +34,6 @@
3034
routes = web.RouteTableDef()
3135

3236

33-
class _ProjectShare(InputSchema):
34-
# TODO: move to models_library.api_schemas_webserver.groups together with the rest
35-
sharee_email: EmailStr
36-
37-
# sharing access
38-
read: bool
39-
write: bool
40-
delete: bool
41-
42-
model_config = ConfigDict(extra="forbid")
43-
44-
4537
@routes.post(f"/{VTAG}/projects/{{project_id}}:share", name="share_project")
4638
@requires_dev_feature_enabled
4739
@login_required
@@ -50,7 +42,7 @@ class _ProjectShare(InputSchema):
5042
async def share_project(request: web.Request):
5143
req_ctx = RequestContext.model_validate(request)
5244
path_params = parse_request_path_parameters_as(ProjectPathParams, request)
53-
body_params = await parse_request_body_as(_ProjectShare, request)
45+
body_params = await parse_request_body_as(ProjectShare, request)
5446

5547
with log_context(
5648
_logger,
@@ -79,15 +71,16 @@ async def share_project(request: web.Request):
7971
request, code=confirmation_code
8072
)
8173

82-
assert HttpUrl(confirmation_link) # nosec
83-
8474
_logger.debug(
8575
"Send email with confirmation link %s to %s ",
8676
confirmation_link,
8777
body_params.sharee_email,
8878
)
8979

90-
return web.json_response(status=status.HTTP_204_NO_CONTENT)
80+
return envelope_response(
81+
data=ProjectShareAccepted(confirmation_link=confirmation_link), # type: ignore
82+
status=status.HTTP_202_ACCEPTED,
83+
)
9184

9285

9386
class _ProjectsGroupsPathParams(BaseModel):

services/web/server/tests/unit/with_dbs/02/test_projects_groups_handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ async def test_share_project(
276276
"delete": False,
277277
},
278278
)
279-
await assert_status(resp, status.HTTP_204_NO_CONTENT)
279+
data, error = await assert_status(resp, status.HTTP_202_ACCEPTED)
280+
assert data["shareeEmail"] == "[email protected]"
281+
assert data["confirmationLink"]
282+
assert not error
280283

281284
# Verify that only logged_user["primary_gid"] has access to the project
282285
url = client.app.router["list_project_groups"].url_for(

0 commit comments

Comments
 (0)