##// END OF EJS Templates
api: modernize code for python3
super-admin -
r5092:d0d88608 default
parent child Browse files
Show More
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -114,7 +112,7 b' def jsonrpc_response(request, result):'
114 112 )
115 113
116 114
117 def jsonrpc_error(request, message, retid=None, code: typing.Optional[int] = None, headers: typing.Optional[dict] = None):
115 def jsonrpc_error(request, message, retid=None, code: int | None = None, headers: dict | None = None):
118 116 """
119 117 Generate a Response object with a JSON-RPC error body
120 118 """
@@ -174,9 +172,9 b' def exception_view(exc, request):'
174 172
175 173 statsd = request.registry.statsd
176 174 if statsd:
177 exc_type = "{}.{}".format(exc.__class__.__module__, exc.__class__.__name__)
175 exc_type = f"{exc.__class__.__module__}.{exc.__class__.__name__}"
178 176 statsd.incr('rhodecode_exception_total',
179 tags=["exc_source:api", "type:{}".format(exc_type)])
177 tags=["exc_source:api", f"type:{exc_type}"])
180 178
181 179 return jsonrpc_error(request, fault_message, rpc_id)
182 180
@@ -210,8 +208,8 b' def request_view(request):'
210 208 if not auth_u.ip_allowed:
211 209 return jsonrpc_error(
212 210 request, retid=request.rpc_id,
213 message='Request from IP:%s not allowed' % (
214 request.rpc_ip_addr,))
211 message='Request from IP:{} not allowed'.format(
212 request.rpc_ip_addr))
215 213 else:
216 214 log.info('Access for IP:%s allowed', request.rpc_ip_addr)
217 215
@@ -357,7 +355,7 b' def setup_request(request):'
357 355 json_body = ext_json.json.loads(raw_body)
358 356 except ValueError as e:
359 357 # catch JSON errors Here
360 raise JSONRPCError("JSON parse error ERR:%s RAW:%r" % (e, raw_body))
358 raise JSONRPCError("JSON parse error ERR:{} RAW:{!r}".format(e, raw_body))
361 359
362 360 request.rpc_id = json_body.get('id')
363 361 request.rpc_method = json_body.get('method')
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -22,7 +20,7 b''
22 20 class JSONRPCBaseError(Exception):
23 21 def __init__(self, message='', *args):
24 22 self.message = message
25 super(JSONRPCBaseError, self).__init__(message, *args)
23 super().__init__(message, *args)
26 24
27 25
28 26 class JSONRPCError(JSONRPCBaseError):
@@ -33,7 +31,7 b' class JSONRPCValidationError(JSONRPCBase'
33 31
34 32 def __init__(self, *args, **kwargs):
35 33 self.colander_exception = kwargs.pop('colander_exc')
36 super(JSONRPCValidationError, self).__init__(
34 super().__init__(
37 35 message=self.colander_exception, *args)
38 36
39 37
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -224,7 +222,7 b' def get_user_or_error(userid):'
224 222
225 223 if user is None:
226 224 raise JSONRPCError(
227 'user `%s` does not exist' % (userid,))
225 'user `{}` does not exist'.format(userid))
228 226 return user
229 227
230 228
@@ -247,7 +245,7 b' def get_repo_or_error(repoid):'
247 245
248 246 if repo is None:
249 247 raise JSONRPCError(
250 'repository `%s` does not exist' % (repoid,))
248 'repository `{}` does not exist'.format(repoid))
251 249 return repo
252 250
253 251
@@ -270,7 +268,7 b' def get_repo_group_or_error(repogroupid)'
270 268
271 269 if repo_group is None:
272 270 raise JSONRPCError(
273 'repository group `%s` does not exist' % (repogroupid,))
271 'repository group `{}` does not exist'.format(repogroupid))
274 272 return repo_group
275 273
276 274
@@ -293,7 +291,7 b' def get_user_group_or_error(usergroupid)'
293 291
294 292 if user_group is None:
295 293 raise JSONRPCError(
296 'user group `%s` does not exist' % (usergroupid,))
294 'user group `{}` does not exist'.format(usergroupid))
297 295 return user_group
298 296
299 297
@@ -307,9 +305,9 b' def get_perm_or_error(permid, prefix=Non'
307 305
308 306 perm = PermissionModel.cls.get_by_key(permid)
309 307 if perm is None:
310 msg = 'permission `{}` does not exist.'.format(permid)
308 msg = f'permission `{permid}` does not exist.'
311 309 if prefix:
312 msg += ' Permission should start with prefix: `{}`'.format(prefix)
310 msg += f' Permission should start with prefix: `{prefix}`'
313 311 raise JSONRPCError(msg)
314 312
315 313 if prefix:
@@ -329,7 +327,7 b' def get_gist_or_error(gistid):'
329 327
330 328 gist = GistModel.cls.get_by_access_id(gistid)
331 329 if gist is None:
332 raise JSONRPCError('gist `%s` does not exist' % (gistid,))
330 raise JSONRPCError('gist `{}` does not exist'.format(gistid))
333 331 return gist
334 332
335 333
@@ -346,8 +344,8 b' def get_pull_request_or_error(pullreques'
346 344 except ValueError:
347 345 raise JSONRPCError('pullrequestid must be an integer')
348 346 if not pull_request:
349 raise JSONRPCError('pull request `%s` does not exist' % (
350 pullrequestid,))
347 raise JSONRPCError('pull request `{}` does not exist'.format(
348 pullrequestid))
351 349 return pull_request
352 350
353 351
@@ -394,7 +392,7 b' def get_commit_or_error(ref, repo):'
394 392 # once get_commit supports ref_types
395 393 return get_commit_from_ref_name(repo, ref_hash)
396 394 except RepositoryError:
397 raise JSONRPCError('Ref `{ref}` does not exist'.format(ref=ref))
395 raise JSONRPCError(f'Ref `{ref}` does not exist')
398 396
399 397
400 398 def _get_ref_hash(repo, type_, name):
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2015-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -51,13 +49,13 b' def get_gist(request, apiuser, gistid, c'
51 49
52 50 if not has_superadmin_permission(apiuser):
53 51 if gist.gist_owner != apiuser.user_id:
54 raise JSONRPCError('gist `%s` does not exist' % (gistid,))
52 raise JSONRPCError('gist `{}` does not exist'.format(gistid))
55 53 data = gist.get_api_data()
56 54
57 55 if content:
58 56 from rhodecode.model.gist import GistModel
59 57 rev, gist_files = GistModel().get_gist_files(gistid)
60 data['content'] = dict([(x.path, x.str_content) for x in gist_files])
58 data['content'] = {x.path: x.str_content for x in gist_files}
61 59 return data
62 60
63 61
@@ -242,13 +240,13 b' def delete_gist(request, apiuser, gistid'
242 240 gist = get_gist_or_error(gistid)
243 241 if not has_superadmin_permission(apiuser):
244 242 if gist.gist_owner != apiuser.user_id:
245 raise JSONRPCError('gist `%s` does not exist' % (gistid,))
243 raise JSONRPCError('gist `{}` does not exist'.format(gistid))
246 244
247 245 try:
248 246 GistModel().delete(gist)
249 247 Session().commit()
250 248 return {
251 'msg': 'deleted gist ID:%s' % (gist.gist_access_id,),
249 'msg': 'deleted gist ID:{}'.format(gist.gist_access_id),
252 250 'gist': None
253 251 }
254 252 except Exception:
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -322,7 +320,7 b' def merge_pull_request('
322 320
323 321 reasons = ','.join(error_messages)
324 322 raise JSONRPCError(
325 'merge not possible for following reasons: {}'.format(reasons))
323 f'merge not possible for following reasons: {reasons}')
326 324
327 325 target_repo = pull_request.target_repo
328 326 extras = vcs_operation_context(
@@ -529,7 +527,7 b' def comment_pull_request('
529 527
530 528 if not PullRequestModel().check_user_read(
531 529 pull_request, apiuser, api=True):
532 raise JSONRPCError('repository `%s` does not exist' % (repoid,))
530 raise JSONRPCError('repository `{}` does not exist'.format(repoid))
533 531 message = Optional.extract(message)
534 532 status = Optional.extract(status)
535 533 commit_id = Optional.extract(commit_id)
@@ -758,7 +756,7 b' def create_pull_request('
758 756 reviewers = validate_default_reviewers(
759 757 reviewer_objects, default_reviewers_data)
760 758 except ValueError as e:
761 raise JSONRPCError('Reviewers Validation: {}'.format(e))
759 raise JSONRPCError(f'Reviewers Validation: {e}')
762 760
763 761 # now MERGE our given with the calculated from the default rules
764 762 just_observers = [
@@ -770,7 +768,7 b' def create_pull_request('
770 768 observers = validate_observers(
771 769 observer_objects, default_reviewers_data)
772 770 except ValueError as e:
773 raise JSONRPCError('Observer Validation: {}'.format(e))
771 raise JSONRPCError(f'Observer Validation: {e}')
774 772
775 773 title = Optional.extract(title)
776 774 if not title:
@@ -820,7 +818,7 b' def create_pull_request('
820 818
821 819 Session().commit()
822 820 data = {
823 'msg': 'Created new pull request `{}`'.format(title),
821 'msg': f'Created new pull request `{title}`',
824 822 'pull_request_id': pull_request.pull_request_id,
825 823 }
826 824 return data
@@ -903,12 +901,12 b' def update_pull_request('
903 901 if not PullRequestModel().check_user_update(
904 902 pull_request, apiuser, api=True):
905 903 raise JSONRPCError(
906 'pull request `%s` update failed, no permission to update.' % (
907 pullrequestid,))
904 'pull request `{}` update failed, no permission to update.'.format(
905 pullrequestid))
908 906 if pull_request.is_closed():
909 907 raise JSONRPCError(
910 'pull request `%s` update failed, pull request is closed' % (
911 pullrequestid,))
908 'pull request `{}` update failed, pull request is closed'.format(
909 pullrequestid))
912 910
913 911 reviewer_objects = Optional.extract(reviewers) or []
914 912 observer_objects = Optional.extract(observers) or []
@@ -968,7 +966,7 b' def update_pull_request('
968 966 try:
969 967 reviewers = validate_default_reviewers(reviewer_objects, default_reviewers_data)
970 968 except ValueError as e:
971 raise JSONRPCError('Reviewers Validation: {}'.format(e))
969 raise JSONRPCError(f'Reviewers Validation: {e}')
972 970 else:
973 971 reviewers = []
974 972
@@ -976,7 +974,7 b' def update_pull_request('
976 974 try:
977 975 observers = validate_default_reviewers(reviewer_objects, default_reviewers_data)
978 976 except ValueError as e:
979 raise JSONRPCError('Observer Validation: {}'.format(e))
977 raise JSONRPCError(f'Observer Validation: {e}')
980 978 else:
981 979 observers = []
982 980
@@ -1023,7 +1021,7 b' def update_pull_request('
1023 1021 request, pr_broadcast_channel, apiuser, msg)
1024 1022
1025 1023 data = {
1026 'msg': 'Updated pull request `{}`'.format(pull_request.pull_request_id),
1024 'msg': f'Updated pull request `{pull_request.pull_request_id}`',
1027 1025 'pull_request': pull_request.get_api_data(),
1028 1026 'updated_commits': commit_changes,
1029 1027 'updated_reviewers': reviewers_changes,
@@ -1084,7 +1082,7 b' def close_pull_request('
1084 1082
1085 1083 if pull_request.is_closed():
1086 1084 raise JSONRPCError(
1087 'pull request `%s` is already closed' % (pullrequestid,))
1085 'pull request `{}` is already closed'.format(pullrequestid))
1088 1086
1089 1087 # only owner or admin or person with write permissions
1090 1088 allowed_to_close = PullRequestModel().check_user_update(
@@ -1092,8 +1090,8 b' def close_pull_request('
1092 1090
1093 1091 if not allowed_to_close:
1094 1092 raise JSONRPCError(
1095 'pull request `%s` close failed, no permission to close.' % (
1096 pullrequestid,))
1093 'pull request `{}` close failed, no permission to close.'.format(
1094 pullrequestid))
1097 1095
1098 1096 # message we're using to close the PR, else it's automatically generated
1099 1097 message = Optional.extract(message)
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -265,7 +263,7 b' def get_repos(request, apiuser, root=Opt'
265 263 parent = RepoGroup.get_by_group_name(root)
266 264 if not parent:
267 265 raise JSONRPCError(
268 'Root repository group `{}` does not exist'.format(root))
266 f'Root repository group `{root}` does not exist')
269 267
270 268 if traverse:
271 269 repos = RepoModel().get_repos_for_root(root=root, traverse=traverse)
@@ -626,7 +624,7 b' def get_repo_fts_tree(request, apiuser, '
626 624 cache_seconds = rhodecode.ConfigGet().get_int('rc_cache.cache_repo.expiration_time')
627 625 cache_on = cache_seconds > 0
628 626
629 cache_namespace_uid = 'repo.{}'.format(repo_id)
627 cache_namespace_uid = f'repo.{repo_id}'
630 628 rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
631 629
632 630 def compute_fts_tree(cache_ver, repo_id, commit_id, root_path):
@@ -869,17 +867,17 b' def create_repo('
869 867 task_id = get_task_id(task)
870 868 # no commit, it's done in RepoModel, or async via celery
871 869 return {
872 'msg': "Created new repository `%s`" % (schema_data['repo_name'],),
870 'msg': "Created new repository `{}`".format(schema_data['repo_name']),
873 871 'success': True, # cannot return the repo data here since fork
874 872 # can be done async
875 873 'task': task_id
876 874 }
877 875 except Exception:
878 876 log.exception(
879 u"Exception while trying to create the repository %s",
877 "Exception while trying to create the repository %s",
880 878 schema_data['repo_name'])
881 879 raise JSONRPCError(
882 'failed to create repository `%s`' % (schema_data['repo_name'],))
880 'failed to create repository `{}`'.format(schema_data['repo_name']))
883 881
884 882
885 883 @jsonrpc_method()
@@ -920,13 +918,13 b' def add_field_to_repo(request, apiuser, '
920 918 field_desc=description)
921 919 Session().commit()
922 920 return {
923 'msg': "Added new repository field `%s`" % (key,),
921 'msg': "Added new repository field `{}`".format(key),
924 922 'success': True,
925 923 }
926 924 except Exception:
927 925 log.exception("Exception occurred while trying to add field to repo")
928 926 raise JSONRPCError(
929 'failed to create new field for repository `%s`' % (repoid,))
927 'failed to create new field for repository `{}`'.format(repoid))
930 928
931 929
932 930 @jsonrpc_method()
@@ -959,14 +957,14 b' def remove_field_from_repo(request, apiu'
959 957 RepoModel().delete_repo_field(repo, field_key=key)
960 958 Session().commit()
961 959 return {
962 'msg': "Deleted repository field `%s`" % (key,),
960 'msg': "Deleted repository field `{}`".format(key),
963 961 'success': True,
964 962 }
965 963 except Exception:
966 964 log.exception(
967 965 "Exception occurred while trying to delete field from repo")
968 966 raise JSONRPCError(
969 'failed to delete field for repository `%s`' % (repoid,))
967 'failed to delete field for repository `{}`'.format(repoid))
970 968
971 969
972 970 @jsonrpc_method()
@@ -979,7 +977,7 b' def update_repo('
979 977 enable_statistics=Optional(False),
980 978 enable_locking=Optional(False),
981 979 enable_downloads=Optional(False), fields=Optional('')):
982 """
980 r"""
983 981 Updates a repository with the given information.
984 982
985 983 This command can only be run using an |authtoken| with at least
@@ -1132,12 +1130,12 b' def update_repo('
1132 1130 user=apiuser, repo=repo)
1133 1131 Session().commit()
1134 1132 return {
1135 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo.repo_name),
1133 'msg': 'updated repo ID:{} {}'.format(repo.repo_id, repo.repo_name),
1136 1134 'repository': repo.get_api_data(include_secrets=include_secrets)
1137 1135 }
1138 1136 except Exception:
1139 1137 log.exception(
1140 u"Exception while trying to update the repository %s",
1138 "Exception while trying to update the repository %s",
1141 1139 repoid)
1142 1140 raise JSONRPCError('failed to update repo `%s`' % repoid)
1143 1141
@@ -1276,7 +1274,7 b' def fork_repo(request, apiuser, repoid, '
1276 1274 task_id = get_task_id(task)
1277 1275
1278 1276 return {
1279 'msg': 'Created fork of `%s` as `%s`' % (
1277 'msg': 'Created fork of `{}` as `{}`'.format(
1280 1278 repo.repo_name, schema_data['repo_name']),
1281 1279 'success': True, # cannot return the repo data here since fork
1282 1280 # can be done async
@@ -1284,10 +1282,10 b' def fork_repo(request, apiuser, repoid, '
1284 1282 }
1285 1283 except Exception:
1286 1284 log.exception(
1287 u"Exception while trying to create fork %s",
1285 "Exception while trying to create fork %s",
1288 1286 schema_data['repo_name'])
1289 1287 raise JSONRPCError(
1290 'failed to fork repository `%s` as `%s`' % (
1288 'failed to fork repository `{}` as `{}`'.format(
1291 1289 repo_name, schema_data['repo_name']))
1292 1290
1293 1291
@@ -1353,13 +1351,13 b' def delete_repo(request, apiuser, repoid'
1353 1351 ScmModel().mark_for_invalidation(repo_name, delete=True)
1354 1352 Session().commit()
1355 1353 return {
1356 'msg': 'Deleted repository `%s`%s' % (repo_name, _forks_msg),
1354 'msg': 'Deleted repository `{}`{}'.format(repo_name, _forks_msg),
1357 1355 'success': True
1358 1356 }
1359 1357 except Exception:
1360 1358 log.exception("Exception occurred while trying to delete repo")
1361 1359 raise JSONRPCError(
1362 'failed to delete repository `%s`' % (repo_name,)
1360 'failed to delete repository `{}`'.format(repo_name)
1363 1361 )
1364 1362
1365 1363
@@ -1414,7 +1412,7 b' def invalidate_cache(request, apiuser, r'
1414 1412 try:
1415 1413 ScmModel().mark_for_invalidation(repo.repo_name, delete=delete)
1416 1414 return {
1417 'msg': 'Cache for repository `%s` was invalidated' % (repoid,),
1415 'msg': 'Cache for repository `{}` was invalidated'.format(repoid),
1418 1416 'repository': repo.repo_name
1419 1417 }
1420 1418 except Exception:
@@ -1696,7 +1694,7 b' def comment_commit('
1696 1694
1697 1695 return {
1698 1696 'msg': (
1699 'Commented on commit `%s` for repository `%s`' % (
1697 'Commented on commit `{}` for repository `{}`'.format(
1700 1698 comment.revision, repo.repo_name)),
1701 1699 'status_change': status,
1702 1700 'success': True,
@@ -1708,7 +1706,7 b' def comment_commit('
1708 1706 except Exception:
1709 1707 log.exception("Exception occurred while trying to comment on commit")
1710 1708 raise JSONRPCError(
1711 'failed to set comment on repository `%s`' % (repo.repo_name,)
1709 'failed to set comment on repository `{}`'.format(repo.repo_name)
1712 1710 )
1713 1711
1714 1712
@@ -1815,14 +1813,14 b' def get_comment(request, apiuser, commen'
1815 1813
1816 1814 comment = ChangesetComment.get(comment_id)
1817 1815 if not comment:
1818 raise JSONRPCError('comment `%s` does not exist' % (comment_id,))
1816 raise JSONRPCError('comment `{}` does not exist'.format(comment_id))
1819 1817
1820 1818 perms = ('repository.read', 'repository.write', 'repository.admin')
1821 1819 has_comment_perm = HasRepoPermissionAnyApi(*perms)\
1822 1820 (user=apiuser, repo_name=comment.repo.repo_name)
1823 1821
1824 1822 if not has_comment_perm:
1825 raise JSONRPCError('comment `%s` does not exist' % (comment_id,))
1823 raise JSONRPCError('comment `{}` does not exist'.format(comment_id))
1826 1824
1827 1825 return comment
1828 1826
@@ -1860,7 +1858,7 b' def edit_comment(request, apiuser, messa'
1860 1858 auth_user = apiuser
1861 1859 comment = ChangesetComment.get(comment_id)
1862 1860 if not comment:
1863 raise JSONRPCError('comment `%s` does not exist' % (comment_id,))
1861 raise JSONRPCError('comment `{}` does not exist'.format(comment_id))
1864 1862
1865 1863 is_super_admin = has_superadmin_permission(apiuser)
1866 1864 is_repo_admin = HasRepoPermissionAnyApi('repository.admin')\
@@ -1891,11 +1889,11 b' def edit_comment(request, apiuser, messa'
1891 1889 Session().commit()
1892 1890 except CommentVersionMismatch:
1893 1891 raise JSONRPCError(
1894 'comment ({}) version ({}) mismatch'.format(comment_id, version)
1892 f'comment ({comment_id}) version ({version}) mismatch'
1895 1893 )
1896 1894 if not comment_history and not message:
1897 1895 raise JSONRPCError(
1898 "comment ({}) can't be changed with empty string".format(comment_id)
1896 f"comment ({comment_id}) can't be changed with empty string"
1899 1897 )
1900 1898
1901 1899 if comment.pull_request:
@@ -1989,7 +1987,7 b' def grant_user_permission(request, apius'
1989 1987 PermissionModel().flush_user_permission_caches(changes)
1990 1988
1991 1989 return {
1992 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % (
1990 'msg': 'Granted perm: `{}` for user: `{}` in repo: `{}`'.format(
1993 1991 perm.permission_name, user.username, repo.repo_name
1994 1992 ),
1995 1993 'success': True
@@ -1997,7 +1995,7 b' def grant_user_permission(request, apius'
1997 1995 except Exception:
1998 1996 log.exception("Exception occurred while trying edit permissions for repo")
1999 1997 raise JSONRPCError(
2000 'failed to edit permission for user: `%s` in repo: `%s`' % (
1998 'failed to edit permission for user: `{}` in repo: `{}`'.format(
2001 1999 userid, repoid
2002 2000 )
2003 2001 )
@@ -2052,7 +2050,7 b' def revoke_user_permission(request, apiu'
2052 2050 PermissionModel().flush_user_permission_caches(changes)
2053 2051
2054 2052 return {
2055 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % (
2053 'msg': 'Revoked perm for user: `{}` in repo: `{}`'.format(
2056 2054 user.username, repo.repo_name
2057 2055 ),
2058 2056 'success': True
@@ -2060,7 +2058,7 b' def revoke_user_permission(request, apiu'
2060 2058 except Exception:
2061 2059 log.exception("Exception occurred while trying revoke permissions to repo")
2062 2060 raise JSONRPCError(
2063 'failed to edit permission for user: `%s` in repo: `%s`' % (
2061 'failed to edit permission for user: `{}` in repo: `{}`'.format(
2064 2062 userid, repoid
2065 2063 )
2066 2064 )
@@ -2122,7 +2120,7 b' def grant_user_group_permission(request,'
2122 2120 if not HasUserGroupPermissionAnyApi(*_perms)(
2123 2121 user=apiuser, user_group_name=user_group.users_group_name):
2124 2122 raise JSONRPCError(
2125 'user group `%s` does not exist' % (usergroupid,))
2123 'user group `{}` does not exist'.format(usergroupid))
2126 2124
2127 2125 perm_additions = [[user_group.users_group_id, perm.permission_name, "user_group"]]
2128 2126 try:
@@ -2196,7 +2194,7 b' def revoke_user_group_permission(request'
2196 2194 if not HasUserGroupPermissionAnyApi(*_perms)(
2197 2195 user=apiuser, user_group_name=user_group.users_group_name):
2198 2196 raise JSONRPCError(
2199 'user group `%s` does not exist' % (usergroupid,))
2197 'user group `{}` does not exist'.format(usergroupid))
2200 2198
2201 2199 perm_deletions = [[user_group.users_group_id, None, "user_group"]]
2202 2200 try:
@@ -2213,7 +2211,7 b' def revoke_user_group_permission(request'
2213 2211 PermissionModel().flush_user_permission_caches(changes)
2214 2212
2215 2213 return {
2216 'msg': 'Revoked perm for user group: `%s` in repo: `%s`' % (
2214 'msg': 'Revoked perm for user group: `{}` in repo: `{}`'.format(
2217 2215 user_group.users_group_name, repo.repo_name
2218 2216 ),
2219 2217 'success': True
@@ -2282,7 +2280,7 b' def pull(request, apiuser, repoid, remot'
2282 2280 ScmModel().pull_changes(
2283 2281 repo.repo_name, apiuser.username, remote_uri=remote_uri)
2284 2282 return {
2285 'msg': 'Pulled from url `%s` on repo `%s`' % (
2283 'msg': 'Pulled from url `{}` on repo `{}`'.format(
2286 2284 remote_uri_display, repo.repo_name),
2287 2285 'repository': repo.repo_name
2288 2286 }
@@ -2351,14 +2349,14 b' def strip(request, apiuser, repoid, revi'
2351 2349 user=apiuser, commit=True)
2352 2350
2353 2351 return {
2354 'msg': 'Stripped commit %s from repo `%s`' % (
2352 'msg': 'Stripped commit {} from repo `{}`'.format(
2355 2353 revision, repo.repo_name),
2356 2354 'repository': repo.repo_name
2357 2355 }
2358 2356 except Exception:
2359 2357 log.exception("Exception while trying to strip")
2360 2358 raise JSONRPCError(
2361 'Unable to strip commit %s from repo `%s`' % (
2359 'Unable to strip commit {} from repo `{}`'.format(
2362 2360 revision, repo.repo_name)
2363 2361 )
2364 2362
@@ -2413,7 +2411,7 b' def get_repo_settings(request, apiuser, '
2413 2411 if key is not None:
2414 2412 settings = settings.get(key, None)
2415 2413 except Exception:
2416 msg = 'Failed to fetch settings for repository `{}`'.format(repoid)
2414 msg = f'Failed to fetch settings for repository `{repoid}`'
2417 2415 log.exception(msg)
2418 2416 raise JSONRPCError(msg)
2419 2417
@@ -2466,7 +2464,7 b' def set_repo_settings(request, apiuser, '
2466 2464 new_settings, inherit_global_settings=inherit_global_settings)
2467 2465 Session().commit()
2468 2466 except Exception:
2469 msg = 'Failed to update settings for repository `{}`'.format(repoid)
2467 msg = f'Failed to update settings for repository `{repoid}`'
2470 2468 log.exception(msg)
2471 2469 raise JSONRPCError(msg)
2472 2470
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -98,7 +96,7 b' def get_repo_group(request, apiuser, rep'
98 96 if not HasRepoGroupPermissionAnyApi(*_perms)(
99 97 user=apiuser, group_name=repo_group.group_name):
100 98 raise JSONRPCError(
101 'repository group `%s` does not exist' % (repogroupid,))
99 'repository group `{}` does not exist'.format(repogroupid))
102 100
103 101 permissions = []
104 102 for _user in repo_group.permissions():
@@ -242,7 +240,7 b' def create_repo_group('
242 240 except Exception:
243 241 log.exception("Exception occurred while trying create repo group")
244 242 raise JSONRPCError(
245 'failed to create repo group `%s`' % (validated_group_name,))
243 'failed to create repo group `{}`'.format(validated_group_name))
246 244
247 245
248 246 @jsonrpc_method()
@@ -331,13 +329,13 b' def update_repo_group('
331 329
332 330 Session().commit()
333 331 return {
334 'msg': 'updated repository group ID:%s %s' % (
332 'msg': 'updated repository group ID:{} {}'.format(
335 333 repo_group.group_id, repo_group.group_name),
336 334 'repo_group': repo_group.get_api_data()
337 335 }
338 336 except Exception:
339 337 log.exception(
340 u"Exception occurred while trying update repo group %s",
338 "Exception occurred while trying update repo group %s",
341 339 repogroupid)
342 340 raise JSONRPCError('failed to update repository group `%s`'
343 341 % (repogroupid,))
@@ -629,7 +627,7 b' def grant_user_group_permission_to_repo_'
629 627 if not HasUserGroupPermissionAnyApi(*_perms)(
630 628 user=apiuser, user_group_name=user_group.users_group_name):
631 629 raise JSONRPCError(
632 'user group `%s` does not exist' % (usergroupid,))
630 'user group `{}` does not exist'.format(usergroupid))
633 631
634 632 apply_to_children = Optional.extract(apply_to_children)
635 633
@@ -722,7 +720,7 b' def revoke_user_group_permission_from_re'
722 720 if not HasUserGroupPermissionAnyApi(*_perms)(
723 721 user=apiuser, user_group_name=user_group.users_group_name):
724 722 raise JSONRPCError(
725 'user group `%s` does not exist' % (usergroupid,))
723 'user group `{}` does not exist'.format(usergroupid))
726 724
727 725 apply_to_children = Optional.extract(apply_to_children)
728 726
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -109,7 +107,7 b' def search(request, apiuser, search_quer'
109 107 searcher.cleanup()
110 108
111 109 if not search_result['error']:
112 data['execution_time'] = '%s results (%.4f seconds)' % (
110 data['execution_time'] = '{} results ({:.4f} seconds)'.format(
113 111 search_result['count'],
114 112 search_result['runtime'])
115 113 else:
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -232,10 +230,10 b' def create_user(request, apiuser, userna'
232 230 raise JSONRPCForbidden()
233 231
234 232 if UserModel().get_by_username(username):
235 raise JSONRPCError("user `%s` already exist" % (username,))
233 raise JSONRPCError("user `{}` already exist".format(username))
236 234
237 235 if UserModel().get_by_email(email, case_insensitive=True):
238 raise JSONRPCError("email `%s` already exist" % (email,))
236 raise JSONRPCError("email `{}` already exist".format(email))
239 237
240 238 # generate random password if we actually given the
241 239 # extern_name and it's not rhodecode
@@ -305,7 +303,7 b' def create_user(request, apiuser, userna'
305 303 }
306 304 except Exception:
307 305 log.exception('Error occurred during creation of user')
308 raise JSONRPCError('failed to create user `%s`' % (username,))
306 raise JSONRPCError('failed to create user `{}`'.format(username))
309 307
310 308
311 309 @jsonrpc_method()
@@ -398,7 +396,7 b' def update_user(request, apiuser, userid'
398 396 user=apiuser)
399 397 Session().commit()
400 398 return {
401 'msg': 'updated user ID:%s %s' % (user.user_id, user.username),
399 'msg': 'updated user ID:{} {}'.format(user.user_id, user.username),
402 400 'user': user.get_api_data(include_secrets=True)
403 401 }
404 402 except DefaultUserException:
@@ -406,7 +404,7 b' def update_user(request, apiuser, userid'
406 404 raise JSONRPCError('editing default user is forbidden')
407 405 except Exception:
408 406 log.exception("Error occurred during update of user")
409 raise JSONRPCError('failed to update user `%s`' % (userid,))
407 raise JSONRPCError('failed to update user `{}`'.format(userid))
410 408
411 409
412 410 @jsonrpc_method()
@@ -467,13 +465,13 b' def delete_user(request, apiuser, userid'
467 465
468 466 Session().commit()
469 467 return {
470 'msg': 'deleted user ID:%s %s' % (user.user_id, user.username),
468 'msg': 'deleted user ID:{} {}'.format(user.user_id, user.username),
471 469 'user': None
472 470 }
473 471 except Exception:
474 472 log.exception("Error occurred during deleting of user")
475 473 raise JSONRPCError(
476 'failed to delete user ID:%s %s' % (user.user_id, user.username))
474 'failed to delete user ID:{} {}'.format(user.user_id, user.username))
477 475
478 476
479 477 @jsonrpc_method()
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2011-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
@@ -103,8 +101,8 b' def get_user_group(request, apiuser, use'
103 101 _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',)
104 102 if not HasUserGroupPermissionAnyApi(*_perms)(
105 103 user=apiuser, user_group_name=user_group.users_group_name):
106 raise JSONRPCError('user group `%s` does not exist' % (
107 usergroupid,))
104 raise JSONRPCError('user group `{}` does not exist'.format(
105 usergroupid))
108 106
109 107 permissions = []
110 108 for _user in user_group.permissions():
@@ -226,7 +224,7 b' def create_user_group('
226 224 raise JSONRPCForbidden()
227 225
228 226 if UserGroupModel().get_by_name(group_name):
229 raise JSONRPCError("user group `%s` already exist" % (group_name,))
227 raise JSONRPCError("user group `{}` already exist".format(group_name))
230 228
231 229 if isinstance(owner, Optional):
232 230 owner = apiuser.user_id
@@ -279,7 +277,7 b' def create_user_group('
279 277 }
280 278 except Exception:
281 279 log.exception("Error occurred during creation of user group")
282 raise JSONRPCError('failed to create group `%s`' % (group_name,))
280 raise JSONRPCError('failed to create group `{}`'.format(group_name))
283 281
284 282
285 283 @jsonrpc_method()
@@ -341,7 +339,7 b' def update_user_group(request, apiuser, '
341 339 if not HasUserGroupPermissionAnyApi(*_perms)(
342 340 user=apiuser, user_group_name=user_group.users_group_name):
343 341 raise JSONRPCError(
344 'user group `%s` does not exist' % (usergroupid,))
342 'user group `{}` does not exist'.format(usergroupid))
345 343 else:
346 344 include_secrets = True
347 345
@@ -374,7 +372,7 b' def update_user_group(request, apiuser, '
374 372 user=apiuser)
375 373 Session().commit()
376 374 return {
377 'msg': 'updated user group ID:%s %s' % (
375 'msg': 'updated user group ID:{} {}'.format(
378 376 user_group.users_group_id, user_group.users_group_name),
379 377 'user_group': user_group.get_api_data(
380 378 include_secrets=include_secrets)
@@ -382,7 +380,7 b' def update_user_group(request, apiuser, '
382 380 except Exception:
383 381 log.exception("Error occurred during update of user group")
384 382 raise JSONRPCError(
385 'failed to update user group `%s`' % (usergroupid,))
383 'failed to update user group `{}`'.format(usergroupid))
386 384
387 385
388 386 @jsonrpc_method()
@@ -431,7 +429,7 b' def delete_user_group(request, apiuser, '
431 429 if not HasUserGroupPermissionAnyApi(*_perms)(
432 430 user=apiuser, user_group_name=user_group.users_group_name):
433 431 raise JSONRPCError(
434 'user group `%s` does not exist' % (usergroupid,))
432 'user group `{}` does not exist'.format(usergroupid))
435 433
436 434 old_data = user_group.get_api_data()
437 435 try:
@@ -441,7 +439,7 b' def delete_user_group(request, apiuser, '
441 439 user=apiuser)
442 440 Session().commit()
443 441 return {
444 'msg': 'deleted user group ID:%s %s' % (
442 'msg': 'deleted user group ID:{} {}'.format(
445 443 user_group.users_group_id, user_group.users_group_name),
446 444 'user_group': None
447 445 }
@@ -506,14 +504,14 b' def add_user_to_user_group(request, apiu'
506 504 _perms = ('usergroup.admin',)
507 505 if not HasUserGroupPermissionAnyApi(*_perms)(
508 506 user=apiuser, user_group_name=user_group.users_group_name):
509 raise JSONRPCError('user group `%s` does not exist' % (
510 usergroupid,))
507 raise JSONRPCError('user group `{}` does not exist'.format(
508 usergroupid))
511 509
512 510 old_values = user_group.get_api_data()
513 511 try:
514 512 ugm = UserGroupModel().add_user_to_group(user_group, user)
515 513 success = True if ugm is not True else False
516 msg = 'added member `%s` to user group `%s`' % (
514 msg = 'added member `{}` to user group `{}`'.format(
517 515 user.username, user_group.users_group_name
518 516 )
519 517 msg = msg if success else 'User is already in that group'
@@ -533,7 +531,7 b' def add_user_to_user_group(request, apiu'
533 531 except Exception:
534 532 log.exception("Error occurred during adding a member to user group")
535 533 raise JSONRPCError(
536 'failed to add member to user group `%s`' % (
534 'failed to add member to user group `{}`'.format(
537 535 user_group.users_group_name,
538 536 )
539 537 )
@@ -579,12 +577,12 b' def remove_user_from_user_group(request,'
579 577 if not HasUserGroupPermissionAnyApi(*_perms)(
580 578 user=apiuser, user_group_name=user_group.users_group_name):
581 579 raise JSONRPCError(
582 'user group `%s` does not exist' % (usergroupid,))
580 'user group `{}` does not exist'.format(usergroupid))
583 581
584 582 old_values = user_group.get_api_data()
585 583 try:
586 584 success = UserGroupModel().remove_user_from_group(user_group, user)
587 msg = 'removed member `%s` from user group `%s`' % (
585 msg = 'removed member `{}` from user group `{}`'.format(
588 586 user.username, user_group.users_group_name
589 587 )
590 588 msg = msg if success else "User wasn't in group"
@@ -600,7 +598,7 b' def remove_user_from_user_group(request,'
600 598 except Exception:
601 599 log.exception("Error occurred during removing an member from user group")
602 600 raise JSONRPCError(
603 'failed to remove member from user group `%s`' % (
601 'failed to remove member from user group `{}`'.format(
604 602 user_group.users_group_name,
605 603 )
606 604 )
@@ -641,7 +639,7 b' def grant_user_permission_to_user_group('
641 639 if not HasUserGroupPermissionAnyApi(*_perms)(
642 640 user=apiuser, user_group_name=user_group.users_group_name):
643 641 raise JSONRPCError(
644 'user group `%s` does not exist' % (usergroupid,))
642 'user group `{}` does not exist'.format(usergroupid))
645 643
646 644 user = get_user_or_error(userid)
647 645 perm = get_perm_or_error(perm, prefix='usergroup.')
@@ -663,7 +661,7 b' def grant_user_permission_to_user_group('
663 661
664 662 return {
665 663 'msg':
666 'Granted perm: `%s` for user: `%s` in user group: `%s`' % (
664 'Granted perm: `{}` for user: `{}` in user group: `{}`'.format(
667 665 perm.permission_name, user.username,
668 666 user_group.users_group_name
669 667 ),
@@ -713,7 +711,7 b' def revoke_user_permission_from_user_gro'
713 711 if not HasUserGroupPermissionAnyApi(*_perms)(
714 712 user=apiuser, user_group_name=user_group.users_group_name):
715 713 raise JSONRPCError(
716 'user group `%s` does not exist' % (usergroupid,))
714 'user group `{}` does not exist'.format(usergroupid))
717 715
718 716 user = get_user_or_error(userid)
719 717
@@ -732,7 +730,7 b' def revoke_user_permission_from_user_gro'
732 730 PermissionModel().flush_user_permission_caches(changes)
733 731
734 732 return {
735 'msg': 'Revoked perm for user: `%s` in user group: `%s`' % (
733 'msg': 'Revoked perm for user: `{}` in user group: `{}`'.format(
736 734 user.username, user_group.users_group_name
737 735 ),
738 736 'success': True
@@ -784,14 +782,14 b' def grant_user_group_permission_to_user_'
784 782 user=apiuser,
785 783 user_group_name=target_user_group.users_group_name):
786 784 raise JSONRPCError(
787 'to user group `%s` does not exist' % (usergroupid,))
785 'to user group `{}` does not exist'.format(usergroupid))
788 786
789 787 # check if we have at least read permission for source user group !
790 788 _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',)
791 789 if not HasUserGroupPermissionAnyApi(*_perms)(
792 790 user=apiuser, user_group_name=user_group.users_group_name):
793 791 raise JSONRPCError(
794 'user group `%s` does not exist' % (sourceusergroupid,))
792 'user group `{}` does not exist'.format(sourceusergroupid))
795 793
796 794 try:
797 795 changes = UserGroupModel().grant_user_group_permission(
@@ -864,7 +862,7 b' def revoke_user_group_permission_from_us'
864 862 user=apiuser,
865 863 user_group_name=target_user_group.users_group_name):
866 864 raise JSONRPCError(
867 'to user group `%s` does not exist' % (usergroupid,))
865 'to user group `{}` does not exist'.format(usergroupid))
868 866
869 867 # check if we have at least read permission
870 868 # for the source user group !
@@ -872,7 +870,7 b' def revoke_user_group_permission_from_us'
872 870 if not HasUserGroupPermissionAnyApi(*_perms)(
873 871 user=apiuser, user_group_name=user_group.users_group_name):
874 872 raise JSONRPCError(
875 'user group `%s` does not exist' % (sourceusergroupid,))
873 'user group `{}` does not exist'.format(sourceusergroupid))
876 874
877 875 try:
878 876 changes = UserGroupModel().revoke_user_group_permission(
@@ -187,7 +187,7 b' class GeventCurlMulti(object):'
187 187 for curl in ok_list:
188 188 curl.waiter.switch(None)
189 189 for curl, errnum, errmsg in err_list:
190 curl.waiter.throw(Exception('%s %s' % (errnum, errmsg)))
190 curl.waiter.throw(Exception('{} {}'.format(errnum, errmsg)))
191 191 if num_q == 0:
192 192 break
193 193
@@ -1,5 +1,3 b''
1
2
3 1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 2 #
5 3 # This program is free software: you can redistribute it and/or modify
General Comments 0
You need to be logged in to leave comments. Login now