Mercurial > kallithea
changeset 4012:55dbc440878b
Fixed bug with log_delete hook didn't properly store
user who triggered delete action
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 18 Jun 2013 02:06:01 +0200 |
parents | 4959e22af6ca |
children | d9a73bfc4107 |
files | rhodecode/lib/utils.py rhodecode/lib/utils2.py rhodecode/model/repo.py |
diffstat | 3 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/utils.py Tue Jun 18 01:45:46 2013 +0200 +++ b/rhodecode/lib/utils.py Tue Jun 18 02:06:01 2013 +0200 @@ -55,7 +55,7 @@ UserLog, RepoGroup, RhodeCodeSetting, CacheInvalidation, UserGroup from rhodecode.model.meta import Session from rhodecode.model.repos_group import ReposGroupModel -from rhodecode.lib.utils2 import safe_str, safe_unicode +from rhodecode.lib.utils2 import safe_str, safe_unicode, get_current_rhodecode_user from rhodecode.lib.vcs.utils.fakemod import create_module from rhodecode.model.users_group import UserGroupModel @@ -150,9 +150,8 @@ sa = meta.Session() # if we don't get explicit IP address try to get one from registered user # in tmpl context var - from pylons import tmpl_context - if not ipaddr and hasattr(tmpl_context, 'rhodecode_user'): - ipaddr = tmpl_context.rhodecode_user.ip_addr + if not ipaddr: + ipaddr = getattr(get_current_rhodecode_user(), 'ip_addr', '') try: if hasattr(user, 'user_id'):
--- a/rhodecode/lib/utils2.py Tue Jun 18 01:45:46 2013 +0200 +++ b/rhodecode/lib/utils2.py Tue Jun 18 02:06:01 2013 +0200 @@ -642,3 +642,14 @@ output.append(_ALPHABET[digit]) unique_id = int(unique_id / alphabet_length) return "".join(output)[:truncate_to] + +def get_current_rhodecode_user(): + """ + Get's rhodecode user from threadlocal tmpl_context variable if it's + defined, else returns None. + """ + from pylons import tmpl_context + if hasattr(tmpl_context, 'rhodecode_user'): + return tmpl_context.rhodecode_user + + return None
--- a/rhodecode/model/repo.py Tue Jun 18 01:45:46 2013 +0200 +++ b/rhodecode/model/repo.py Tue Jun 18 02:06:01 2013 +0200 @@ -32,7 +32,7 @@ from rhodecode.lib.vcs.backends import get_backend from rhodecode.lib.compat import json from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode,\ - remove_prefix, obfuscate_url_pw + remove_prefix, obfuscate_url_pw, get_current_rhodecode_user from rhodecode.lib.caching_query import FromCache from rhodecode.lib.hooks import log_create_repository, log_delete_repository @@ -504,7 +504,7 @@ from rhodecode.lib.celerylib import tasks, run_task run_task(tasks.create_repo_fork, form_data, cur_user) - def delete(self, repo, forks=None, fs_remove=True): + def delete(self, repo, forks=None, fs_remove=True, cur_user=None): """ Delete given repository, forks parameter defines what do do with attached forks. Throws AttachedForksError if deleted repo has attached @@ -514,6 +514,8 @@ :param forks: str 'delete' or 'detach' :param fs_remove: remove(archive) repo from filesystem """ + if not cur_user: + cur_user = getattr(get_current_rhodecode_user(), 'username', '?') repo = self._get_repo(repo) if repo: if forks == 'detach': @@ -535,7 +537,7 @@ else: log.debug('skipping removal from filesystem') log_delete_repository(old_repo_dict, - deleted_by=owner.username) + deleted_by=cur_user) except Exception: log.error(traceback.format_exc()) raise