Mercurial > kallithea
comparison 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 |
comparison
equal
deleted
inserted
replaced
688:8acbfa837180 | 689:ecc566f8b69f |
---|---|
66 http_user_agent = environ.get('HTTP_USER_AGENT') | 66 http_user_agent = environ.get('HTTP_USER_AGENT') |
67 if http_user_agent and http_user_agent.startswith('git'): | 67 if http_user_agent and http_user_agent.startswith('git'): |
68 return True | 68 return True |
69 return False | 69 return False |
70 | 70 |
71 def action_logger(user, action, repo, ipaddr, sa=None): | 71 def action_logger(user, action, repo, ipaddr='', sa=None): |
72 """ | 72 """ |
73 Action logger for various action made by users | 73 Action logger for various action made by users |
74 | |
75 :param user: user that made this action, can be a string unique username or | |
76 object containing user_id attribute | |
77 :param action: action to log, should be on of predefined unique actions for | |
78 easy translations | |
79 :param repo: repository that action was made on | |
80 :param ipaddr: optional ip address from what the action was made | |
81 :param sa: optional sqlalchemy session | |
82 | |
74 """ | 83 """ |
75 | 84 |
76 if not sa: | 85 if not sa: |
77 sa = meta.Session() | 86 sa = meta.Session() |
78 | 87 |
82 elif isinstance(user, basestring): | 91 elif isinstance(user, basestring): |
83 user_obj = UserModel(sa).get_by_username(user, cache=False) | 92 user_obj = UserModel(sa).get_by_username(user, cache=False) |
84 else: | 93 else: |
85 raise Exception('You have to provide user object or username') | 94 raise Exception('You have to provide user object or username') |
86 | 95 |
87 repo_name = repo.lstrip('/') | 96 |
97 if repo: | |
98 repo_name = repo.lstrip('/') | |
99 | |
100 repository = RepoModel(sa).get(repo_name, cache=False) | |
101 if not repository: | |
102 raise Exception('You have to provide valid repository') | |
103 else: | |
104 raise Exception('You have to provide repository to action logger') | |
105 | |
106 | |
88 user_log = UserLog() | 107 user_log = UserLog() |
89 user_log.user_id = user_obj.user_id | 108 user_log.user_id = user_obj.user_id |
90 user_log.action = action | 109 user_log.action = action |
91 user_log.repository_name = repo_name | 110 user_log.repository_name = repo_name |
92 user_log.repository = RepoModel(sa).get(repo_name, cache=False) | 111 user_log.repository = repository |
93 user_log.action_date = datetime.datetime.now() | 112 user_log.action_date = datetime.datetime.now() |
94 user_log.user_ip = ipaddr | 113 user_log.user_ip = ipaddr |
95 sa.add(user_log) | 114 sa.add(user_log) |
96 sa.commit() | 115 sa.commit() |
97 | 116 |