Changeset - 55dbc440878b
[Not reviewed]
default
0 3 0
Marcin Kuzminski - 12 years ago 2013-06-18 02:06:01
marcin@python-works.com
Fixed bug with log_delete hook didn't properly store
user who triggered delete action
3 files changed with 19 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/utils.py
Show inline comments
 
@@ -55,7 +55,7 @@ from rhodecode.model.db import Repositor
 
    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 @@ def action_logger(user, action, repo, ip
 
        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'):
rhodecode/lib/utils2.py
Show inline comments
 
@@ -642,3 +642,14 @@ def suuid(url=None, truncate_to=22, alph
 
        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
rhodecode/model/repo.py
Show inline comments
 
@@ -32,7 +32,7 @@ from datetime import datetime
 
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 @@ class RepoModel(BaseModel):
 
        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 @@ class RepoModel(BaseModel):
 
        :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 @@ class RepoModel(BaseModel):
 
                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
0 comments (0 inline, 0 general)