Mercurial > libervia-web
comparison libervia/web/pages/g/page_meta.py @ 1599:197350e8bf3b
pages(g): fix guest session data:
Following https://repos.goffi.org/libervia-web/rev/86c7a3a625d5, new session are now
started on connection, as a result, guest data were lost on connection. This patch fixes
it by storing those data after the connection.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 16:40:25 +0100 |
parents | eb00d593801d |
children |
comparison
equal
deleted
inserted
replaced
1598:86c7a3a625d5 | 1599:197350e8bf3b |
---|---|
19 """ | 19 """ |
20 try: | 20 try: |
21 invitation_id = self.next_path(request) | 21 invitation_id = self.next_path(request) |
22 except IndexError: | 22 except IndexError: |
23 self.page_error(request) | 23 self.page_error(request) |
24 return | |
24 | 25 |
25 web_session, guest_session = self.host.get_session_data( | 26 web_session, guest_session = self.host.get_session_data( |
26 request, session_iface.IWebSession, session_iface.IWebGuestSession | 27 request, session_iface.IWebSession, session_iface.IWebGuestSession |
27 ) | 28 ) |
28 current_id = guest_session.id | 29 current_id = guest_session.id |
29 | 30 |
30 if current_id is not None and current_id != invitation_id: | 31 if current_id is not None and current_id != invitation_id: |
32 # we are already in a guest session, but not the one specified in URL, we reset id | |
31 log.info( | 33 log.info( |
32 _( | 34 _( |
33 "killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]" | 35 "killing guest session [{old_id}] because it is connecting with an other ID [{new_id}]" |
34 ).format(old_id=current_id, new_id=invitation_id) | 36 ).format(old_id=current_id, new_id=invitation_id) |
35 ) | 37 ) |
57 log.debug(_("checking invitation [{id}]").format(id=invitation_id)) | 59 log.debug(_("checking invitation [{id}]").format(id=invitation_id)) |
58 try: | 60 try: |
59 data = await self.host.bridge_call("invitation_get", invitation_id) | 61 data = await self.host.bridge_call("invitation_get", invitation_id) |
60 except Exception: | 62 except Exception: |
61 self.page_error(request, C.HTTP_FORBIDDEN) | 63 self.page_error(request, C.HTTP_FORBIDDEN) |
62 else: | 64 return |
63 guest_session.id = invitation_id | |
64 guest_session.data = data | |
65 else: | 65 else: |
66 data = guest_session.data | 66 data = guest_session.data |
67 | 67 |
68 if profile is None: | 68 if profile is None: |
69 log.debug(_("connecting profile [{}]").format(profile)) | 69 log.debug(_("connecting profile [{}]").format(profile)) |
75 except Exception as e: | 75 except Exception as e: |
76 log.warning(_("Can't connect profile: {msg}").format(msg=e)) | 76 log.warning(_("Can't connect profile: {msg}").format(msg=e)) |
77 # FIXME: no good error code correspond | 77 # FIXME: no good error code correspond |
78 # maybe use a custom one? | 78 # maybe use a custom one? |
79 self.page_error(request, code=C.HTTP_SERVICE_UNAVAILABLE) | 79 self.page_error(request, code=C.HTTP_SERVICE_UNAVAILABLE) |
80 else: | |
81 # a new session is created, we need to store guest session data | |
82 __, guest_session = self.host.get_session_data( | |
83 request, session_iface.IWebSession, session_iface.IWebGuestSession | |
84 ) | |
85 guest_session.id = invitation_id | |
86 guest_session.data = data | |
80 | 87 |
81 log.info( | 88 log.info( |
82 _( | 89 _( |
83 "guest session started, connected with profile [{profile}]".format( | 90 "guest session started, connected with profile [{profile}]".format( |
84 profile=profile | 91 profile=profile |