Skip to content

Commit

Permalink
🎨 Emit proper product name on socketio connection (#5285)
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 authored Jan 31, 2024
1 parent 6706f0f commit ffc15b7
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from aiohttp import web
from models_library.api_schemas_webserver.socketio import SocketIORoomStr
from models_library.products import ProductName
from models_library.socketio import SocketMessageDict
from models_library.users import UserID
from servicelib.aiohttp.observer import emit
Expand All @@ -18,6 +19,7 @@

from ..groups.api import list_user_groups
from ..login.decorators import login_required
from ..products.api import Product, get_current_product
from ..resource_manager.user_sessions import managed_resource
from ._utils import EnvironDict, SocketID, get_socket_server, register_socketio_handler
from .messages import SOCKET_IO_HEARTBEAT_EVENT, send_messages
Expand All @@ -41,14 +43,15 @@

def auth_user_factory(socket_id: SocketID):
@login_required
async def _handler(request: web.Request) -> UserID:
async def _handler(request: web.Request) -> tuple[UserID, ProductName]:
"""
Raises:
web.HTTPUnauthorized: when the user is not recognized. Keeps the original request
"""
app = request.app
user_id = UserID(request.get(RQT_USERID_KEY, _ANONYMOUS_USER_ID))
client_session_id = request.query.get("client_session_id", None)
product: Product = get_current_product(request)

_logger.debug(
"client %s,%s authenticated", f"{user_id=}", f"{client_session_id=}"
Expand Down Expand Up @@ -76,7 +79,7 @@ async def _handler(request: web.Request) -> UserID:
)
await resource_registry.set_socket_id(socket_id)

return user_id
return user_id, product.name

return _handler

Expand Down Expand Up @@ -121,7 +124,7 @@ async def connect(

try:
auth_user_handler = auth_user_factory(socket_id)
user_id = await auth_user_handler(environ["aiohttp.request"])
user_id, product_name = await auth_user_handler(environ["aiohttp.request"])

await _set_user_in_group_rooms(app, user_id, socket_id)

Expand All @@ -132,7 +135,7 @@ async def connect(
"SIGNAL_USER_CONNECTED",
user_id,
app,
"s4l", # NOTE: will be changed after https://github.com/ITISFoundation/osparc-simcore/issues/4776
product_name,
)

heart_beat_messages: list[SocketMessageDict] = [
Expand Down

0 comments on commit ffc15b7

Please sign in to comment.