Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 0 additions & 5 deletions api/specs/web-server/_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
)
from simcore_service_webserver.conversations._controller._conversations_rest import (
_ConversationsCreateBodyParams,
_GetConversationsQueryParams,
_ListConversationsQueryParams,
)

Expand All @@ -56,7 +55,6 @@
)
async def create_conversation(
_body: _ConversationsCreateBodyParams,
_query: Annotated[_GetConversationsQueryParams, Depends()],
): ...


Expand All @@ -76,7 +74,6 @@ async def list_conversations(
async def update_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_body: ConversationPatch,
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


Expand All @@ -86,7 +83,6 @@ async def update_conversation(
)
async def delete_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


Expand All @@ -96,7 +92,6 @@ async def delete_conversation(
)
async def get_conversation(
_params: Annotated[ConversationPathParams, Depends()],
_query: Annotated[as_query(_GetConversationsQueryParams), Depends()],
): ...


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1487,11 +1487,11 @@ qx.Class.define("osparc.data.Resources", {
},
getConversation: {
method: "GET",
url: statics.API + "/conversations/{conversationId}?type=SUPPORT"
url: statics.API + "/conversations/{conversationId}"
},
renameConversation: {
method: "PATCH",
url: statics.API + "/conversations/{conversationId}?type=SUPPORT"
url: statics.API + "/conversations/{conversationId}"
},
deleteConversation: {
method: "DELETE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,6 @@ paths:
- conversations
summary: Create Conversation
operationId: create_conversation
parameters:
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
requestBody:
required: true
content:
Expand All @@ -541,11 +535,6 @@ paths:
summary: List Conversations
operationId: list_conversations
parameters:
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
- name: limit
in: query
required: false
Expand All @@ -563,6 +552,11 @@ paths:
minimum: 0
default: 0
title: Offset
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
responses:
'200':
description: Successful Response
Expand All @@ -584,11 +578,6 @@ paths:
type: string
format: uuid
title: Conversation Id
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
requestBody:
required: true
content:
Expand All @@ -615,11 +604,6 @@ paths:
type: string
format: uuid
title: Conversation Id
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
responses:
'204':
description: Successful Response
Expand All @@ -636,11 +620,6 @@ paths:
type: string
format: uuid
title: Conversation Id
- name: type
in: query
required: true
schema:
$ref: '#/components/schemas/ConversationType'
responses:
'200':
description: Successful Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def create_conversation_message(request: web.Request):
message, is_first_message = (
await _conversation_message_service.create_support_message_with_first_check(
app=request.app,
product_name=req_ctx.product_name,
user_id=req_ctx.user_id,
project_id=None, # Support conversations don't use project_id
conversation_id=path_params.conversation_id,
Expand Down Expand Up @@ -128,11 +129,6 @@ async def create_conversation_message(request: web.Request):
template=email_template_path,
context={
"host": request.host,
"product": product.model_dump(
include={
"display_name",
}
),
"first_name": user["first_name"],
"last_name": user["last_name"],
"user_email": user["email"],
Expand Down Expand Up @@ -275,6 +271,7 @@ async def update_conversation_message(request: web.Request):

message = await _conversation_message_service.update_message(
app=request.app,
product_name=req_ctx.product_name,
project_id=None, # Support conversations don't use project_id
conversation_id=path_params.conversation_id,
message_id=path_params.message_id,
Expand Down Expand Up @@ -314,6 +311,7 @@ async def delete_conversation_message(request: web.Request):

await _conversation_message_service.delete_message(
app=request.app,
product_name=req_ctx.product_name,
user_id=req_ctx.user_id,
project_id=None, # Support conversations don't use project_id
conversation_id=path_params.conversation_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PageQueryParameters,
)
from models_library.rest_pagination_utils import paginate_data
from pydantic import BaseModel, ConfigDict, field_validator
from pydantic import ConfigDict, field_validator
from servicelib.aiohttp import status
from servicelib.aiohttp.requests_validation import (
parse_request_body_as,
Expand All @@ -25,16 +25,13 @@
)
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
from simcore_service_webserver.users import users_service

from ..._meta import API_VTAG as VTAG
from ...login.decorators import login_required
from ...models import AuthenticatedRequestContext
from ...utils_aiohttp import envelope_json_response
from .. import conversations_service
from .._conversation_service import (
get_support_conversation_for_user,
list_support_conversations_for_user,
)
from .. import _conversation_service, conversations_service
from ._common import ConversationPathParams, raise_unsupported_type
from ._rest_exceptions import _handle_exceptions

Expand All @@ -43,7 +40,7 @@
routes = web.RouteTableDef()


class _GetConversationsQueryParams(BaseModel):
class _ListConversationsQueryParams(PageQueryParameters):
type: ConversationType
model_config = ConfigDict(extra="forbid")

Expand All @@ -56,11 +53,6 @@ def validate_type(cls, value):
return value


class _ListConversationsQueryParams(PageQueryParameters, _GetConversationsQueryParams):

model_config = ConfigDict(extra="forbid")


class _ConversationsCreateBodyParams(InputSchema):
name: str
type: ConversationType
Expand Down Expand Up @@ -109,14 +101,17 @@ async def list_conversations(request: web.Request):
query_params = parse_request_query_parameters_as(
_ListConversationsQueryParams, request
)
assert query_params.type == ConversationType.SUPPORT # nosec

total, conversations = await list_support_conversations_for_user(
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
offset=query_params.offset,
limit=query_params.limit,
if query_params.type != ConversationType.SUPPORT:
raise_unsupported_type(query_params.type)

total, conversations = (
await _conversation_service.list_support_conversations_for_user(
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
offset=query_params.offset,
limit=query_params.limit,
)
)

page = Page[ConversationRestGet].model_validate(
Expand Down Expand Up @@ -147,12 +142,14 @@ async def get_conversation(request: web.Request):
"""Get a specific conversation"""
req_ctx = AuthenticatedRequestContext.model_validate(request)
path_params = parse_request_path_parameters_as(ConversationPathParams, request)
query_params = parse_request_query_parameters_as(
_GetConversationsQueryParams, request

conversation = await _conversation_service.get_conversation(
request.app, conversation_id=path_params.conversation_id
)
assert query_params.type == ConversationType.SUPPORT # nosec
if conversation.type != ConversationType.SUPPORT:
raise_unsupported_type(conversation.type)

conversation = await get_support_conversation_for_user(
conversation = await _conversation_service.get_support_conversation_for_user(
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
Expand All @@ -174,16 +171,21 @@ async def update_conversation(request: web.Request):
req_ctx = AuthenticatedRequestContext.model_validate(request)
path_params = parse_request_path_parameters_as(ConversationPathParams, request)
body_params = await parse_request_body_as(ConversationPatch, request)
query_params = parse_request_query_parameters_as(
_GetConversationsQueryParams, request

conversation = await _conversation_service.get_conversation(
request.app, conversation_id=path_params.conversation_id
)
assert query_params.type == ConversationType.SUPPORT # nosec
if conversation.type != ConversationType.SUPPORT:
raise_unsupported_type(conversation.type)

await get_support_conversation_for_user(
# Only support conversation creator can update conversation
_user_group_id = await users_service.get_user_primary_group_id(
request.app, user_id=req_ctx.user_id
)
await _conversation_service.get_conversation_for_user(
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
conversation_id=path_params.conversation_id,
user_group_id=_user_group_id,
)

conversation = await conversations_service.update_conversation(
Expand All @@ -207,16 +209,21 @@ async def delete_conversation(request: web.Request):
"""Delete a conversation"""
req_ctx = AuthenticatedRequestContext.model_validate(request)
path_params = parse_request_path_parameters_as(ConversationPathParams, request)
query_params = parse_request_query_parameters_as(
_GetConversationsQueryParams, request

conversation = await _conversation_service.get_conversation(
request.app, conversation_id=path_params.conversation_id
)
assert query_params.type == ConversationType.SUPPORT # nosec
if conversation.type != ConversationType.SUPPORT:
raise_unsupported_type(conversation.type)

await get_support_conversation_for_user(
# Only support conversation creator can delete conversation
_user_group_id = await users_service.get_user_primary_group_id(
request.app, user_id=req_ctx.user_id
)
await _conversation_service.get_conversation_for_user(
app=request.app,
user_id=req_ctx.user_id,
product_name=req_ctx.product_name,
conversation_id=path_params.conversation_id,
user_group_id=_user_group_id,
)

await conversations_service.delete_conversation(
Expand Down
Loading
Loading