[req] add a _set_user method
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 25 Jun 2013 17:25:47 +0200
changeset 9051 944d66870c6a
parent 9050 635862b48485
child 9052 4cba5f2cd57b
[req] add a _set_user method RequestSessionBase usally need to recreate a new CWuser appobject linked to themself. We add it to the base class to avoid multiple redifinition.
req.py
--- a/req.py	Mon Jun 24 18:00:20 2013 +0200
+++ b/req.py	Tue Jun 25 17:25:47 2013 +0200
@@ -72,6 +72,23 @@
         self.local_perm_cache = {}
         self._ = unicode
 
+    def _set_user(self, orig_user):
+        """set the user for this req_session_base
+
+        A special method is needed to ensure the linked user is linked to the
+        connection too.
+        """
+        # cnx validity is checked by the call to .user_info
+        rset = self.eid_rset(orig_user.eid, 'CWUser')
+        user_cls = self.vreg['etypes'].etype_class('CWUser')
+        user = user_cls(self, rset, row=0, groups=orig_user.groups,
+                        properties=orig_user.properties)
+        user.cw_attr_cache['login'] = orig_user.login # cache login
+        self.user = user
+        self.set_entity_cache(user)
+        self.set_language(user.prefered_language())
+
+
     def set_language(self, lang):
         """install i18n configuration for `lang` translation.