From e8f79d3ea8047883e65d34170ee5c871614b9d6d Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:33:59 +0100 Subject: [PATCH 1/9] fixes @odeimaiz issue --- .../src/simcore_service_webserver/groups/_groups_api.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/groups/_groups_api.py b/services/web/server/src/simcore_service_webserver/groups/_groups_api.py index 9b9e712df54..18491ec60bf 100644 --- a/services/web/server/src/simcore_service_webserver/groups/_groups_api.py +++ b/services/web/server/src/simcore_service_webserver/groups/_groups_api.py @@ -258,14 +258,11 @@ async def add_user_in_group( ) new_by_user_id = user.id - if not new_by_user_id: - msg = "Missing new user in arguments" - raise GroupsError(msg=msg) - return await _groups_db.add_new_user_in_group( app, user_id=user_id, group_id=group_id, new_user_id=new_by_user_id, + new_user_name=new_by_user_name, access_rights=access_rights, ) From 9d3185df36dfaae8c65c6181a369f969c5395e8a Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:39:28 +0100 Subject: [PATCH 2/9] adds tests --- .../with_dbs/01/groups/test_groups_handlers_crud.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/web/server/tests/unit/with_dbs/01/groups/test_groups_handlers_crud.py b/services/web/server/tests/unit/with_dbs/01/groups/test_groups_handlers_crud.py index 5adaf33d9af..684f8726089 100644 --- a/services/web/server/tests/unit/with_dbs/01/groups/test_groups_handlers_crud.py +++ b/services/web/server/tests/unit/with_dbs/01/groups/test_groups_handlers_crud.py @@ -85,7 +85,7 @@ async def test_list_user_groups_and_try_modify_organizations( key=by_gid, ) == sorted(standard_groups, key=by_gid) - for group in standard_groups: + for i, group in enumerate(standard_groups): # try to delete a group url = client.app.router["delete_group"].url_for(gid=f"{group['gid']}") response = await client.delete(f"{url}") @@ -93,7 +93,15 @@ async def test_list_user_groups_and_try_modify_organizations( # try to add some user in the group url = client.app.router["add_group_user"].url_for(gid=f"{group['gid']}") - response = await client.post(f"{url}", json={"uid": logged_user["id"]}) + + if i % 2 == 0: + # by user-id + params = {"uid": logged_user["id"]} + else: + # by user name + params = {"userName": logged_user["name"]} + + response = await client.post(f"{url}", json=params) await assert_status(response, status.HTTP_403_FORBIDDEN) # try to modify the user in the group From 358d83d7d4cb8c666689a4641674082a1f927d81 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:48:34 +0100 Subject: [PATCH 3/9] types --- .../models_library/api_schemas_webserver/groups.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/models-library/src/models_library/api_schemas_webserver/groups.py b/packages/models-library/src/models_library/api_schemas_webserver/groups.py index d595447c3d3..9439d0ba371 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/groups.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/groups.py @@ -14,16 +14,16 @@ model_validator, ) -from ..basic_types import IDStr from ..emails import LowerCaseEmailStr from ..groups import ( AccessRightsDict, Group, + GroupID, GroupMember, StandardGroupCreate, StandardGroupUpdate, ) -from ..users import UserID +from ..users import UserID, UserNameID from ..utils.common_validators import create__check_only_one_is_set__root_validator from ._base import InputSchema, OutputSchema @@ -55,7 +55,7 @@ class GroupAccessRights(BaseModel): class GroupGet(OutputSchema): - gid: int = Field(..., description="the group ID") + gid: GroupID = Field(..., description="the group ID") label: str = Field(..., description="the group name") description: str = Field(..., description="the group description") thumbnail: AnyUrl | None = Field( @@ -229,11 +229,11 @@ class GroupUserGet(BaseModel): # Identifiers id: Annotated[ - str | None, Field(description="the user id", coerce_numbers_to_str=True) + UserID | None, Field(description="the user id", coerce_numbers_to_str=True) ] = None - user_name: Annotated[IDStr, Field(alias="userName")] + user_name: Annotated[UserNameID, Field(alias="userName")] gid: Annotated[ - str | None, + GroupID | None, Field(description="the user primary gid", coerce_numbers_to_str=True), ] = None @@ -296,7 +296,7 @@ class GroupUserAdd(InputSchema): """ uid: UserID | None = None - user_name: Annotated[IDStr | None, Field(alias="userName")] = None + user_name: Annotated[UserNameID | None, Field(alias="userName")] = None email: Annotated[ LowerCaseEmailStr | None, Field( From 46e5fd773586dda54d96f0e1a205be7d9c3a48f1 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:48:53 +0100 Subject: [PATCH 4/9] fixes OAS --- .../server/src/simcore_service_webserver/api/v0/openapi.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml index fe6f65828b9..b95c19d9845 100644 --- a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml +++ b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml @@ -10033,8 +10033,10 @@ components: properties: gid: type: integer + exclusiveMinimum: true title: Gid description: the group ID + minimum: 0 label: type: string title: Label From d19ecda9df13410c4fc386599f579da30dd4a18b Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:50:13 +0100 Subject: [PATCH 5/9] =?UTF-8?q?services/webserver=20api=20version:=200.49.?= =?UTF-8?q?0=20=E2=86=92=200.50.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/web/server/VERSION | 2 +- services/web/server/setup.cfg | 2 +- .../server/src/simcore_service_webserver/api/v0/openapi.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/web/server/VERSION b/services/web/server/VERSION index 5c4503b7043..564edf82ddf 100644 --- a/services/web/server/VERSION +++ b/services/web/server/VERSION @@ -1 +1 @@ -0.49.0 +0.50.0 diff --git a/services/web/server/setup.cfg b/services/web/server/setup.cfg index 0e40e2535ee..9a74fe46b3d 100644 --- a/services/web/server/setup.cfg +++ b/services/web/server/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.49.0 +current_version = 0.50.0 commit = True message = services/webserver api version: {current_version} → {new_version} tag = False diff --git a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml index b95c19d9845..5d889be34af 100644 --- a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml +++ b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml @@ -2,7 +2,7 @@ openapi: 3.1.0 info: title: simcore-service-webserver description: Main service with an interface (http-API & websockets) to the web front-end - version: 0.49.0 + version: 0.50.0 servers: - url: '' description: webserver From eb95f24379c70e9bb219a556c580d4bf548c2fe2 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:56:22 +0100 Subject: [PATCH 6/9] fixes OAS --- .../src/models_library/api_schemas_webserver/groups.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/models-library/src/models_library/api_schemas_webserver/groups.py b/packages/models-library/src/models_library/api_schemas_webserver/groups.py index 9439d0ba371..fcf89919b9b 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/groups.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/groups.py @@ -228,13 +228,11 @@ class GroupUserGet(BaseModel): # OutputSchema # Identifiers - id: Annotated[ - UserID | None, Field(description="the user id", coerce_numbers_to_str=True) - ] = None + id: Annotated[UserID | None, Field(description="the user's id")] = None user_name: Annotated[UserNameID, Field(alias="userName")] gid: Annotated[ GroupID | None, - Field(description="the user primary gid", coerce_numbers_to_str=True), + Field(description="the user primary gid"), ] = None # Private Profile From 694f93263129c1edb86d82a5ea68b7babd7fb4eb Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:56:48 +0100 Subject: [PATCH 7/9] update oas --- .../src/simcore_service_webserver/api/v0/openapi.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml index 5d889be34af..d27cbd9537e 100644 --- a/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml +++ b/services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml @@ -10118,10 +10118,12 @@ components: properties: id: anyOf: - - type: string + - type: integer + exclusiveMinimum: true + minimum: 0 - type: 'null' title: Id - description: the user id + description: the user's id userName: type: string maxLength: 100 @@ -10129,7 +10131,9 @@ components: title: Username gid: anyOf: - - type: string + - type: integer + exclusiveMinimum: true + minimum: 0 - type: 'null' title: Gid description: the user primary gid From 85ac82e817b765e180d693ae89c148f41058e7d4 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:25:24 +0100 Subject: [PATCH 8/9] fixes mypy --- packages/models-library/src/models_library/groups.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/models-library/src/models_library/groups.py b/packages/models-library/src/models_library/groups.py index e79928574a6..368f01523ea 100644 --- a/packages/models-library/src/models_library/groups.py +++ b/packages/models-library/src/models_library/groups.py @@ -13,6 +13,9 @@ EVERYONE_GROUP_ID: Final[int] = 1 +__all__: tuple[str, ...] = ("GroupID",) + + class GroupTypeInModel(str, enum.Enum): """ standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group From 394d02a3c7354c5a181817c67fbaa67f56e2b143 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:00:19 +0100 Subject: [PATCH 9/9] fixes tsts --- .../src/models_library/api_schemas_webserver/groups.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/models-library/src/models_library/api_schemas_webserver/groups.py b/packages/models-library/src/models_library/api_schemas_webserver/groups.py index fcf89919b9b..3b2b77199fb 100644 --- a/packages/models-library/src/models_library/api_schemas_webserver/groups.py +++ b/packages/models-library/src/models_library/api_schemas_webserver/groups.py @@ -2,6 +2,7 @@ from typing import Annotated, Any, Self, TypeVar from common_library.basic_types import DEFAULT_FACTORY +from models_library.groups import EVERYONE_GROUP_ID from pydantic import ( AnyHttpUrl, AnyUrl, @@ -114,7 +115,7 @@ def from_model(cls, group: Group, access_rights: AccessRightsDict) -> Self: "accessRights": {"read": True, "write": False, "delete": False}, }, { - "gid": "0", + "gid": "1", "label": "All", "description": "Open to all users", "accessRights": {"read": True, "write": True, "delete": True}, @@ -214,7 +215,7 @@ class MyGroupsGet(OutputSchema): }, ], "all": { - "gid": "0", + "gid": EVERYONE_GROUP_ID, "label": "All", "description": "Open to all users", "accessRights": {"read": True, "write": False, "delete": False},