Mercurial > libervia-web
changeset 1266:6b7f9c3558cc
server, pages: better identities handling:
- own identity is now retrieve on connection
- use session identities all the time, fixed pages where an empty dict was used
- identities and own_jid are alway set in template_data for normal rendering
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 19 May 2020 11:02:32 +0200 |
parents | 24e2973378f6 |
children | b5f920845d34 |
files | libervia/pages/blog/page_meta.py libervia/pages/blog/view/page_meta.py libervia/pages/chat/page_meta.py libervia/pages/forums/topics/page_meta.py libervia/server/pages.py libervia/server/server.py |
diffstat | 6 files changed, 19 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/pages/blog/page_meta.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/pages/blog/page_meta.py Tue May 19 11:02:32 2020 +0200 @@ -35,7 +35,7 @@ list(entities_own.keys()) + list(entities_roster.keys()) ) entities_url = template_data["entities_url"] = {} - identities = template_data["identities"] = self.host.getSessionData( + identities = self.host.getSessionData( request, session_iface.ISATSession ).identities d_list = []
--- a/libervia/pages/blog/view/page_meta.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/pages/blog/view/page_meta.py Tue May 19 11:02:32 2020 +0200 @@ -214,7 +214,7 @@ ## identities ## # identities are used to show nice nickname or avatars - identities = template_data['identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities + identities = self.host.getSessionData(request, session_iface.ISATSession).identities ## Comments ## # if comments are requested, we need to take them
--- a/libervia/pages/chat/page_meta.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/pages/chat/page_meta.py Tue May 19 11:02:32 2020 +0200 @@ -84,14 +84,14 @@ profile, ) authors = {m[2] for m in history} - identities = {} + identities = session.identities for author in authors: id_raw = yield self.host.bridgeCall( "identityGet", author, [], True, profile) identities[author] = data_format.deserialise(id_raw) template_data["messages"] = data_objects.Messages(history) - rdata['identities'] = template_data["identities"] = identities + rdata['identities'] = identities template_data["target_jid"] = target_jid template_data["chat_type"] = chat_type
--- a/libervia/pages/forums/topics/page_meta.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/pages/forums/topics/page_meta.py Tue May 19 11:02:32 2020 +0200 @@ -29,7 +29,9 @@ topics, metadata = yield self.host.bridgeCall( "forumTopicsGet", service.full(), node, {}, profile ) - template_data["identities"] = identities = {} + identities = self.host.getSessionData( + request, session_iface.ISATSession + ).identities for topic in topics: parsed_uri = xmpp_uri.parseXMPPUri(topic["uri"]) author = topic["author"]
--- a/libervia/server/pages.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/server/pages.py Tue May 19 11:02:32 2020 +0200 @@ -1308,11 +1308,14 @@ # if confirm variable is set in case of successfuly data post session_data = self.host.getSessionData(request, session_iface.ISATSession) + template_data['identities'] = session_data.identities if session_data.popPageFlag(self, C.FLAG_CONFIRM): template_data["confirm"] = True notifs = session_data.popPageNotifications(self) if notifs: template_data["notifications"] = notifs + if session_data.jid is not None: + template_data["own_jid"] = session_data.jid if session_data.locale is not None: template_data['locale'] = session_data.locale if self.vhost_root.site_name:
--- a/libervia/server/server.py Tue May 19 11:02:31 2020 +0200 +++ b/libervia/server/server.py Tue May 19 11:02:32 2020 +0200 @@ -51,6 +51,7 @@ from sat.tools.common import template from sat.tools.common import uri as common_uri from sat.tools.common.utils import recursive_update +from sat.tools.common import data_format import libervia from libervia.server import websockets from libervia.server.pages import LiberviaPage @@ -1015,8 +1016,7 @@ getattr(self.bridge, method_name)(*args, **kwargs) return d - @defer.inlineCallbacks - def _logged(self, profile, request): + async def _logged(self, profile, request): """Set everything when a user just logged in @param profile @@ -1061,12 +1061,16 @@ session.notifyOnExpire(onExpire) # FIXME: those session infos should be returned by connect or isConnected - infos = yield self.bridgeCall("sessionInfosGet", profile) + infos = await self.bridgeCall("sessionInfosGet", profile) sat_session.jid = jid.JID(infos["jid"]) + own_bare_jid_s = sat_session.jid.userhost() + own_id_raw = await self.bridgeCall( + "identityGet", own_bare_jid_s, [], True, profile) + sat_session.identities[own_bare_jid_s] = data_format.deserialise(own_id_raw) sat_session.backend_started = int(infos["started"]) state = C.PROFILE_LOGGED_EXT_JID if register_with_ext_jid else C.PROFILE_LOGGED - defer.returnValue(state) + return state @defer.inlineCallbacks def connect(self, request, login, password): @@ -1218,7 +1222,7 @@ ) # no, we have to create it - state = yield self._logged(profile, request) + state = yield defer.ensureDeferred(self._logged(profile, request)) defer.returnValue(state) def registerNewAccount(self, request, login, password, email):