##// END OF EJS Templates
Fixed bug with log_delete hook didn't properly store...
marcink -
r4012:55dbc440 default
parent child Browse files
Show More
@@ -55,7 +55,7 b' from rhodecode.model.db import Repositor'
55 UserLog, RepoGroup, RhodeCodeSetting, CacheInvalidation, UserGroup
55 UserLog, RepoGroup, RhodeCodeSetting, CacheInvalidation, UserGroup
56 from rhodecode.model.meta import Session
56 from rhodecode.model.meta import Session
57 from rhodecode.model.repos_group import ReposGroupModel
57 from rhodecode.model.repos_group import ReposGroupModel
58 from rhodecode.lib.utils2 import safe_str, safe_unicode
58 from rhodecode.lib.utils2 import safe_str, safe_unicode, get_current_rhodecode_user
59 from rhodecode.lib.vcs.utils.fakemod import create_module
59 from rhodecode.lib.vcs.utils.fakemod import create_module
60 from rhodecode.model.users_group import UserGroupModel
60 from rhodecode.model.users_group import UserGroupModel
61
61
@@ -150,9 +150,8 b' def action_logger(user, action, repo, ip'
150 sa = meta.Session()
150 sa = meta.Session()
151 # if we don't get explicit IP address try to get one from registered user
151 # if we don't get explicit IP address try to get one from registered user
152 # in tmpl context var
152 # in tmpl context var
153 from pylons import tmpl_context
153 if not ipaddr:
154 if not ipaddr and hasattr(tmpl_context, 'rhodecode_user'):
154 ipaddr = getattr(get_current_rhodecode_user(), 'ip_addr', '')
155 ipaddr = tmpl_context.rhodecode_user.ip_addr
156
155
157 try:
156 try:
158 if hasattr(user, 'user_id'):
157 if hasattr(user, 'user_id'):
@@ -642,3 +642,14 b' def suuid(url=None, truncate_to=22, alph'
642 output.append(_ALPHABET[digit])
642 output.append(_ALPHABET[digit])
643 unique_id = int(unique_id / alphabet_length)
643 unique_id = int(unique_id / alphabet_length)
644 return "".join(output)[:truncate_to]
644 return "".join(output)[:truncate_to]
645
646 def get_current_rhodecode_user():
647 """
648 Get's rhodecode user from threadlocal tmpl_context variable if it's
649 defined, else returns None.
650 """
651 from pylons import tmpl_context
652 if hasattr(tmpl_context, 'rhodecode_user'):
653 return tmpl_context.rhodecode_user
654
655 return None
@@ -32,7 +32,7 b' from datetime import datetime'
32 from rhodecode.lib.vcs.backends import get_backend
32 from rhodecode.lib.vcs.backends import get_backend
33 from rhodecode.lib.compat import json
33 from rhodecode.lib.compat import json
34 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode,\
34 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode,\
35 remove_prefix, obfuscate_url_pw
35 remove_prefix, obfuscate_url_pw, get_current_rhodecode_user
36 from rhodecode.lib.caching_query import FromCache
36 from rhodecode.lib.caching_query import FromCache
37 from rhodecode.lib.hooks import log_create_repository, log_delete_repository
37 from rhodecode.lib.hooks import log_create_repository, log_delete_repository
38
38
@@ -504,7 +504,7 b' class RepoModel(BaseModel):'
504 from rhodecode.lib.celerylib import tasks, run_task
504 from rhodecode.lib.celerylib import tasks, run_task
505 run_task(tasks.create_repo_fork, form_data, cur_user)
505 run_task(tasks.create_repo_fork, form_data, cur_user)
506
506
507 def delete(self, repo, forks=None, fs_remove=True):
507 def delete(self, repo, forks=None, fs_remove=True, cur_user=None):
508 """
508 """
509 Delete given repository, forks parameter defines what do do with
509 Delete given repository, forks parameter defines what do do with
510 attached forks. Throws AttachedForksError if deleted repo has attached
510 attached forks. Throws AttachedForksError if deleted repo has attached
@@ -514,6 +514,8 b' class RepoModel(BaseModel):'
514 :param forks: str 'delete' or 'detach'
514 :param forks: str 'delete' or 'detach'
515 :param fs_remove: remove(archive) repo from filesystem
515 :param fs_remove: remove(archive) repo from filesystem
516 """
516 """
517 if not cur_user:
518 cur_user = getattr(get_current_rhodecode_user(), 'username', '?')
517 repo = self._get_repo(repo)
519 repo = self._get_repo(repo)
518 if repo:
520 if repo:
519 if forks == 'detach':
521 if forks == 'detach':
@@ -535,7 +537,7 b' class RepoModel(BaseModel):'
535 else:
537 else:
536 log.debug('skipping removal from filesystem')
538 log.debug('skipping removal from filesystem')
537 log_delete_repository(old_repo_dict,
539 log_delete_repository(old_repo_dict,
538 deleted_by=owner.username)
540 deleted_by=cur_user)
539 except Exception:
541 except Exception:
540 log.error(traceback.format_exc())
542 log.error(traceback.format_exc())
541 raise
543 raise
General Comments 0
You need to be logged in to leave comments. Login now