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

🐛♻️ web-api: fixes adding group member by user-name and some cleanup #6940

Merged
merged 12 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion api/specs/web-server/_projects_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
ServiceResourcesDict,
)
from models_library.generics import Envelope
from models_library.groups import GroupID
from models_library.projects import ProjectID
from models_library.projects_nodes_io import NodeID
from models_library.users import GroupID
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.projects._crud_handlers import ProjectPathParams
from simcore_service_webserver.projects._nodes_handlers import (
Expand Down
2 changes: 1 addition & 1 deletion api/specs/web-server/_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
WalletPaymentInitiated,
)
from models_library.generics import Envelope
from models_library.groups import GroupID
from models_library.rest_pagination import Page, PageQueryParameters
from models_library.users import GroupID
from models_library.wallets import WalletID
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.wallets._groups_api import WalletGroupGet
Expand Down
13 changes: 13 additions & 0 deletions packages/common-library/src/common_library/groups_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import enum


class GroupType(enum.Enum):
"""
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
everyone: the only group for all users
"""

STANDARD = "standard"
PRIMARY = "primary"
EVERYONE = "everyone"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import BaseModel

from ..groups import GroupID
from ..services import ServiceKey, ServiceVersion
from ..users import GroupID


class ServiceAccessRightsGet(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ..boot_options import BootOptions
from ..emails import LowerCaseEmailStr
from ..groups import GroupID
from ..services_access import ServiceAccessRights, ServiceGroupAccessRightsV2
from ..services_authoring import Author
from ..services_enums import ServiceType
Expand All @@ -18,7 +19,6 @@
)
from ..services_resources import ServiceResourcesDict
from ..services_types import ServiceKey, ServiceVersion
from ..users import GroupID
from ..utils.change_case import snake_to_camel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from models_library.basic_types import IDStr
from models_library.folders import FolderID
from models_library.groups import GroupID
from models_library.projects_access import AccessRights
from models_library.users import GroupID
from models_library.utils.common_validators import null_or_none_str_to_none_validator
from pydantic import ConfigDict, PositiveInt, field_validator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..access_rights import AccessRights
from ..basic_types import IDStr
from ..folders import FolderID
from ..users import GroupID
from ..groups import GroupID
from ..utils.common_validators import null_or_none_str_to_none_validator
from ..workspaces import WorkspaceID
from ._base import InputSchema, OutputSchema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..basic_types import IDStr
from ..users import GroupID, UserID
from ..groups import GroupID
from ..users import UserID


class SocketIORoomStr(IDStr):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import ConfigDict, Field, HttpUrl, ValidationInfo, field_validator

from ..basic_types import AmountDecimal, IDStr, NonNegativeDecimal
from ..users import GroupID
from ..groups import GroupID
from ..wallets import WalletID, WalletStatus
from ._base import InputSchema, OutputSchema

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import NamedTuple

from models_library.basic_types import IDStr
from models_library.users import GroupID
from models_library.groups import GroupID
from models_library.workspaces import WorkspaceID
from pydantic import ConfigDict, PositiveInt

Expand Down
2 changes: 1 addition & 1 deletion packages/models-library/src/models_library/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, HttpUrl, field_validator
from pydantic.types import NonNegativeInt

from .users import GroupID
from .groups import GroupID
from .utils.common_validators import create_enums_pre_validator
from .utils.enums import StrAutoEnum

Expand Down
3 changes: 2 additions & 1 deletion packages/models-library/src/models_library/folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
)

from .access_rights import AccessRights
from .users import GroupID, UserID
from .groups import GroupID
from .users import UserID
from .utils.enums import StrAutoEnum
from .workspaces import WorkspaceID

Expand Down
23 changes: 6 additions & 17 deletions packages/models-library/src/models_library/groups.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
import enum
from typing import Annotated, Final, NamedTuple, TypeAlias

from common_library.basic_types import DEFAULT_FACTORY
from common_library.groups_enums import GroupType as GroupType
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
from pydantic.types import PositiveInt
from typing_extensions import TypedDict

from .basic_types import IDStr
from .users import GroupID, UserID
from .users import UserID
from .utils.common_validators import create_enums_pre_validator

