Skip to content

Commit 43c224a

Browse files
conversation
1 parent 158ba68 commit 43c224a

File tree

9 files changed

+393
-25
lines changed

9 files changed

+393
-25
lines changed

packages/models-library/src/models_library/api_schemas_webserver/projects_conversations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from ..groups import GroupID
1313
from ..products import ProductName
1414
from ..projects import ProjectID
15-
from ..users import UserID
1615
from ._base import InputSchema, OutputSchema
1716

1817

@@ -21,7 +20,7 @@ class ConversationRestGet(OutputSchema):
2120
product_name: ProductName
2221
name: str
2322
project_uuid: ProjectID | None
24-
user_id: UserID
23+
user_group_id: GroupID
2524
type: ConversationType
2625

2726
# states
@@ -35,7 +34,7 @@ def from_domain_model(cls, domain: ConversationDB) -> Self:
3534
product_name=domain.product_name,
3635
name=domain.name,
3736
project_uuid=domain.project_uuid,
38-
user_id=domain.user_id,
37+
user_group_id=domain.user_group_id,
3938
type=domain.type,
4039
created=domain.created,
4140
modified=domain.modified,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from models_library.groups import GroupID
77
from models_library.projects import ProjectID
8-
from models_library.users import UserID
98
from pydantic import BaseModel, ConfigDict
109
from simcore_postgres_database.models.conversation_messages import (
1110
ConversationMessageType as PostgresConversationMessageType,
@@ -53,7 +52,7 @@ class ConversationDB(BaseModel):
5352
product_name: ProductName
5453
name: str
5554
project_uuid: ProjectID | None
56-
user_id: UserID
55+
user_group_id: GroupID
5756
type: ConversationType
5857

5958
# states
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""add conversations
22
3-
Revision ID: 5921537e608d
3+
Revision ID: 03d6d6ab0d5f
44
Revises: 742123f0933a
5-
Create Date: 2025-04-24 11:25:11.868406+00:00
5+
Create Date: 2025-04-28 10:57:35.554780+00:00
66
77
"""
88

@@ -11,7 +11,7 @@
1111
from sqlalchemy.dialects import postgresql
1212

1313
# revision identifiers, used by Alembic.
14-
revision = "5921537e608d"
14+
revision = "03d6d6ab0d5f"
1515
down_revision = "742123f0933a"
1616
branch_labels = None
1717
depends_on = None
@@ -35,6 +35,7 @@ def upgrade():
3535
sa.Enum("PROJECT_STATIC", "PROJECT_ANNOTATION", name="conversationtype"),
3636
nullable=True,
3737
),
38+
sa.Column("product_name", sa.String(), nullable=False),
3839
sa.Column(
3940
"created",
4041
sa.DateTime(timezone=True),
@@ -47,6 +48,13 @@ def upgrade():
4748
server_default=sa.text("now()"),
4849
nullable=False,
4950
),
51+
sa.ForeignKeyConstraint(
52+
["product_name"],
53+
["products.name"],
54+
name="fk_resource_tracker_license_packages_product_name",
55+
onupdate="CASCADE",
56+
ondelete="CASCADE",
57+
),
5058
sa.ForeignKeyConstraint(
5159
["project_uuid"],
5260
["projects.uuid"],
@@ -77,7 +85,7 @@ def upgrade():
7785
nullable=False,
7886
),
7987
sa.Column("conversation_id", postgresql.UUID(as_uuid=True), nullable=False),
80-
sa.Column("user_group_id", sa.BigInteger(), nullable=False),
88+
sa.Column("user_group_id", sa.BigInteger(), nullable=True),
8189
sa.Column("content", sa.String(), nullable=False),
8290
sa.Column(
8391
"type",
@@ -105,8 +113,8 @@ def upgrade():
105113
),
106114
sa.ForeignKeyConstraint(
107115
["user_group_id"],
108-
["users.id"],
109-
name="fk_conversation_messages_user_id",
116+
["groups.gid"],
117+
name="fk_conversation_messages_user_primary_gid",
110118
ondelete="SET NULL",
111119
),
112120
sa.PrimaryKeyConstraint("message_id"),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ._common import RefActions, column_created_datetime, column_modified_datetime
77
from .base import metadata
88
from .conversations import conversations
9-
from .users import users
9+
from .groups import groups
1010

1111

1212
class ConversationMessageType(enum.Enum):
@@ -41,12 +41,12 @@ class ConversationMessageType(enum.Enum):
4141
"user_group_id",
4242
sa.BigInteger,
4343
sa.ForeignKey(
44-
users.c.id,
45-
name="fk_conversation_messages_user_id",
44+
groups.c.gid,
45+
name="fk_conversation_messages_user_primary_gid",
4646
ondelete=RefActions.SET_NULL,
4747
),
4848
doc="user primary group ID who created the message",
49-
nullable=False,
49+
nullable=True,
5050
),
5151
sa.Column(
5252
"content",

services/web/server/src/simcore_service_webserver/conversations/_conversation_message_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ async def list_messages_for_conversation(
9393
conversation_id=conversation_id,
9494
offset=offset,
9595
limit=limit,
96-
order_by=OrderBy(field=IDStr("message_id"), direction=OrderDirection.DESC),
96+
order_by=OrderBy(
97+
field=IDStr("created"), direction=OrderDirection.DESC
98+
), # NOTE: Message should be ordered by creation date (latest first)
9799
)

services/web/server/src/simcore_service_webserver/conversations/_conversation_repository.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
ConversationPatchDB,
99
ConversationType,
1010
)
11+
from models_library.groups import GroupID
1112
from models_library.products import ProductName
1213
from models_library.projects import ProjectID
1314
from models_library.rest_ordering import OrderBy, OrderDirection
14-
from models_library.users import UserID
1515
from pydantic import NonNegativeInt
1616
from simcore_postgres_database.models.conversations import conversations
1717
from simcore_postgres_database.utils_repos import (
@@ -38,7 +38,7 @@ async def create(
3838
*,
3939
name: str,
4040
project_uuid: ProjectID | None,
41-
user_id: UserID,
41+
user_group_id: GroupID,
4242
type_: ConversationType,
4343
product_name: ProductName,
4444
) -> ConversationDB:
@@ -47,8 +47,8 @@ async def create(
4747
conversations.insert()
4848
.values(
4949
name=name,
50-
project_uuid=project_uuid,
51-
user_id=user_id,
50+
project_uuid=f"{project_uuid}" if project_uuid else None,
51+
user_group_id=user_group_id,
5252
type=type_,
5353
created=func.now(),
5454
modified=func.now(),
@@ -75,7 +75,7 @@ async def list_project_conversations(
7575
base_query = (
7676
select(*_SELECTION_ARGS)
7777
.select_from(conversations)
78-
.where(conversations.c.project_uuid == project_uuid)
78+
.where(conversations.c.project_uuid == f"{project_uuid}")
7979
)
8080

8181
# Select total count from base_query
@@ -115,7 +115,7 @@ async def get(
115115
select_query = (
116116
select(*_SELECTION_ARGS)
117117
.select_from(conversations)
118-
.where(conversations.c.conversation_id == conversation_id)
118+
.where(conversations.c.conversation_id == f"{conversation_id}")
119119
)
120120

121121
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
@@ -143,7 +143,7 @@ async def update(
143143
result = await conn.execute(
144144
conversations.update()
145145
.values(**_updates)
146-
.where(conversations.c.conversation_id == conversation_id)
146+
.where(conversations.c.conversation_id == f"{conversation_id}")
147147
.returning(*_SELECTION_ARGS)
148148
)
149149
row = result.one_or_none()
@@ -161,6 +161,6 @@ async def delete(
161161
async with transaction_context(get_asyncpg_engine(app), connection) as conn:
162162
await conn.execute(
163163
conversations.delete().where(
164-
conversations.c.conversation_id == conversation_id
164+
conversations.c.conversation_id == f"{conversation_id}"
165165
)
166166
)

services/web/server/src/simcore_service_webserver/conversations/_conversation_service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from models_library.rest_ordering import OrderBy, OrderDirection
1616
from models_library.users import UserID
1717

18+
from ..users.api import get_user_primary_group_id
1819
from . import _conversation_repository
1920

2021
_logger = logging.getLogger(__name__)
@@ -33,11 +34,13 @@ async def create_conversation(
3334
if project_uuid is None:
3435
raise NotImplementedError
3536

37+
_user_group_id = await get_user_primary_group_id(app, user_id=user_id)
38+
3639
return await _conversation_repository.create(
3740
app,
3841
name=name,
3942
project_uuid=project_uuid,
40-
user_id=user_id,
43+
user_group_id=_user_group_id,
4144
type_=type_,
4245
product_name=product_name,
4346
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._controller import (
1515
access_rights_rest,
1616
comments_rest,
17+
conversations_rest,
1718
folders_rest,
1819
metadata_rest,
1920
nodes_pricing_unit_rest,
@@ -62,6 +63,7 @@ def setup_projects(app: web.Application) -> bool:
6263
app.router.add_routes(projects_states_rest.routes)
6364
app.router.add_routes(projects_rest.routes)
6465
app.router.add_routes(comments_rest.routes)
66+
app.router.add_routes(conversations_rest.routes)
6567
app.router.add_routes(access_rights_rest.routes)
6668
app.router.add_routes(metadata_rest.routes)
6769
app.router.add_routes(ports_rest.routes)

0 commit comments

Comments
 (0)