changeset 5692:52356a58c1f6

middleware: allow git and hg users to use email address instead of the username This commit also replaces __get_user('default') with a call to a more widely used User.get_default_user() function, and removes no longer really used __get_user() methods from both SimpleHg and SimpleGit.
author Andrew Shadura <andrew@shadura.me>
date Sat, 30 Jan 2016 16:38:26 +0100
parents b24e015a4174
children 460520415b67
files kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py
diffstat 2 files changed, 4 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/middleware/simplegit.py	Sat Jan 30 16:37:43 2016 +0100
+++ b/kallithea/lib/middleware/simplegit.py	Sat Jan 30 16:38:26 2016 +0100
@@ -99,7 +99,7 @@
         # CHECK ANONYMOUS PERMISSION
         #======================================================================
         if action in ['pull', 'push']:
-            anonymous_user = self.__get_user('default')
+            anonymous_user = User.get_default_user(cache=True)
             username = anonymous_user.username
             if anonymous_user.active:
                 # ONLY check permissions if the user is activated
@@ -146,7 +146,7 @@
                 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
                 #==============================================================
                 try:
-                    user = self.__get_user(username)
+                    user = User.get_by_username_or_email(username)
                     if user is None or not user.active:
                         return HTTPForbidden()(environ, start_response)
                     username = user.username
@@ -248,9 +248,6 @@
 
         return repo_name
 
-    def __get_user(self, username):
-        return User.get_by_username(username)
-
     def __get_action(self, environ):
         """
         Maps git request commands into a pull or push command.
--- a/kallithea/lib/middleware/simplehg.py	Sat Jan 30 16:37:43 2016 +0100
+++ b/kallithea/lib/middleware/simplehg.py	Sat Jan 30 16:38:26 2016 +0100
@@ -105,7 +105,7 @@
         # CHECK ANONYMOUS PERMISSION
         #======================================================================
         if action in ['pull', 'push']:
-            anonymous_user = self.__get_user('default')
+            anonymous_user = User.get_default_user(cache=True)
             username = anonymous_user.username
             if anonymous_user.active:
                 # ONLY check permissions if the user is activated
@@ -152,7 +152,7 @@
                 # CHECK PERMISSIONS FOR THIS REQUEST USING GIVEN USERNAME
                 #==============================================================
                 try:
-                    user = self.__get_user(username)
+                    user = User.get_by_username_or_email(username)
                     if user is None or not user.active:
                         return HTTPForbidden()(environ, start_response)
                     username = user.username
@@ -248,9 +248,6 @@
 
         return repo_name
 
-    def __get_user(self, username):
-        return User.get_by_username(username)
-
     def __get_action(self, environ):
         """
         Maps mercurial request commands into a clone,pull or push command.