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