##// END OF EJS Templates
api: refactor auth helpers to reflect the action they do....
marcink -
r1150:081f50ab default
parent child Browse files
Show More
@@ -249,7 +249,7 b' class TestRepoAccess(object):'
249 fake_repo = Mock()
249 fake_repo = Mock()
250 with self.repo_perm_patch as rmock:
250 with self.repo_perm_patch as rmock:
251 rmock.return_value = repo_mock
251 rmock.return_value = repo_mock
252 assert utils.has_repo_permissions(
252 assert utils.validate_repo_permissions(
253 'fake_user', 'fake_repo_id', fake_repo,
253 'fake_user', 'fake_repo_id', fake_repo,
254 ['perm1', 'perm2'])
254 ['perm1', 'perm2'])
255 rmock.assert_called_once_with(*['perm1', 'perm2'])
255 rmock.assert_called_once_with(*['perm1', 'perm2'])
@@ -263,6 +263,6 b' class TestRepoAccess(object):'
263 with self.repo_perm_patch as rmock:
263 with self.repo_perm_patch as rmock:
264 rmock.return_value = repo_mock
264 rmock.return_value = repo_mock
265 with pytest.raises(JSONRPCError) as excinfo:
265 with pytest.raises(JSONRPCError) as excinfo:
266 utils.has_repo_permissions(
266 utils.validate_repo_permissions(
267 'fake_user', 'fake_repo_id', fake_repo, 'perms')
267 'fake_user', 'fake_repo_id', fake_repo, 'perms')
268 assert 'fake_repo_id' in excinfo
268 assert 'fake_repo_id' in excinfo
@@ -154,7 +154,7 b' def has_superadmin_permission(apiuser):'
154 return False
154 return False
155
155
156
156
157 def has_repo_permissions(apiuser, repoid, repo, perms):
157 def validate_repo_permissions(apiuser, repoid, repo, perms):
158 """
158 """
159 Raise JsonRPCError if apiuser is not authorized or return True
159 Raise JsonRPCError if apiuser is not authorized or return True
160
160
@@ -188,7 +188,7 b' def validate_repo_group_permissions(apiu'
188 return True
188 return True
189
189
190
190
191 def has_set_owner_permissions(apiuser, owner):
191 def validate_set_owner_permissions(apiuser, owner):
192 if isinstance(owner, Optional):
192 if isinstance(owner, Optional):
193 owner = get_user_or_error(apiuser.user_id)
193 owner = get_user_or_error(apiuser.user_id)
194 else:
194 else:
@@ -25,7 +25,7 b' from rhodecode.api import jsonrpc_method'
25 from rhodecode.api.utils import (
25 from rhodecode.api.utils import (
26 has_superadmin_permission, Optional, OAttr, get_repo_or_error,
26 has_superadmin_permission, Optional, OAttr, get_repo_or_error,
27 get_pull_request_or_error, get_commit_or_error, get_user_or_error,
27 get_pull_request_or_error, get_commit_or_error, get_user_or_error,
28 has_repo_permissions, resolve_ref_or_error)
28 validate_repo_permissions, resolve_ref_or_error)
29 from rhodecode.lib.auth import (HasRepoPermissionAnyApi)
29 from rhodecode.lib.auth import (HasRepoPermissionAnyApi)
30 from rhodecode.lib.base import vcs_operation_context
30 from rhodecode.lib.base import vcs_operation_context
31 from rhodecode.lib.utils2 import str2bool
31 from rhodecode.lib.utils2 import str2bool
@@ -215,7 +215,7 b' def get_pull_requests(request, apiuser, '
215 if not has_superadmin_permission(apiuser):
215 if not has_superadmin_permission(apiuser):
216 _perms = (
216 _perms = (
217 'repository.admin', 'repository.write', 'repository.read',)
217 'repository.admin', 'repository.write', 'repository.read',)
218 has_repo_permissions(apiuser, repoid, repo, _perms)
218 validate_repo_permissions(apiuser, repoid, repo, _perms)
219
219
220 status = Optional.extract(status)
220 status = Optional.extract(status)
221 pull_requests = PullRequestModel().get_all(repo, statuses=[status])
221 pull_requests = PullRequestModel().get_all(repo, statuses=[status])
@@ -504,7 +504,7 b' def create_pull_request('
504 target = get_repo_or_error(target_repo)
504 target = get_repo_or_error(target_repo)
505 if not has_superadmin_permission(apiuser):
505 if not has_superadmin_permission(apiuser):
506 _perms = ('repository.admin', 'repository.write', 'repository.read',)
506 _perms = ('repository.admin', 'repository.write', 'repository.read',)
507 has_repo_permissions(apiuser, source_repo, source, _perms)
507 validate_repo_permissions(apiuser, source_repo, source, _perms)
508
508
509 full_source_ref = resolve_ref_or_error(source_ref, source)
509 full_source_ref = resolve_ref_or_error(source_ref, source)
510 full_target_ref = resolve_ref_or_error(target_ref, target)
510 full_target_ref = resolve_ref_or_error(target_ref, target)
General Comments 0
You need to be logged in to leave comments. Login now