Skip to content

Commit

Permalink
rename GroupTyoe
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 11, 2024
1 parent 5d8866f commit b0e3e8c
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 86 deletions.
2 changes: 1 addition & 1 deletion packages/common-library/src/common_library/groups_enums.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import enum


class GroupTypeEnum(enum.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)
Expand Down
8 changes: 4 additions & 4 deletions packages/models-library/src/models_library/groups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated, Final, NamedTuple, TypeAlias

from common_library.basic_types import DEFAULT_FACTORY
from common_library.groups_enums import GroupTypeEnum as GroupTypeEnum
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
Expand All @@ -14,14 +14,14 @@

GroupID: TypeAlias = PositiveInt

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


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

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

_from_equivalent_enums = field_validator("group_type", mode="before")(
create_enums_pre_validator(GroupTypeEnum)
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 @@ -6,7 +6,7 @@


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

Expand All @@ -27,7 +27,7 @@
sa.Column("description", sa.String, nullable=False, doc="Short description"),
sa.Column(
"type",
sa.Enum(GroupTypeEnum),
sa.Enum(GroupType),
nullable=False,
server_default="STANDARD",
doc="Classification of the group based on GroupType enum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aiopg.sa.connection import SAConnection
from aiopg.sa.result import RowProxy

from .models.groups import GroupTypeEnum, groups, user_to_groups
from .models.groups import GroupType, groups, user_to_groups
from .models.groups_extra_properties import groups_extra_properties
from .utils_models import FromRowMixin

Expand Down Expand Up @@ -44,9 +44,9 @@ async def _list_table_entries_ordered_by_group_type(
groups.c.type,
sa.case(
# NOTE: the ordering is important for the aggregation afterwards
(groups.c.type == GroupTypeEnum.EVERYONE, sa.literal(3)),
(groups.c.type == GroupTypeEnum.STANDARD, sa.literal(2)),
(groups.c.type == GroupTypeEnum.PRIMARY, sa.literal(1)),
(groups.c.type == GroupType.EVERYONE, sa.literal(3)),
(groups.c.type == GroupType.STANDARD, sa.literal(2)),
(groups.c.type == GroupType.PRIMARY, sa.literal(1)),
else_=sa.literal(4),
).label("type_order"),
)
Expand Down Expand Up @@ -124,10 +124,10 @@ async def get_aggregated_properties_for_user(
for row in rows:
group_extra_properties = GroupExtraProperties.from_row(row)
match row.type:
case GroupTypeEnum.PRIMARY:
case GroupType.PRIMARY:
# this always has highest priority
return group_extra_properties
case GroupTypeEnum.STANDARD:
case GroupType.STANDARD:
if merged_standard_extra_properties:
merged_standard_extra_properties = (
_merge_extra_properties_booleans(
Expand All @@ -137,7 +137,7 @@ async def get_aggregated_properties_for_user(
)
else:
merged_standard_extra_properties = group_extra_properties
case GroupTypeEnum.EVERYONE:
case GroupType.EVERYONE:
# if there are standard properties, they take precedence
return (
merged_standard_extra_properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sqlalchemy as sa

from ._protocols import AiopgConnection, DBConnection
from .models.groups import GroupTypeEnum, groups
from .models.groups import GroupType, groups
from .models.products import products

# NOTE: outside this module, use instead packages/models-library/src/models_library/users.py
Expand Down Expand Up @@ -57,7 +57,7 @@ async def execute_get_or_create_product_group(conn, product_name: str) -> int:
.values(
name=product_name,
description=f"{product_name} product group",
type=GroupTypeEnum.STANDARD,
type=GroupType.STANDARD,
)
.returning(groups.c.gid)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .models.comp_pipeline import StateType, comp_pipeline
from .models.comp_tasks import DB_CHANNEL_NAME, NodeClass, comp_tasks
from .models.confirmations import ConfirmationAction, confirmations
from .models.groups import GroupTypeEnum, groups, user_to_groups
from .models.groups import GroupType, groups, user_to_groups
from .models.products import products
from .models.projects import ProjectType, projects
from .models.projects_tags import projects_tags
Expand All @@ -28,7 +28,7 @@
"DB_CHANNEL_NAME",
"group_classifiers",
"groups",
"GroupTypeEnum",
"GroupType",
"NodeClass",
"products",
"projects",
Expand Down
6 changes: 3 additions & 3 deletions packages/postgres-database/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ProjectNodesRepo,
)
from simcore_postgres_database.webserver_models import (
GroupTypeEnum,
GroupType,
groups,
user_to_groups,
users,
Expand Down Expand Up @@ -237,7 +237,7 @@ def create_fake_group(

async def _creator(conn: SAConnection, **overrides) -> RowProxy:
if "type" not in overrides:
overrides["type"] = GroupTypeEnum.STANDARD
overrides["type"] = GroupType.STANDARD
result: ResultProxy = await conn.execute(
groups.insert()
.values(**random_group(**overrides))
Expand Down Expand Up @@ -281,7 +281,7 @@ async def _creator(conn, group: RowProxy | None = None, **overrides) -> RowProxy
created_ids.append(user.id)

if group:
assert group.type == GroupTypeEnum.STANDARD.name
assert group.type == GroupType.STANDARD.name
result = await conn.execute(
user_to_groups.insert().values(uid=user.id, gid=group.gid)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest
import sqlalchemy as sa
from aiopg.sa.engine import Engine
from simcore_postgres_database.models.groups import GroupTypeEnum, groups
from simcore_postgres_database.models.groups import GroupType, groups
from simcore_postgres_database.models.products import products
from simcore_postgres_database.utils_products import (
get_default_product_name,
Expand Down Expand Up @@ -61,7 +61,7 @@ async def test_get_or_create_group_product(
product_group = await result.first()

# check product's group
assert product_group.type == GroupTypeEnum.STANDARD
assert product_group.type == GroupType.STANDARD
assert product_group.name == product_row.name
assert product_group.description == f"{product_row.name} product group"

Expand Down
8 changes: 4 additions & 4 deletions packages/postgres-database/tests/test_models_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pytest_simcore.helpers.faker_factories import random_user
from simcore_postgres_database.models.base import metadata
from simcore_postgres_database.webserver_models import (
GroupTypeEnum,
GroupType,
groups,
user_to_groups,
users,
Expand Down Expand Up @@ -74,7 +74,7 @@ async def test_all_group(
assert groups_count == 1

result = await connection.execute(
groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE)
groups.select().where(groups.c.type == GroupType.EVERYONE)
)
all_group_gid = (await result.fetchone()).gid
assert all_group_gid == 1 # it's the first group so it gets a 1
Expand Down Expand Up @@ -108,7 +108,7 @@ async def test_all_group(
groups_count = await connection.scalar(select(func.count()).select_from(groups))
assert groups_count == 1
result = await connection.execute(
groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE)
groups.select().where(groups.c.type == GroupType.EVERYONE)
)
all_group_gid = (await result.fetchone()).gid
assert all_group_gid == 1 # it's the first group so it gets a 1
Expand All @@ -130,7 +130,7 @@ async def test_own_group(

# now check there is a primary group
result = await connection.execute(
groups.select().where(groups.c.type == GroupTypeEnum.PRIMARY)
groups.select().where(groups.c.type == GroupType.PRIMARY)
)
primary_group: RowProxy = await result.fetchone()
assert primary_group.gid == user.primary_gid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import sqlalchemy
from aiopg.sa.result import RowProxy
from faker import Faker
from simcore_postgres_database.models.groups import (
GroupTypeEnum,
groups,
user_to_groups,
)
from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups
from simcore_postgres_database.models.groups_extra_properties import (
groups_extra_properties,
)
Expand Down Expand Up @@ -108,7 +104,7 @@ async def test_get(
@pytest.fixture
async def everyone_group_id(connection: aiopg.sa.connection.SAConnection) -> int:
result = await connection.scalar(
sqlalchemy.select(groups.c.gid).where(groups.c.type == GroupTypeEnum.EVERYONE)
sqlalchemy.select(groups.c.gid).where(groups.c.type == GroupType.EVERYONE)
)
assert result
return result
Expand Down
6 changes: 3 additions & 3 deletions packages/postgres-database/tests/test_utils_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sqlalchemy as sa
from faker import Faker
from pytest_simcore.helpers.faker_factories import random_group
from simcore_postgres_database.models.groups import GroupTypeEnum, groups
from simcore_postgres_database.models.groups import GroupType, groups
from simcore_postgres_database.models.products import products
from simcore_postgres_database.models.services import (
services_access_rights,
Expand Down Expand Up @@ -165,12 +165,12 @@ def services_fixture(faker: Faker, pg_sa_engine: sa.engine.Engine) -> ServicesFi
# GROUPS
product_gid = conn.execute(
groups.insert()
.values(**random_group(type=GroupTypeEnum.STANDARD, name="osparc group"))
.values(**random_group(type=GroupType.STANDARD, name="osparc group"))
.returning(groups.c.gid)
).scalar()

everyone_gid = conn.execute(
sa.select(groups.c.gid).where(groups.c.type == GroupTypeEnum.EVERYONE)
sa.select(groups.c.gid).where(groups.c.type == GroupType.EVERYONE)
).scalar()

assert product_gid != everyone_gid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def random_project(fake: Faker = DEFAULT_FAKER, **overrides) -> dict[str, Any]:

def random_group(fake: Faker = DEFAULT_FAKER, **overrides) -> dict[str, Any]:
from simcore_postgres_database.models.groups import groups
from simcore_postgres_database.webserver_models import GroupTypeEnum
from simcore_postgres_database.webserver_models import GroupType

data = {
"name": fake.company(),
"description": fake.text(),
"type": GroupTypeEnum.STANDARD.name,
"type": GroupType.STANDARD.name,
}

assert set(data.keys()).issubset({c.name for c in groups.columns}) # nosec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from simcore_postgres_database.models.api_keys import api_keys
from simcore_postgres_database.models.base import metadata
from simcore_postgres_database.models.groups import (
GroupTypeEnum,
groups,
user_to_groups,
)
from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups
from simcore_postgres_database.models.users import UserRole, UserStatus, users

__all__: tuple[str, ...] = (
"api_keys",
"groups",
"GroupTypeEnum",
"GroupType",
"metadata",
"user_to_groups",
"UserRole",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic.types import PositiveInt

from ...exceptions.errors import UninitializedGroupError
from ..tables import GroupTypeEnum, groups, user_to_groups, users
from ..tables import GroupType, groups, user_to_groups, users
from ._base import BaseRepository


Expand All @@ -30,12 +30,12 @@ async def list_user_groups(self, user_id: int) -> list[GroupAtDB]:
async def get_everyone_group(self) -> GroupAtDB:
async with self.db_engine.connect() as conn:
result = await conn.execute(
sa.select(groups).where(groups.c.type == GroupTypeEnum.EVERYONE)
sa.select(groups).where(groups.c.type == GroupType.EVERYONE)
)
row = result.first()
if not row:
raise UninitializedGroupError(
group=GroupTypeEnum.EVERYONE, repo_cls=GroupsRepository
group=GroupType.EVERYONE, repo_cls=GroupsRepository
)
return GroupAtDB.model_validate(row)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from models_library.api_schemas_catalog.services_specifications import (
ServiceSpecifications,
)
from models_library.groups import GroupAtDB, GroupID, GroupTypeEnum
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 UserID
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 == GroupTypeEnum.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 == GroupTypeEnum.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 == GroupTypeEnum.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
8 changes: 2 additions & 6 deletions services/catalog/src/simcore_service_catalog/db/tables.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from simcore_postgres_database.models.groups import (
GroupTypeEnum,
groups,
user_to_groups,
)
from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups
from simcore_postgres_database.models.projects import ProjectType, projects
from simcore_postgres_database.models.services import (
services_access_rights,
Expand All @@ -18,7 +14,7 @@

__all__ = (
"groups",
"GroupTypeEnum",
"GroupType",
"projects",
"ProjectType",
"services_access_rights",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from simcore_postgres_database.models.base import metadata
from simcore_postgres_database.webserver_models import (
ConfirmationAction,
GroupTypeEnum,
GroupType,
UserRole,
UserStatus,
api_keys,
Expand All @@ -28,7 +28,7 @@
"confirmations",
"group_classifiers",
"groups",
"GroupTypeEnum",
"GroupType",
"metadata",
"products",
"projects",
Expand Down
Loading

0 comments on commit b0e3e8c

Please sign in to comment.