# HG changeset patch # User RhodeCode Admin # Date 2024-10-06 06:41:02 # Node ID 8026ecb9e90a8628e10ef9c34c1deff101735ea6 # Parent bf8e8ca31b3ce837fe6ff7541c2887e6644b4e05 fix(vcs-operations): fixed problems with locked repos and with branch permissions reporting, previously it shown error 500 when those cases were handled diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -17,6 +17,7 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import logging + import rhodecode import collections diff --git a/rhodecode/lib/hook_daemon/hook_module.py b/rhodecode/lib/hook_daemon/hook_module.py --- a/rhodecode/lib/hook_daemon/hook_module.py +++ b/rhodecode/lib/hook_daemon/hook_module.py @@ -66,12 +66,12 @@ class Hooks(object): result = hook(extras) if result is None: raise Exception(f'Failed to obtain hook result from func: {hook}') - except HTTPBranchProtected as handled_error: + except HTTPBranchProtected as error: # Those special cases don't need error reporting. It's a case of # locked repo or protected branch result = AttributeDict({ - 'status': handled_error.code, - 'output': handled_error.explanation + 'status': error.code, + 'output': error.explanation }) except (HTTPLockedRC, Exception) as error: # locked needs different handling since we need to also diff --git a/rhodecode/lib/hooks_base.py b/rhodecode/lib/hooks_base.py --- a/rhodecode/lib/hooks_base.py +++ b/rhodecode/lib/hooks_base.py @@ -142,6 +142,8 @@ def pre_push(extras): if extras.commit_ids and extras.check_branch_perms: auth_user = user.AuthUser() repo = Repository.get_by_repo_name(extras.repository) + if not repo: + raise ValueError(f'Repo for {extras.repository} not found') affected_branches = [] if repo.repo_type == 'hg': for entry in extras.commit_ids: diff --git a/rhodecode/lib/middleware/simplevcs.py b/rhodecode/lib/middleware/simplevcs.py --- a/rhodecode/lib/middleware/simplevcs.py +++ b/rhodecode/lib/middleware/simplevcs.py @@ -293,7 +293,7 @@ class SimpleVCS(object): def compute_perm_vcs( cache_name, plugin_id, action, user_id, repo_name, ip_addr): - log.debug('auth: calculating permission access now...') + log.debug('auth: calculating permission access now for vcs operation: %s', action) # check IP inherit = user.inherit_default_permissions ip_allowed = AuthUser.check_ip_allowed( diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -43,6 +43,7 @@ from webhelpers2.text import collapse, s from mako import exceptions from rhodecode import ConfigGet +from rhodecode.lib.exceptions import HTTPBranchProtected, HTTPLockedRC from rhodecode.lib.hash_utils import sha256_safe, md5, sha1 from rhodecode.lib.type_utils import AttributeDict from rhodecode.lib.str_utils import safe_bytes, safe_str @@ -88,8 +89,36 @@ def adopt_for_celery(func): try: # HooksResponse implements to_json method which must be used there. return func(extras).to_json() + except HTTPBranchProtected as error: + # Those special cases don't need error reporting. It's a case of + # locked repo or protected branch + error_args = error.args + return { + 'status': error.code, + 'output': error.explanation, + 'exception': type(error).__name__, + 'exception_args': error_args, + 'exception_traceback': '', + } + except HTTPLockedRC as error: + # Those special cases don't need error reporting. It's a case of + # locked repo or protected branch + error_args = error.args + return { + 'status': error.code, + 'output': error.explanation, + 'exception': type(error).__name__, + 'exception_args': error_args, + 'exception_traceback': '', + } except Exception as e: - return {'status': 128, 'exception': type(e).__name__, 'exception_args': e.args} + return { + 'status': 128, + 'output': '', + 'exception': type(e).__name__, + 'exception_args': e.args, + 'exception_traceback': '', + } return wrapper