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