EVERYONE_GROUP_ID: Final[int] = 1

GroupID: TypeAlias = PositiveInt

__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
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
everyone: the only group for all users
"""

STANDARD = "standard"
PRIMARY = "primary"
EVERYONE = "everyone"
__all__: tuple[str, ...] = ("GroupType",)


class Group(BaseModel):
gid: PositiveInt
name: str
description: str
group_type: Annotated[GroupTypeInModel, Field(alias="type")]
group_type: Annotated[GroupType, Field(alias="type")]
thumbnail: str | None

inclusion_rules: Annotated[
Expand All @@ -43,7 +32,7 @@ class Group(BaseModel):
] = DEFAULT_FACTORY

_from_equivalent_enums = field_validator("group_type", mode="before")(
create_enums_pre_validator(GroupTypeInModel)
create_enums_pre_validator(GroupType)
)

model_config = ConfigDict(populate_by_name=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pydantic import BaseModel, ConfigDict, Field

from .users import GroupID
from .groups import GroupID
from .utils.change_case import snake_to_camel


Expand Down
1 change: 0 additions & 1 deletion packages/models-library/src/models_library/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

UserID: TypeAlias = PositiveInt
UserNameID: TypeAlias = IDStr
GroupID: TypeAlias = PositiveInt


FirstNameStr: TypeAlias = Annotated[
Expand Down
3 changes: 2 additions & 1 deletion packages/models-library/src/models_library/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
)

from .access_rights import AccessRights
from .users import GroupID, UserID
from .groups import GroupID
from .users import UserID
from .utils.enums import StrAutoEnum

WorkspaceID: TypeAlias = PositiveInt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import pytest
from faker import Faker
from models_library.api_schemas_webserver.socketio import SocketIORoomStr
from models_library.users import GroupID, UserID
from models_library.groups import GroupID
from models_library.users import UserID


@pytest.fixture
Expand Down
3 changes: 2 additions & 1 deletion packages/notifications-library/tests/with_db/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import pytest
import sqlalchemy as sa
from models_library.basic_types import IDStr
from models_library.groups import GroupID
from models_library.products import ProductName
from models_library.users import GroupID, UserID
from models_library.users import UserID
from notifications_library._templates import get_default_named_templates
from pydantic import validate_call
from simcore_postgres_database.models.jinja2_templates import jinja2_templates
Expand Down
1 change: 1 addition & 0 deletions packages/postgres-database/requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
--requirement _base.txt
--requirement _migration.txt

simcore-common-library @ ../common-library/
pcrespov marked this conversation as resolved.
Show resolved Hide resolved
simcore-postgres-database @ .
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@
- Groups have a ID, name and a list of users that belong to the group
"""

import enum

import sqlalchemy as sa
from common_library.groups_enums import GroupType
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.sql import func

from ._common import RefActions
from .base import metadata


class GroupType(enum.Enum):
"""
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
everyone: the only group for all users
"""

STANDARD = "standard"
PRIMARY = "primary"
EVERYONE = "everyone"

__all__: tuple[str, ...] = ("GroupType",)

