Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixes web-api: issues on groups entrypoints #6939

Merged
merged 10 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions packages/models-library/src/models_library/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion services/web/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.49.0
0.50.0
2 changes: 1 addition & 1 deletion services/web/server/setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
openapi: 3.1.0

Check failure on line 1 in services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

View workflow job for this annotation

GitHub Actions / check OAS' are up to date

Error when checking services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml
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
Expand Down Expand Up @@ -10033,8 +10033,10 @@
properties:
gid:
type: integer
exclusiveMinimum: true
title: Gid
description: the group ID
minimum: 0
label:
type: string
title: Label
Expand Down Expand Up @@ -10116,18 +10118,22 @@
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
minLength: 1
title: Username
gid:
anyOf:
- type: string
- type: integer
exclusiveMinimum: true
minimum: 0
- type: 'null'
title: Gid
description: the user primary gid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,23 @@ 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):
pcrespov marked this conversation as resolved.
Show resolved Hide resolved
# try to delete a group
url = client.app.router["delete_group"].url_for(gid=f"{group['gid']}")
response = await client.delete(f"{url}")
await assert_status(response, status.HTTP_403_FORBIDDEN)

# 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
Expand Down
Loading