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..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, @@ -14,16 +15,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 +56,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( @@ -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}, @@ -228,13 +229,11 @@ class GroupUserGet(BaseModel): # OutputSchema # Identifiers - id: Annotated[ - str | None, Field(description="the user id", coerce_numbers_to_str=True) - ] = None - user_name: Annotated[IDStr, Field(alias="userName")] + id: Annotated[UserID | None, Field(description="the user's id")] = None + user_name: Annotated[UserNameID, Field(alias="userName")] gid: Annotated[ - str | None, - Field(description="the user primary gid", coerce_numbers_to_str=True), + GroupID | None, + Field(description="the user primary gid"), ] = None # Private Profile @@ -296,7 +295,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( 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 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 fe6f65828b9..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 @@ -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 @@ -10033,8 +10033,10 @@ components: properties: gid: type: integer + exclusiveMinimum: true title: Gid description: the group ID + minimum: 0 label: type: string title: Label @@ -10116,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 @@ -10127,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 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, ) 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