Skip to content

Commit 6c49ba9

Browse files
committed
Group Enum common
1 parent 85f17ae commit 6c49ba9

File tree

7 files changed

+30
-52
lines changed

7 files changed

+30
-52
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import enum
2+
3+
4+
class GroupType(enum.Enum):
5+
"""
6+
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
7+
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
8+
everyone: the only group for all users
9+
"""
10+
11+
STANDARD = "standard"
12+
PRIMARY = "primary"
13+
EVERYONE = "everyone"

packages/models-library/src/models_library/groups.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import enum
21
from typing import Annotated, Final, NamedTuple, TypeAlias
32

43
from common_library.basic_types import DEFAULT_FACTORY
4+
from common_library.groups_enums import GroupType as GroupTypeEnum
55
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
66
from pydantic.types import PositiveInt
77
from typing_extensions import TypedDict
@@ -14,24 +14,14 @@
1414

1515
GroupID: TypeAlias = PositiveInt
1616

17-
18-
class GroupTypeInModel(str, enum.Enum):
19-
"""
20-
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
21-
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
22-
everyone: the only group for all users
23-
"""
24-
25-
STANDARD = "standard"
26-
PRIMARY = "primary"
27-
EVERYONE = "everyone"
17+
__all__: tuple[str, ...] = ("GroupTypeEnum",)
2818

2919

3020
class Group(BaseModel):
3121
gid: PositiveInt
3222
name: str
3323
description: str
34-
group_type: Annotated[GroupTypeInModel, Field(alias="type")]
24+
group_type: Annotated[GroupTypeEnum, Field(alias="type")]
3525
thumbnail: str | None
3626

3727
inclusion_rules: Annotated[
@@ -42,7 +32,7 @@ class Group(BaseModel):
4232
] = DEFAULT_FACTORY
4333

4434
_from_equivalent_enums = field_validator("group_type", mode="before")(
45-
create_enums_pre_validator(GroupTypeInModel)
35+
create_enums_pre_validator(GroupTypeEnum)
4636
)
4737

4838
model_config = ConfigDict(populate_by_name=True)

