##// END OF EJS Templates
logging: use logger_generic in all suitable places, and fix get_current_rhodecode_user()...
marcink -
r2108:03c7441c default
parent child Browse files
Show More
@@ -32,7 +32,6 b' import logging'
32 32 import re
33 33 import sys
34 34 import time
35 import threading
36 35 import urllib
37 36 import urlobject
38 37 import uuid
@@ -44,6 +43,7 b' import sqlalchemy.exc'
44 43 import sqlalchemy.sql
45 44 import webob
46 45 import routes.util
46 import pyramid.threadlocal
47 47
48 48 import rhodecode
49 49 from rhodecode.translation import _, _pluralize
@@ -798,12 +798,17 b' def suuid(url=None, truncate_to=22, alph'
798 798
799 799 def get_current_rhodecode_user():
800 800 """
801 Gets rhodecode user from threadlocal tmpl_context variable if it's
802 defined, else returns None.
801 Gets rhodecode user from request
803 802 """
804 from pylons import tmpl_context as c
805 if hasattr(c, 'rhodecode_user'):
806 return c.rhodecode_user
803 pyramid_request = pyramid.threadlocal.get_current_request()
804
805 # web case
806 if pyramid_request and hasattr(pyramid_request, 'user'):
807 return pyramid_request.user
808
809 # api case
810 if pyramid_request and hasattr(pyramid_request, 'rpc_user'):
811 return pyramid_request.rpc_user
807 812
808 813 return None
809 814
@@ -286,16 +286,14 b' class UserGroupModel(BaseModel):'
286 286 users = user_or_users
287 287 if not isinstance(users, (list, tuple)):
288 288 users = [users]
289 rhodecode_user = get_current_rhodecode_user()
290 ipaddr = getattr(rhodecode_user, 'ip_addr', '')
289
291 290 group_name = user_group.users_group_name
292 291
293 292 for user_or_user_id in users:
294 293 user = self._get_user(user_or_user_id)
295 294 log_text = 'User {user} {action} {group}'.format(
296 295 action=action, user=user.username, group=group_name)
297 log.info('Logging action: {0} by {1} ip:{2}'.format(
298 log_text, rhodecode_user, ipaddr))
296 action_logger_generic(log_text)
299 297
300 298 def _find_user_in_group(self, user, user_group):
301 299 user_group_member = None
General Comments 0
You need to be logged in to leave comments. Login now