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

♻️ Enhanced groups/organizations web-api specs and validation 🚨 #6640

Merged
merged 27 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixing tests
  • Loading branch information
pcrespov committed Nov 5, 2024
commit 7677692c045cd6f949116f1f1eec2698df1e70c0
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ class Config:


class GroupUserUpdate(InputSchema):
access_rights: GroupAccessRights | None = None
# NOTE: since it is a single item, it is required. Cannot
# update for the moment partial attributes e.g. {read: False}
access_rights: GroupAccessRights

class Config:
schema_extra: ClassVar[dict[str, Any]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,12 @@ async def update_user_in_group(
user_id: UserID,
gid: GroupID,
the_user_id_in_group: int,
new_values_for_user_in_group: dict,
access_rights: dict,
) -> dict[str, str]:
if not access_rights:
msg = f"Cannot update empty {access_rights}"
raise ValueError(msg)

# first check if the group exists
group: RowProxy = await _get_user_group(conn, user_id, gid)
check_group_permissions(group, user_id, gid, "write")
Expand All @@ -368,7 +372,7 @@ async def update_user_in_group(
conn, gid, the_user_id_in_group
)
# modify the user access rights
new_db_values = {"access_rights": new_values_for_user_in_group["accessRights"]}
new_db_values = {"access_rights": access_rights}
await conn.execute(
# pylint: disable=no-value-for-parameter
user_to_groups.update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async def list_groups(request: web.Request):

if product.group_id:
with suppress(GroupNotFoundError):
# Product is optional
my_group["product"] = await api.get_product_group_for_user(
app=request.app,
user_id=req_ctx.user_id,
Expand Down Expand Up @@ -260,10 +261,10 @@ async def update_group_user(request: web.Request):

user = await api.update_user_in_group(
request.app,
req_ctx.user_id,
path_params.gid,
path_params.uid,
update.dict(exclude_unset=True),
user_id=req_ctx.user_id,
gid=path_params.gid,
the_user_id_in_group=path_params.uid,
access_rights=update.access_rights.dict(),
)
assert parse_obj_as(GroupUserGet, user) is not None # nosec
return envelope_json_response(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ async def update_user_in_group(
user_id: UserID,
gid: GroupID,
the_user_id_in_group: int,
new_values_for_user_in_group: dict,
access_rights: dict,
) -> dict[str, str]:
async with get_database_engine(app).acquire() as conn:
return await _db.update_user_in_group(
conn,
user_id=user_id,
gid=gid,
the_user_id_in_group=the_user_id_in_group,
new_values_for_user_in_group=new_values_for_user_in_group,
access_rights=access_rights,
)


Expand Down
10 changes: 5 additions & 5 deletions services/web/server/tests/unit/with_dbs/01/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# pylint: disable=unused-argument
# pylint: disable=unused-variable

import random
from collections.abc import AsyncIterator, Callable
from contextlib import AsyncExitStack
from copy import deepcopy
Expand Down Expand Up @@ -160,7 +159,7 @@ async def test_list_groups(
)
response = await client.patch(
f"{url}",
json={"access_rights": {"read": True, "write": True, "delete": True}},
json={"accessRights": {"read": True, "write": True, "delete": True}},
)
await assert_status(response, status.HTTP_403_FORBIDDEN)

Expand Down Expand Up @@ -285,6 +284,7 @@ async def test_add_remove_users_from_group(
logged_user: UserInfoDict,
user_role: UserRole,
expected: ExpectedResponse,
faker: Faker,
):
assert client.app
new_group = {
Expand All @@ -295,7 +295,7 @@ async def test_add_remove_users_from_group(
}

# check that our group does not exist
url = client.app.router["get_group_users"].url_for(gid=new_group["gid"])
url = client.app.router["get_all_group_users"].url_for(gid=new_group["gid"])
assert f"{url}" == f"/{API_VTAG}/groups/{new_group['gid']}/users"
resp = await client.get(f"{url}")
data, error = await assert_status(resp, expected.not_found)
Expand Down Expand Up @@ -323,7 +323,7 @@ async def test_add_remove_users_from_group(
assert assigned_group["accessRights"] == _DEFAULT_GROUP_OWNER_ACCESS_RIGHTS

# check that our user is in the group of users
get_group_users_url = client.app.router["get_group_users"].url_for(
get_group_users_url = client.app.router["get_all_group_users"].url_for(
gid=f"{assigned_group['gid']}"
)
assert (
Expand All @@ -345,7 +345,7 @@ async def test_add_remove_users_from_group(
assert (
f"{add_group_user_url}" == f"/{API_VTAG}/groups/{assigned_group['gid']}/users"
)
num_new_users = random.randint(1, 10)
num_new_users = faker.random_int(1, 10)
created_users_list = []

async with AsyncExitStack() as users_stack:
Expand Down