diff --git a/packages/common-library/src/common_library/groups_enums.py b/packages/common-library/src/common_library/groups_enums.py index 215edf335f1..72c5029d646 100644 --- a/packages/common-library/src/common_library/groups_enums.py +++ b/packages/common-library/src/common_library/groups_enums.py @@ -1,7 +1,7 @@ import enum -class GroupType(enum.Enum): +class GroupTypeEnum(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) diff --git a/packages/models-library/src/models_library/groups.py b/packages/models-library/src/models_library/groups.py index b165e6635fa..902a7da0355 100644 --- a/packages/models-library/src/models_library/groups.py +++ b/packages/models-library/src/models_library/groups.py @@ -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 GroupType as GroupTypeEnum +from common_library.groups_enums import GroupTypeEnum as GroupTypeEnum from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator from pydantic.types import PositiveInt from typing_extensions import TypedDict diff --git a/packages/postgres-database/src/simcore_postgres_database/models/groups.py b/packages/postgres-database/src/simcore_postgres_database/models/groups.py index e2d1e4655ef..86ac946b4e9 100644 --- a/packages/postgres-database/src/simcore_postgres_database/models/groups.py +++ b/packages/postgres-database/src/simcore_postgres_database/models/groups.py @@ -6,7 +6,7 @@ import sqlalchemy as sa -from common_library.groups_enums import GroupType +from common_library.groups_enums import GroupTypeEnum from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.sql import func @@ -27,7 +27,7 @@ sa.Column("description", sa.String, nullable=False, doc="Short description"), sa.Column( "type", - sa.Enum(GroupType), + sa.Enum(GroupTypeEnum), nullable=False, server_default="STANDARD", doc="Classification of the group based on GroupType enum", diff --git a/packages/postgres-database/src/simcore_postgres_database/utils_groups_extra_properties.py b/packages/postgres-database/src/simcore_postgres_database/utils_groups_extra_properties.py index b6c25183a21..e88fe83b0df 100644 --- a/packages/postgres-database/src/simcore_postgres_database/utils_groups_extra_properties.py +++ b/packages/postgres-database/src/simcore_postgres_database/utils_groups_extra_properties.py @@ -7,7 +7,7 @@ from aiopg.sa.connection import SAConnection from aiopg.sa.result import RowProxy -from .models.groups import GroupType, groups, user_to_groups +from .models.groups import GroupTypeEnum, groups, user_to_groups from .models.groups_extra_properties import groups_extra_properties from .utils_models import FromRowMixin @@ -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 == GroupType.EVERYONE, sa.literal(3)), - (groups.c.type == GroupType.STANDARD, sa.literal(2)), - (groups.c.type == GroupType.PRIMARY, sa.literal(1)), + (groups.c.type == GroupTypeEnum.EVERYONE, sa.literal(3)), + (groups.c.type == GroupTypeEnum.STANDARD, sa.literal(2)), + (groups.c.type == GroupTypeEnum.PRIMARY, sa.literal(1)), else_=sa.literal(4), ).label("type_order"), ) @@ -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 GroupType.PRIMARY: + case GroupTypeEnum.PRIMARY: # this always has highest priority return group_extra_properties - case GroupType.STANDARD: + case GroupTypeEnum.STANDARD: if merged_standard_extra_properties: merged_standard_extra_properties = ( _merge_extra_properties_booleans( @@ -137,7 +137,7 @@ async def get_aggregated_properties_for_user( ) else: merged_standard_extra_properties = group_extra_properties - case GroupType.EVERYONE: + case GroupTypeEnum.EVERYONE: # if there are standard properties, they take precedence return ( merged_standard_extra_properties diff --git a/packages/postgres-database/src/simcore_postgres_database/utils_products.py b/packages/postgres-database/src/simcore_postgres_database/utils_products.py index 33e877c21d0..9e54fef9787 100644 --- a/packages/postgres-database/src/simcore_postgres_database/utils_products.py +++ b/packages/postgres-database/src/simcore_postgres_database/utils_products.py @@ -7,7 +7,7 @@ import sqlalchemy as sa from ._protocols import AiopgConnection, DBConnection -from .models.groups import GroupType, groups +from .models.groups import GroupTypeEnum, groups from .models.products import products # NOTE: outside this module, use instead packages/models-library/src/models_library/users.py @@ -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=GroupType.STANDARD, + type=GroupTypeEnum.STANDARD, ) .returning(groups.c.gid) ) diff --git a/packages/postgres-database/src/simcore_postgres_database/webserver_models.py b/packages/postgres-database/src/simcore_postgres_database/webserver_models.py index 571db047cfb..68f8d51bfe4 100644 --- a/packages/postgres-database/src/simcore_postgres_database/webserver_models.py +++ b/packages/postgres-database/src/simcore_postgres_database/webserver_models.py @@ -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 GroupType, groups, user_to_groups +from .models.groups import GroupTypeEnum, groups, user_to_groups from .models.products import products from .models.projects import ProjectType, projects from .models.projects_tags import projects_tags @@ -28,7 +28,7 @@ "DB_CHANNEL_NAME", "group_classifiers", "groups", - "GroupType", + "GroupTypeEnum", "NodeClass", "products", "projects", diff --git a/packages/postgres-database/tests/conftest.py b/packages/postgres-database/tests/conftest.py index feb8bfaae97..a446120e344 100644 --- a/packages/postgres-database/tests/conftest.py +++ b/packages/postgres-database/tests/conftest.py @@ -33,7 +33,7 @@ ProjectNodesRepo, ) from simcore_postgres_database.webserver_models import ( - GroupType, + GroupTypeEnum, groups, user_to_groups, users, @@ -237,7 +237,7 @@ def create_fake_group( async def _creator(conn: SAConnection, **overrides) -> RowProxy: if "type" not in overrides: - overrides["type"] = GroupType.STANDARD + overrides["type"] = GroupTypeEnum.STANDARD result: ResultProxy = await conn.execute( groups.insert() .values(**random_group(**overrides)) @@ -281,7 +281,7 @@ async def _creator(conn, group: RowProxy | None = None, **overrides) -> RowProxy created_ids.append(user.id) if group: - assert group.type == GroupType.STANDARD.name + assert group.type == GroupTypeEnum.STANDARD.name result = await conn.execute( user_to_groups.insert().values(uid=user.id, gid=group.gid) ) diff --git a/packages/postgres-database/tests/products/test_utils_products.py b/packages/postgres-database/tests/products/test_utils_products.py index a1b84fe96dd..f2557037a95 100644 --- a/packages/postgres-database/tests/products/test_utils_products.py +++ b/packages/postgres-database/tests/products/test_utils_products.py @@ -10,7 +10,7 @@ import pytest import sqlalchemy as sa from aiopg.sa.engine import Engine -from simcore_postgres_database.models.groups import GroupType, groups +from simcore_postgres_database.models.groups import GroupTypeEnum, groups from simcore_postgres_database.models.products import products from simcore_postgres_database.utils_products import ( get_default_product_name, @@ -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 == GroupType.STANDARD + assert product_group.type == GroupTypeEnum.STANDARD assert product_group.name == product_row.name assert product_group.description == f"{product_row.name} product group" diff --git a/packages/postgres-database/tests/test_models_groups.py b/packages/postgres-database/tests/test_models_groups.py index 649e2111867..95c9242e840 100644 --- a/packages/postgres-database/tests/test_models_groups.py +++ b/packages/postgres-database/tests/test_models_groups.py @@ -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 ( - GroupType, + GroupTypeEnum, groups, user_to_groups, users, @@ -74,7 +74,7 @@ async def test_all_group( assert groups_count == 1 result = await connection.execute( - groups.select().where(groups.c.type == GroupType.EVERYONE) + groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE) ) all_group_gid = (await result.fetchone()).gid assert all_group_gid == 1 # it's the first group so it gets a 1 @@ -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 == GroupType.EVERYONE) + groups.select().where(groups.c.type == GroupTypeEnum.EVERYONE) ) all_group_gid = (await result.fetchone()).gid assert all_group_gid == 1 # it's the first group so it gets a 1 @@ -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 == GroupType.PRIMARY) + groups.select().where(groups.c.type == GroupTypeEnum.PRIMARY) ) primary_group: RowProxy = await result.fetchone() assert primary_group.gid == user.primary_gid diff --git a/packages/postgres-database/tests/test_utils_groups_extra_properties.py b/packages/postgres-database/tests/test_utils_groups_extra_properties.py index fafc97d1551..bad39c75d5f 100644 --- a/packages/postgres-database/tests/test_utils_groups_extra_properties.py +++ b/packages/postgres-database/tests/test_utils_groups_extra_properties.py @@ -11,7 +11,11 @@ import sqlalchemy from aiopg.sa.result import RowProxy from faker import Faker -from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups +from simcore_postgres_database.models.groups import ( + GroupTypeEnum, + groups, + user_to_groups, +) from simcore_postgres_database.models.groups_extra_properties import ( groups_extra_properties, ) @@ -104,7 +108,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 == GroupType.EVERYONE) + sqlalchemy.select(groups.c.gid).where(groups.c.type == GroupTypeEnum.EVERYONE) ) assert result return result diff --git a/packages/postgres-database/tests/test_utils_services.py b/packages/postgres-database/tests/test_utils_services.py index 70b102fea70..5e2866cf6c3 100644 --- a/packages/postgres-database/tests/test_utils_services.py +++ b/packages/postgres-database/tests/test_utils_services.py @@ -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 GroupType, groups +from simcore_postgres_database.models.groups import GroupTypeEnum, groups from simcore_postgres_database.models.products import products from simcore_postgres_database.models.services import ( services_access_rights, @@ -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=GroupType.STANDARD, name="osparc group")) + .values(**random_group(type=GroupTypeEnum.STANDARD, name="osparc group")) .returning(groups.c.gid) ).scalar() everyone_gid = conn.execute( - sa.select(groups.c.gid).where(groups.c.type == GroupType.EVERYONE) + sa.select(groups.c.gid).where(groups.c.type == GroupTypeEnum.EVERYONE) ).scalar() assert product_gid != everyone_gid diff --git a/packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py b/packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py index d4418a5ef81..eee0c78a3c1 100644 --- a/packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py +++ b/packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py @@ -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 GroupType + from simcore_postgres_database.webserver_models import GroupTypeEnum data = { "name": fake.company(), "description": fake.text(), - "type": GroupType.STANDARD.name, + "type": GroupTypeEnum.STANDARD.name, } assert set(data.keys()).issubset({c.name for c in groups.columns}) # nosec diff --git a/services/api-server/src/simcore_service_api_server/db/tables.py b/services/api-server/src/simcore_service_api_server/db/tables.py index e07cfdb3792..34bec9bf785 100644 --- a/services/api-server/src/simcore_service_api_server/db/tables.py +++ b/services/api-server/src/simcore_service_api_server/db/tables.py @@ -1,12 +1,16 @@ 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 GroupType, groups, user_to_groups +from simcore_postgres_database.models.groups import ( + GroupTypeEnum, + groups, + user_to_groups, +) from simcore_postgres_database.models.users import UserRole, UserStatus, users __all__: tuple[str, ...] = ( "api_keys", "groups", - "GroupType", + "GroupTypeEnum", "metadata", "user_to_groups", "UserRole", diff --git a/services/catalog/src/simcore_service_catalog/db/repositories/groups.py b/services/catalog/src/simcore_service_catalog/db/repositories/groups.py index d7061947a10..c491e3eb208 100644 --- a/services/catalog/src/simcore_service_catalog/db/repositories/groups.py +++ b/services/catalog/src/simcore_service_catalog/db/repositories/groups.py @@ -7,7 +7,7 @@ from pydantic.types import PositiveInt from ...exceptions.errors import UninitializedGroupError -from ..tables import GroupType, groups, user_to_groups, users +from ..tables import GroupTypeEnum, groups, user_to_groups, users from ._base import BaseRepository @@ -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 == GroupType.EVERYONE) + sa.select(groups).where(groups.c.type == GroupTypeEnum.EVERYONE) ) row = result.first() if not row: raise UninitializedGroupError( - group=GroupType.EVERYONE, repo_cls=GroupsRepository + group=GroupTypeEnum.EVERYONE, repo_cls=GroupsRepository ) return GroupAtDB.model_validate(row) diff --git a/services/catalog/src/simcore_service_catalog/db/tables.py b/services/catalog/src/simcore_service_catalog/db/tables.py index aaff065fcf7..fa0413d2812 100644 --- a/services/catalog/src/simcore_service_catalog/db/tables.py +++ b/services/catalog/src/simcore_service_catalog/db/tables.py @@ -1,4 +1,8 @@ -from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups +from simcore_postgres_database.models.groups import ( + GroupTypeEnum, + groups, + user_to_groups, +) from simcore_postgres_database.models.projects import ProjectType, projects from simcore_postgres_database.models.services import ( services_access_rights, @@ -14,7 +18,7 @@ __all__ = ( "groups", - "GroupType", + "GroupTypeEnum", "projects", "ProjectType", "services_access_rights", diff --git a/services/web/server/src/simcore_service_webserver/db/models.py b/services/web/server/src/simcore_service_webserver/db/models.py index 0cbfaa7638c..f4a3a819799 100644 --- a/services/web/server/src/simcore_service_webserver/db/models.py +++ b/services/web/server/src/simcore_service_webserver/db/models.py @@ -4,7 +4,7 @@ from simcore_postgres_database.models.base import metadata from simcore_postgres_database.webserver_models import ( ConfirmationAction, - GroupType, + GroupTypeEnum, UserRole, UserStatus, api_keys, @@ -28,7 +28,7 @@ "confirmations", "group_classifiers", "groups", - "GroupType", + "GroupTypeEnum", "metadata", "products", "projects", diff --git a/services/web/server/src/simcore_service_webserver/groups/_groups_db.py b/services/web/server/src/simcore_service_webserver/groups/_groups_db.py index bb62469c121..741e099a2e7 100644 --- a/services/web/server/src/simcore_service_webserver/groups/_groups_db.py +++ b/services/web/server/src/simcore_service_webserver/groups/_groups_db.py @@ -16,7 +16,7 @@ ) from models_library.users import UserID from simcore_postgres_database.errors import UniqueViolation -from simcore_postgres_database.models.groups import GroupType +from simcore_postgres_database.models.groups import GroupTypeEnum from simcore_postgres_database.utils_products import execute_get_or_create_product_group from simcore_postgres_database.utils_repos import ( pass_or_acquire_connection, @@ -27,7 +27,7 @@ from sqlalchemy.engine.row import Row from sqlalchemy.ext.asyncio import AsyncConnection -from ..db.models import GroupType, groups, user_to_groups, users +from ..db.models import GroupTypeEnum, groups, user_to_groups, users from ..db.plugin import get_asyncpg_engine from ..users.exceptions import UserNotFoundError from .exceptions import ( @@ -172,16 +172,16 @@ async def get_all_user_groups_with_read_access( async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn: result = await conn.stream(query) async for row in result: - if row.type == GroupType.EVERYONE: + if row.type == GroupTypeEnum.EVERYONE: assert row.access_rights["read"] # nosec everyone_group = _to_group_info_tuple(row) - elif row.type == GroupType.PRIMARY: + elif row.type == GroupTypeEnum.PRIMARY: assert row.access_rights["read"] # nosec primary_group = _to_group_info_tuple(row) else: - assert row.type == GroupType.STANDARD # nosec + assert row.type == GroupTypeEnum.STANDARD # nosec # only add if user has read access if row.access_rights["read"]: standard_groups.append(_to_group_info_tuple(row)) @@ -311,7 +311,7 @@ async def create_standard_group( groups.insert() .values( **create.model_dump(mode="json", exclude_unset=True), - type=GroupType.STANDARD, + type=GroupTypeEnum.STANDARD, ) .returning(*_GROUP_COLUMNS) ) @@ -357,7 +357,9 @@ async def update_standard_group( # pylint: disable=no-value-for-parameter groups.update() .values(**values) - .where((groups.c.gid == row.gid) & (groups.c.type == GroupType.STANDARD)) + .where( + (groups.c.gid == row.gid) & (groups.c.type == GroupTypeEnum.STANDARD) + ) .returning(*_GROUP_COLUMNS) ) row = await result.fetchone() @@ -383,7 +385,7 @@ async def delete_standard_group( await conn.execute( # pylint: disable=no-value-for-parameter groups.delete().where( - (groups.c.gid == group.gid) & (groups.c.type == GroupType.STANDARD) + (groups.c.gid == group.gid) & (groups.c.type == GroupTypeEnum.STANDARD) ) ) diff --git a/services/web/server/src/simcore_service_webserver/projects/_db_utils.py b/services/web/server/src/simcore_service_webserver/projects/_db_utils.py index e36e2d455b3..a4d7e6fdbdd 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_db_utils.py +++ b/services/web/server/src/simcore_service_webserver/projects/_db_utils.py @@ -22,7 +22,7 @@ from sqlalchemy.sql import select from sqlalchemy.sql.selectable import CompoundSelect, Select -from ..db.models import GroupType, groups, projects_tags, user_to_groups, users +from ..db.models import GroupTypeEnum, groups, projects_tags, user_to_groups, users from ..users.exceptions import UserNotFoundError from ..utils import format_datetime from .exceptions import ( @@ -112,7 +112,7 @@ class BaseProjectDB: @classmethod async def _get_everyone_group(cls, conn: SAConnection) -> RowProxy: result = await conn.execute( - sa.select(groups).where(groups.c.type == GroupType.EVERYONE) + sa.select(groups).where(groups.c.type == GroupTypeEnum.EVERYONE) ) row = await result.first() assert row is not None # nosec diff --git a/services/web/server/src/simcore_service_webserver/users/api.py b/services/web/server/src/simcore_service_webserver/users/api.py index 1c1d217a28e..944e703ec98 100644 --- a/services/web/server/src/simcore_service_webserver/users/api.py +++ b/services/web/server/src/simcore_service_webserver/users/api.py @@ -24,7 +24,11 @@ from models_library.products import ProductName from models_library.users import UserID from pydantic import EmailStr, TypeAdapter, ValidationError -from simcore_postgres_database.models.groups import GroupType, groups, user_to_groups +from simcore_postgres_database.models.groups import ( + GroupTypeEnum, + groups, + user_to_groups, +) from simcore_postgres_database.models.users import UserRole, users from simcore_postgres_database.utils_groups_extra_properties import ( GroupExtraPropertiesNotFoundError, @@ -121,13 +125,13 @@ async def get_user_profile( } assert user_profile["id"] == user_id # nosec - if row.groups_type == GroupType.EVERYONE: + if row.groups_type == GroupTypeEnum.EVERYONE: everyone_group = _convert_groups_db_to_schema( row, prefix="groups_", accessRights=row["user_to_groups_access_rights"], ) - elif row.groups_type == GroupType.PRIMARY: + elif row.groups_type == GroupTypeEnum.PRIMARY: user_primary_group = _convert_groups_db_to_schema( row, prefix="groups_",