fix(vcs-operations): fixed problems with locked repos and with branch permissions reporting, previously it shown error 500 when those cases were handled
This commit is contained in:
parent
62690f16e4
commit
d59469e975
5 changed files with 37 additions and 5 deletions
|
|
@ -17,6 +17,7 @@
|
|||
# and proprietary license terms, please see https://rhodecode.com/licenses/
|
||||
|
||||
import logging
|
||||
|
||||
import rhodecode
|
||||
import collections
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ from webhelpers2.text import collapse, strip_tags, convert_accented_entities, co
|
|||
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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue