Skip to content

Commit 81855ce

Browse files
fix support user access permissions to messages
1 parent 9d63834 commit 81855ce

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

services/web/server/src/simcore_service_webserver/conversations/_controller/_conversations_messages_rest.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from ...login.decorators import login_required
3636
from ...models import AuthenticatedRequestContext
3737
from ...products import products_web
38-
from ...users import users_service
3938
from ...utils_aiohttp import envelope_json_response
4039
from .. import _conversation_message_service, _conversation_service
4140
from ._common import ConversationPathParams, raise_unsupported_type
@@ -80,15 +79,19 @@ async def create_conversation_message(request: web.Request):
8079
_ConversationMessageCreateBodyParams, request
8180
)
8281

83-
user = await users_service.get_user(request.app, user_id=req_ctx.user_id)
84-
conversation = await _conversation_service.get_conversation_for_user(
82+
_conversation = await _conversation_service.get_conversation(
83+
request.app, conversation_id=path_params.conversation_id
84+
)
85+
if _conversation.type != ConversationType.SUPPORT:
86+
raise_unsupported_type(_conversation.type)
87+
88+
# This function takes care of granting support user access to the message
89+
await _conversation_service.get_support_conversation_for_user(
8590
app=request.app,
91+
user_id=req_ctx.user_id,
92+
product_name=req_ctx.product_name,
8693
conversation_id=path_params.conversation_id,
87-
user_group_id=user["primary_gid"],
8894
)
89-
# Ensure only support conversations are allowed
90-
if conversation.type != ConversationType.SUPPORT:
91-
raise_unsupported_type(conversation.type)
9295

9396
message, is_first_message = (
9497
await _conversation_message_service.create_support_message_with_first_check(
@@ -162,16 +165,19 @@ async def list_conversation_messages(request: web.Request):
162165
_ListConversationMessageQueryParams, request
163166
)
164167

165-
user_primary_gid = await users_service.get_user_primary_group_id(
166-
request.app, user_id=req_ctx.user_id
168+
_conversation = await _conversation_service.get_conversation(
169+
request.app, conversation_id=path_params.conversation_id
167170
)
168-
conversation = await _conversation_service.get_conversation_for_user(
171+
if _conversation.type != ConversationType.SUPPORT:
172+
raise_unsupported_type(_conversation.type)
173+
174+
# This function takes care of granting support user access to the message
175+
await _conversation_service.get_support_conversation_for_user(
169176
app=request.app,
177+
user_id=req_ctx.user_id,
178+
product_name=req_ctx.product_name,
170179
conversation_id=path_params.conversation_id,
171-
user_group_id=user_primary_gid,
172180
)
173-
if conversation.type != ConversationType.SUPPORT:
174-
raise_unsupported_type(conversation.type)
175181

176182
total, messages = (
177183
await _conversation_message_service.list_messages_for_conversation(
@@ -213,16 +219,19 @@ async def get_conversation_message(request: web.Request):
213219
_ConversationMessagePathParams, request
214220
)
215221

216-
user_primary_gid = await users_service.get_user_primary_group_id(
217-
request.app, user_id=req_ctx.user_id
222+
_conversation = await _conversation_service.get_conversation(
223+
request.app, conversation_id=path_params.conversation_id
218224
)
219-
conversation = await _conversation_service.get_conversation_for_user(
225+
if _conversation.type != ConversationType.SUPPORT:
226+
raise_unsupported_type(_conversation.type)
227+
228+
# This function takes care of granting support user access to the message
229+
await _conversation_service.get_support_conversation_for_user(
220230
app=request.app,
231+
user_id=req_ctx.user_id,
232+
product_name=req_ctx.product_name,
221233
conversation_id=path_params.conversation_id,
222-
user_group_id=user_primary_gid,
223234
)
224-
if conversation.type != ConversationType.SUPPORT:
225-
raise_unsupported_type(conversation.type)
226235

227236
message = await _conversation_message_service.get_message(
228237
app=request.app,
@@ -248,16 +257,19 @@ async def update_conversation_message(request: web.Request):
248257
)
249258
body_params = await parse_request_body_as(ConversationMessagePatch, request)
250259

251-
user_primary_gid = await users_service.get_user_primary_group_id(
252-
request.app, user_id=req_ctx.user_id
260+
_conversation = await _conversation_service.get_conversation(
261+
request.app, conversation_id=path_params.conversation_id
253262
)
254-
conversation = await _conversation_service.get_conversation_for_user(
263+
if _conversation.type != ConversationType.SUPPORT:
264+
raise_unsupported_type(_conversation.type)
265+
266+
# This function takes care of granting support user access to the message
267+
await _conversation_service.get_support_conversation_for_user(
255268
app=request.app,
269+
user_id=req_ctx.user_id,
270+
product_name=req_ctx.product_name,
256271
conversation_id=path_params.conversation_id,
257-
user_group_id=user_primary_gid,
258272
)
259-
if conversation.type != ConversationType.SUPPORT:
260-
raise_unsupported_type(conversation.type)
261273

262274
message = await _conversation_message_service.update_message(
263275
app=request.app,
@@ -284,16 +296,19 @@ async def delete_conversation_message(request: web.Request):
284296
_ConversationMessagePathParams, request
285297
)
286298

287-
user_primary_gid = await users_service.get_user_primary_group_id(
288-
request.app, user_id=req_ctx.user_id
299+
_conversation = await _conversation_service.get_conversation(
300+
request.app, conversation_id=path_params.conversation_id
289301
)
290-
conversation = await _conversation_service.get_conversation_for_user(
302+
if _conversation.type != ConversationType.SUPPORT:
303+
raise_unsupported_type(_conversation.type)
304+
305+
# This function takes care of granting support user access to the message
306+
await _conversation_service.get_support_conversation_for_user(
291307
app=request.app,
308+
user_id=req_ctx.user_id,
309+
product_name=req_ctx.product_name,
292310
conversation_id=path_params.conversation_id,
293-
user_group_id=user_primary_gid,
294311
)
295-
if conversation.type != ConversationType.SUPPORT:
296-
raise_unsupported_type(conversation.type)
297312

298313
await _conversation_message_service.delete_message(
299314
app=request.app,

0 commit comments

Comments
 (0)