diff rhodecode/lib/utils.py @ 689:ecc566f8b69f beta

fixes #59, notifications for user registrations + some changes to mailer
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 14 Nov 2010 19:57:14 +0100
parents 8acbfa837180
children cb0d9ce6ac5c
line wrap: on
line diff
--- a/rhodecode/lib/utils.py	Sun Nov 14 17:24:32 2010 +0100
+++ b/rhodecode/lib/utils.py	Sun Nov 14 19:57:14 2010 +0100
@@ -68,9 +68,18 @@
         return True
     return False
 
-def action_logger(user, action, repo, ipaddr, sa=None):
+def action_logger(user, action, repo, ipaddr='', sa=None):
     """
     Action logger for various action made by users
+    
+    :param user: user that made this action, can be a string unique username or
+        object containing user_id attribute
+    :param action: action to log, should be on of predefined unique actions for
+        easy translations
+    :param repo: repository that action was made on
+    :param ipaddr: optional ip address from what the action was made
+    :param sa: optional sqlalchemy session
+    
     """
 
     if not sa:
@@ -84,12 +93,22 @@
         else:
             raise Exception('You have to provide user object or username')
 
-        repo_name = repo.lstrip('/')
+
+        if repo:
+            repo_name = repo.lstrip('/')
+
+            repository = RepoModel(sa).get(repo_name, cache=False)
+            if not repository:
+                raise Exception('You have to provide valid repository')
+        else:
+            raise Exception('You have to provide repository to action logger')
+
+
         user_log = UserLog()
         user_log.user_id = user_obj.user_id
         user_log.action = action
         user_log.repository_name = repo_name
-        user_log.repository = RepoModel(sa).get(repo_name, cache=False)
+        user_log.repository = repository
         user_log.action_date = datetime.datetime.now()
         user_log.user_ip = ipaddr
         sa.add(user_log)