groups = sa.Table(
"groups",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sqlalchemy as sa
from aiohttp import web
from models_library.users import GroupID
from models_library.groups import GroupID
from models_library.workspaces import WorkspaceID
from simcore_postgres_database.models.workspaces_access_rights import (
workspaces_access_rights,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
WalletGetWithAvailableCredits as _WalletGetWithAvailableCredits,
)
from models_library.basic_types import IDStr, NonNegativeDecimal
from models_library.groups import GroupID
from models_library.resource_tracker import (
PricingPlanClassification,
PricingPlanId,
PricingUnitId,
UnitExtraInfo,
)
from models_library.users import GroupID
from models_library.wallets import WalletID, WalletStatus
from pydantic import (
BaseModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from models_library.api_schemas_catalog.services_specifications import (
ServiceSpecifications,
)
from models_library.groups import GroupAtDB, GroupTypeInModel
from models_library.groups import GroupAtDB, GroupID, GroupType
from models_library.products import ProductName
from models_library.services import ServiceKey, ServiceVersion
from models_library.users import GroupID, UserID
from models_library.users import UserID
from psycopg2.errors import ForeignKeyViolation
from pydantic import PositiveInt, TypeAdapter, ValidationError
from simcore_postgres_database.utils_services import create_select_latest_services_query
Expand Down Expand Up @@ -597,16 +597,16 @@ async def get_service_specifications(
continue
# filter by group type
group = gid_to_group_map[row.gid]
if (group.group_type == GroupTypeInModel.STANDARD) and _is_newer(
if (group.group_type == GroupType.STANDARD) and _is_newer(
teams_specs.get(db_service_spec.gid),
db_service_spec,
):
teams_specs[db_service_spec.gid] = db_service_spec
elif (group.group_type == GroupTypeInModel.EVERYONE) and _is_newer(
elif (group.group_type == GroupType.EVERYONE) and _is_newer(
everyone_specs, db_service_spec
):
everyone_specs = db_service_spec
elif (group.group_type == GroupTypeInModel.PRIMARY) and _is_newer(
elif (group.group_type == GroupType.PRIMARY) and _is_newer(
primary_specs, db_service_spec
):
primary_specs = db_service_spec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from models_library.api_schemas_catalog.services_specifications import (
ServiceSpecifications,
)
from models_library.groups import GroupID
from models_library.services import ServiceKey, ServiceVersion
from models_library.users import GroupID
from pydantic import ConfigDict


Expand Down
2 changes: 1 addition & 1 deletion services/migration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ WORKDIR /build/packages/postgres-database

# install only base 3rd party dependencies
RUN \
--mount=type=bind,source=packages/postgres-database,target=/build/packages/postgres-database,rw \
--mount=type=bind,source=packages,target=/build/packages,rw \
--mount=type=cache,target=/root/.cache/uv \
uv pip install \
--requirement requirements/prod.txt \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sqlalchemy as sa
from models_library.api_schemas_webserver.wallets import PaymentID
from models_library.users import GroupID, UserID
from models_library.groups import GroupID
from models_library.users import UserID
from simcore_postgres_database.models.payments_transactions import payments_transactions
from simcore_postgres_database.models.products import products
from simcore_postgres_database.models.users import users
Expand Down
2 changes: 1 addition & 1 deletion services/payments/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest
import simcore_service_payments
from faker import Faker
from models_library.users import GroupID
from models_library.groups import GroupID
from pydantic import TypeAdapter
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from pytest_simcore.helpers.typing_env import EnvVarsDict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import pytest
from fastapi import FastAPI
from models_library.users import GroupID, UserID
from models_library.groups import GroupID
from models_library.users import UserID
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
from pytest_simcore.helpers.postgres_tools import insert_and_get_row_lifespan
from pytest_simcore.helpers.typing_env import EnvVarsDict
Expand Down
3 changes: 2 additions & 1 deletion services/payments/tests/unit/test_services_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
)
from models_library.api_schemas_webserver.socketio import SocketIORoomStr
from models_library.api_schemas_webserver.wallets import PaymentTransaction
from models_library.users import GroupID, UserID
from models_library.groups import GroupID
from models_library.users import UserID
from pydantic import TypeAdapter
from pytest_mock import MockerFixture
from pytest_simcore.helpers.faker_factories import random_payment_transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
import sqlalchemy as sa
from aiopg.sa.connection import SAConnection
from aiopg.sa.result import ResultProxy, RowProxy
from models_library.groups import GroupID
from models_library.projects import ProjectID
from models_library.projects_nodes_io import StorageFileID
from models_library.users import GroupID, UserID
from models_library.users import UserID
from simcore_postgres_database.models.project_to_groups import project_to_groups
from simcore_postgres_database.models.projects import projects
from simcore_postgres_database.models.workspaces_access_rights import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
FolderScope,
UserFolderAccessRightsDB,
)
from models_library.groups import GroupID
from models_library.products import ProductName
from models_library.projects import ProjectID
from models_library.rest_ordering import OrderBy, OrderDirection
from models_library.users import GroupID, UserID
from models_library.users import UserID
from models_library.workspaces import WorkspaceID, WorkspaceQuery, WorkspaceScope
from pydantic import NonNegativeInt
from simcore_postgres_database.models.folders_v2 import folders_v2
Expand Down
Loading
Loading