logging: use logger_generic in all suitable places, and fix get_current_rhodecode_user()
function to use the new mechanics from pyramid. Fixes #5390
This commit is contained in:
parent
24a6e0ad1a
commit
13e4927d13
2 changed files with 13 additions and 10 deletions
|
|
@ -32,7 +32,6 @@ import logging
|
|||
import re
|
||||
import sys
|
||||
import time
|
||||
import threading
|
||||
import urllib
|
||||
import urlobject
|
||||
import uuid
|
||||
|
|
@ -44,6 +43,7 @@ import sqlalchemy.exc
|
|||
import sqlalchemy.sql
|
||||
import webob
|
||||
import routes.util
|
||||
import pyramid.threadlocal
|
||||
|
||||
import rhodecode
|
||||
from rhodecode.translation import _, _pluralize
|
||||
|
|
@ -798,12 +798,17 @@ def suuid(url=None, truncate_to=22, alphabet=None):
|
|||
|
||||
def get_current_rhodecode_user():
|
||||
"""
|
||||
Gets rhodecode user from threadlocal tmpl_context variable if it's
|
||||
defined, else returns None.
|
||||
Gets rhodecode user from request
|
||||
"""
|
||||
from pylons import tmpl_context as c
|
||||
if hasattr(c, 'rhodecode_user'):
|
||||
return c.rhodecode_user
|
||||
pyramid_request = pyramid.threadlocal.get_current_request()
|
||||
|
||||
# web case
|
||||
if pyramid_request and hasattr(pyramid_request, 'user'):
|
||||
return pyramid_request.user
|
||||
|
||||
# api case
|
||||
if pyramid_request and hasattr(pyramid_request, 'rpc_user'):
|
||||
return pyramid_request.rpc_user
|
||||
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -286,16 +286,14 @@ class UserGroupModel(BaseModel):
|
|||
users = user_or_users
|
||||
if not isinstance(users, (list, tuple)):
|
||||
users = [users]
|
||||
rhodecode_user = get_current_rhodecode_user()
|
||||
ipaddr = getattr(rhodecode_user, 'ip_addr', '')
|
||||
|
||||
group_name = user_group.users_group_name
|
||||
|
||||
for user_or_user_id in users:
|
||||
user = self._get_user(user_or_user_id)
|
||||
log_text = 'User {user} {action} {group}'.format(
|
||||
action=action, user=user.username, group=group_name)
|
||||
log.info('Logging action: {0} by {1} ip:{2}'.format(
|
||||
log_text, rhodecode_user, ipaddr))
|
||||
action_logger_generic(log_text)
|
||||
|
||||
def _find_user_in_group(self, user, user_group):
|
||||
user_group_member = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue