changeset 5327:fd80edc4aa20

auth: move UserModel.fill_data to AuthUser Because the method is only used by AuthUser, and also because it's an awful thing to do (copying a large but ill-defined set of attributes from one object to another), and we don't want usage to spread.
author Søren Løvborg <kwi@kwi.dk>
date Sun, 26 Jul 2015 14:10:42 +0200
parents 7557da2252a3
children b580691553f5
files kallithea/lib/auth.py kallithea/model/user.py
diffstat 2 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/auth.py	Sun Jul 26 14:10:16 2015 +0200
+++ b/kallithea/lib/auth.py	Sun Jul 26 14:10:42 2015 +0200
@@ -503,11 +503,11 @@
             # Note: dbuser is allowed to be None.
             log.debug('Auth User lookup by database user %s', dbuser)
 
-        is_user_loaded = user_model.fill_data(self, dbuser)
+        is_user_loaded = self._fill_data(dbuser)
 
         # If user cannot be found, try falling back to anonymous.
         if not is_user_loaded:
-            is_user_loaded =  user_model.fill_data(self, self.anonymous_user)
+            is_user_loaded =  self._fill_data(self.anonymous_user)
 
         # The anonymous user is always "logged in".
         if self.user_id == self.anonymous_user.user_id:
@@ -518,6 +518,22 @@
 
         log.debug('Auth User is now %s' % self)
 
+    def _fill_data(self, dbuser):
+        """
+        Copies database fields from a `db.User` to this `AuthUser`. Does
+        not copy `api_keys` and `permissions` attributes.
+
+        Checks that `dbuser` is `active` (and not None) before copying;
+        returns True on success.
+        """
+        if dbuser is not None and dbuser.active:
+            log.debug('filling %s data', dbuser)
+            for k, v in dbuser.get_dict().iteritems():
+                if k not in ['api_keys', 'permissions']:
+                    setattr(self, k, v)
+            return True
+        return False
+
     @LazyProperty
     def permissions(self):
         return self.__get_perms(user=self, cache=False)
--- a/kallithea/model/user.py	Sun Jul 26 14:10:16 2015 +0200
+++ b/kallithea/model/user.py	Sun Jul 26 14:10:42 2015 +0200
@@ -322,25 +322,6 @@
 
         return True
 
-    def fill_data(self, auth_user, dbuser):
-        """
-        Copies database fields from a `db.User` to an `AuthUser`. Does
-        not copy `api_keys` and `permissions` attributes.
-
-        Checks that `dbuser` is `active` (and not None) before copying;
-        returns True on success.
-
-        :param auth_user: instance of user to set attributes
-        :param dbuser: `db.User` instance to copy from
-        """
-        if dbuser is not None and dbuser.active:
-            log.debug('filling %s data' % dbuser)
-            for k, v in dbuser.get_dict().iteritems():
-                if k not in ['api_keys', 'permissions']:
-                    setattr(auth_user, k, v)
-            return True
-        return False
-
     def has_perm(self, user, perm):
         perm = self._get_perm(perm)
         user = self._get_user(user)