packages/postgres-database/src/simcore_postgres_database/models/groups.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,15 @@
44
- Groups have a ID, name and a list of users that belong to the group
55
"""
66

7-
import enum
87

98
import sqlalchemy as sa
9+
from common_library.groups_enums import GroupType
1010
from sqlalchemy.dialects.postgresql import JSONB
1111
from sqlalchemy.sql import func
1212

1313
from ._common import RefActions
1414
from .base import metadata
1515

16-
17-
class GroupType(enum.Enum):
18-
"""
19-
standard: standard group, e.g. any group that is not a primary group or special group such as the everyone group
20-
primary: primary group, e.g. the primary group is the user own defined group that typically only contain the user (same as in linux)
21-
everyone: the only group for all users
22-
"""
23-
24-
STANDARD = "standard"
25-
PRIMARY = "primary"
26-
EVERYONE = "everyone"
27-
28-
2916
groups = sa.Table(
3017
"groups",
3118
metadata,

services/catalog/src/simcore_service_catalog/db/repositories/services.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from models_library.api_schemas_catalog.services_specifications import (
1111
ServiceSpecifications,
1212
)
13-
from models_library.groups import GroupAtDB, GroupID, GroupTypeInModel
13+
from models_library.groups import GroupAtDB, GroupID, GroupTypeEnum
1414
from models_library.products import ProductName
1515
from models_library.services import ServiceKey, ServiceVersion
1616
from models_library.users import UserID
@@ -597,16 +597,16 @@ async def get_service_specifications(
597597
continue
598598
# filter by group type
599599
group = gid_to_group_map[row.gid]
600-
if (group.group_type == GroupTypeInModel.STANDARD) and _is_newer(
600+
if (group.group_type == GroupTypeEnum.STANDARD) and _is_newer(
601601
teams_specs.get(db_service_spec.gid),
602602
db_service_spec,
603603
):
604604
teams_specs[db_service_spec.gid] = db_service_spec
605-
elif (group.group_type == GroupTypeInModel.EVERYONE) and _is_newer(
605+
elif (group.group_type == GroupTypeEnum.EVERYONE) and _is_newer(
606606
everyone_specs, db_service_spec
607607
):
608608
everyone_specs = db_service_spec
609-
elif (group.group_type == GroupTypeInModel.PRIMARY) and _is_newer(
609+
elif (group.group_type == GroupTypeEnum.PRIMARY) and _is_newer(
610610
primary_specs, db_service_spec
611611
):
612612
primary_specs = db_service_spec

services/web/server/src/simcore_service_webserver/garbage_collector/_core_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncpg.exceptions
44
from aiohttp import web
5-
from models_library.groups import Group, GroupID, GroupTypeInModel
5+
from models_library.groups import Group, GroupID, GroupTypeEnum
66
from models_library.projects import ProjectID
77
from models_library.users import UserID
88
from simcore_postgres_database.errors import DatabaseError
@@ -86,9 +86,9 @@ async def get_new_project_owner_gid(
8686
if access_rights[other_gid]["write"] is not True:
8787
continue
8888

89-
if group.group_type == GroupTypeInModel.STANDARD:
89+
if group.group_type == GroupTypeEnum.STANDARD:
9090
standard_groups[other_gid] = access_rights[other_gid]
91-
elif group.group_type == GroupTypeInModel.PRIMARY:
91+
elif group.group_type == GroupTypeEnum.PRIMARY:
9292
primary_groups[other_gid] = access_rights[other_gid]
9393

9494
_logger.debug(

services/web/server/src/simcore_service_webserver/projects/_nodes_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
NodePatch,
2626
NodeRetrieve,
2727
)
28-
from models_library.groups import EVERYONE_GROUP_ID, Group, GroupID, GroupTypeInModel
28+
from models_library.groups import EVERYONE_GROUP_ID, Group, GroupID, GroupTypeEnum
2929
from models_library.projects import Project, ProjectID
3030
from models_library.projects_nodes_io import NodeID, NodeIDStr
3131
from models_library.services import ServiceKeyVersion
@@ -566,7 +566,7 @@ async def get_project_services_access_for_gid(
566566
raise GroupNotFoundError(gid=query_params.for_gid)
567567

568568
# Update groups to compare based on the type of sharing group
569-
if _sharing_with_group.group_type == GroupTypeInModel.PRIMARY:
569+
if _sharing_with_group.group_type == GroupTypeEnum.PRIMARY:
570570
_user_id = await get_user_id_from_gid(
571571
app=request.app, primary_gid=query_params.for_gid
572572
)
@@ -575,7 +575,7 @@ async def get_project_services_access_for_gid(
575575
)
576576
groups_to_compare.update(set(user_groups_ids))
577577
groups_to_compare.add(query_params.for_gid)
578-
elif _sharing_with_group.group_type == GroupTypeInModel.STANDARD:
578+
elif _sharing_with_group.group_type == GroupTypeEnum.STANDARD:
579579
groups_to_compare = {query_params.for_gid}
580580

581581
# Initialize a list for inaccessible services

services/web/server/tests/unit/isolated/test_groups_models.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import models_library.groups
21
import pytest
3-
import simcore_postgres_database.models.groups
42
from faker import Faker
53
from models_library.api_schemas_webserver._base import OutputSchema
64
from models_library.api_schemas_webserver.groups import (
@@ -14,23 +12,13 @@
1412
AccessRightsDict,
1513
Group,
1614
GroupMember,
17-
GroupTypeInModel,
15+
GroupTypeEnum,
1816
StandardGroupCreate,
1917
StandardGroupUpdate,
2018
)
21-
from models_library.utils.enums import enum_to_dict
2219
from pydantic import ValidationError
2320

2421

25-
def test_models_library_and_postgress_database_enums_are_equivalent():
26-
# For the moment these two libraries they do not have a common library to share these
27-
# basic types so we test here that they are in sync
28-
29-
assert enum_to_dict(
30-
simcore_postgres_database.models.groups.GroupType
31-
) == enum_to_dict(models_library.groups.GroupTypeInModel)
32-
33-
3422
def test_sanitize_legacy_data():
3523
users_group_1 = GroupGet.model_validate(
3624
{
@@ -66,7 +54,7 @@ def test_output_schemas_from_models(faker: Faker):
6654
gid=1,
6755
name=faker.word(),
6856
description=faker.sentence(),
69-
group_type=GroupTypeInModel.STANDARD,
57+
group_type=GroupTypeEnum.STANDARD,
7058
thumbnail=None,
7159
)
7260
output_schema = GroupGet.from_model(

0 commit comments

Comments
 (0)