Show More
@@ -30,43 +30,45 b' from rhodecode.api.tests.utils import (' | |||||
30 | class TestApiDeleteRepo(object): |
|
30 | class TestApiDeleteRepo(object): | |
31 | def test_api_delete_repo(self, backend): |
|
31 | def test_api_delete_repo(self, backend): | |
32 | repo = backend.create_repo() |
|
32 | repo = backend.create_repo() | |
33 |
|
33 | repo_name = repo.repo_name | ||
34 | id_, params = build_data( |
|
34 | id_, params = build_data( | |
35 | self.apikey, 'delete_repo', repoid=repo.repo_name, ) |
|
35 | self.apikey, 'delete_repo', repoid=repo.repo_name, ) | |
36 | response = api_call(self.app, params) |
|
36 | response = api_call(self.app, params) | |
37 |
|
37 | |||
38 | expected = { |
|
38 | expected = { | |
39 |
'msg': 'Deleted repository `%s`' % ( |
|
39 | 'msg': 'Deleted repository `%s`' % (repo_name,), | |
40 | 'success': True |
|
40 | 'success': True | |
41 | } |
|
41 | } | |
42 | assert_ok(id_, expected, given=response.body) |
|
42 | assert_ok(id_, expected, given=response.body) | |
43 |
|
43 | |||
44 | def test_api_delete_repo_by_non_admin(self, backend, user_regular): |
|
44 | def test_api_delete_repo_by_non_admin(self, backend, user_regular): | |
45 | repo = backend.create_repo(cur_user=user_regular.username) |
|
45 | repo = backend.create_repo(cur_user=user_regular.username) | |
|
46 | repo_name = repo.repo_name | |||
46 | id_, params = build_data( |
|
47 | id_, params = build_data( | |
47 | user_regular.api_key, 'delete_repo', repoid=repo.repo_name, ) |
|
48 | user_regular.api_key, 'delete_repo', repoid=repo.repo_name, ) | |
48 | response = api_call(self.app, params) |
|
49 | response = api_call(self.app, params) | |
49 |
|
50 | |||
50 | expected = { |
|
51 | expected = { | |
51 |
'msg': 'Deleted repository `%s`' % ( |
|
52 | 'msg': 'Deleted repository `%s`' % (repo_name,), | |
52 | 'success': True |
|
53 | 'success': True | |
53 | } |
|
54 | } | |
54 | assert_ok(id_, expected, given=response.body) |
|
55 | assert_ok(id_, expected, given=response.body) | |
55 |
|
56 | |||
56 | def test_api_delete_repo_by_non_admin_no_permission(self, backend): |
|
57 | def test_api_delete_repo_by_non_admin_no_permission(self, backend): | |
57 | repo = backend.create_repo() |
|
58 | repo = backend.create_repo() | |
|
59 | repo_name = repo.repo_name | |||
58 | id_, params = build_data( |
|
60 | id_, params = build_data( | |
59 | self.apikey_regular, 'delete_repo', repoid=repo.repo_name, ) |
|
61 | self.apikey_regular, 'delete_repo', repoid=repo.repo_name, ) | |
60 | response = api_call(self.app, params) |
|
62 | response = api_call(self.app, params) | |
61 |
expected = 'repository `%s` does not exist' % ( |
|
63 | expected = 'repository `%s` does not exist' % (repo_name) | |
62 | assert_error(id_, expected, given=response.body) |
|
64 | assert_error(id_, expected, given=response.body) | |
63 |
|
65 | |||
64 | def test_api_delete_repo_exception_occurred(self, backend): |
|
66 | def test_api_delete_repo_exception_occurred(self, backend): | |
65 | repo = backend.create_repo() |
|
67 | repo = backend.create_repo() | |
|
68 | repo_name = repo.repo_name | |||
66 | id_, params = build_data( |
|
69 | id_, params = build_data( | |
67 | self.apikey, 'delete_repo', repoid=repo.repo_name, ) |
|
70 | self.apikey, 'delete_repo', repoid=repo.repo_name, ) | |
68 | with mock.patch.object(RepoModel, 'delete', crash): |
|
71 | with mock.patch.object(RepoModel, 'delete', crash): | |
69 | response = api_call(self.app, params) |
|
72 | response = api_call(self.app, params) | |
70 | expected = 'failed to delete repository `%s`' % ( |
|
73 | expected = 'failed to delete repository `%s`' % (repo_name,) | |
71 | repo.repo_name,) |
|
|||
72 | assert_error(id_, expected, given=response.body) |
|
74 | assert_error(id_, expected, given=response.body) |
@@ -29,6 +29,7 b' from rhodecode.api.utils import (' | |||||
29 | get_user_group_or_error, get_user_or_error, validate_repo_permissions, |
|
29 | get_user_group_or_error, get_user_or_error, validate_repo_permissions, | |
30 | get_perm_or_error, parse_args, get_origin, build_commit_data, |
|
30 | get_perm_or_error, parse_args, get_origin, build_commit_data, | |
31 | validate_set_owner_permissions) |
|
31 | validate_set_owner_permissions) | |
|
32 | from rhodecode.lib import audit_logger | |||
32 | from rhodecode.lib import repo_maintenance |
|
33 | from rhodecode.lib import repo_maintenance | |
33 | from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi |
|
34 | from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi | |
34 | from rhodecode.lib.utils2 import str2bool, time_to_datetime |
|
35 | from rhodecode.lib.utils2 import str2bool, time_to_datetime | |
@@ -1154,6 +1155,7 b' def delete_repo(request, apiuser, repoid' | |||||
1154 | """ |
|
1155 | """ | |
1155 |
|
1156 | |||
1156 | repo = get_repo_or_error(repoid) |
|
1157 | repo = get_repo_or_error(repoid) | |
|
1158 | repo_name = repo.repo_name | |||
1157 | if not has_superadmin_permission(apiuser): |
|
1159 | if not has_superadmin_permission(apiuser): | |
1158 | _perms = ('repository.admin',) |
|
1160 | _perms = ('repository.admin',) | |
1159 | validate_repo_permissions(apiuser, repoid, repo, _perms) |
|
1161 | validate_repo_permissions(apiuser, repoid, repo, _perms) | |
@@ -1171,18 +1173,27 b' def delete_repo(request, apiuser, repoid' | |||||
1171 | 'Cannot delete `%s` it still contains attached forks' % |
|
1173 | 'Cannot delete `%s` it still contains attached forks' % | |
1172 | (repo.repo_name,) |
|
1174 | (repo.repo_name,) | |
1173 | ) |
|
1175 | ) | |
|
1176 | repo_data = repo.get_api_data() | |||
|
1177 | RepoModel().delete(repo, forks=forks) | |||
1174 |
|
1178 | |||
1175 | RepoModel().delete(repo, forks=forks) |
|
1179 | repo = audit_logger.RepoWrap(repo_id=None, | |
|
1180 | repo_name=repo.repo_name) | |||
|
1181 | ||||
|
1182 | audit_logger.store( | |||
|
1183 | action='repo.delete', | |||
|
1184 | action_data={'repo_data': repo_data, 'source': 'api_call'}, | |||
|
1185 | user=apiuser, repo=repo, commit=False) | |||
|
1186 | ||||
|
1187 | ScmModel().mark_for_invalidation(repo_name, delete=True) | |||
1176 | Session().commit() |
|
1188 | Session().commit() | |
1177 | return { |
|
1189 | return { | |
1178 | 'msg': 'Deleted repository `%s`%s' % ( |
|
1190 | 'msg': 'Deleted repository `%s`%s' % (repo_name, _forks_msg), | |
1179 | repo.repo_name, _forks_msg), |
|
|||
1180 | 'success': True |
|
1191 | 'success': True | |
1181 | } |
|
1192 | } | |
1182 | except Exception: |
|
1193 | except Exception: | |
1183 | log.exception("Exception occurred while trying to delete repo") |
|
1194 | log.exception("Exception occurred while trying to delete repo") | |
1184 | raise JSONRPCError( |
|
1195 | raise JSONRPCError( | |
1185 |
'failed to delete repository `%s`' % ( |
|
1196 | 'failed to delete repository `%s`' % (repo_name,) | |
1186 | ) |
|
1197 | ) | |
1187 |
|
1198 | |||
1188 |
|
1199 |
@@ -97,13 +97,14 b' class RepoSettingsView(RepoAppView):' | |||||
97 | repo_data = self.db_repo.get_api_data() |
|
97 | repo_data = self.db_repo.get_api_data() | |
98 | RepoModel().delete(self.db_repo, forks=handle_forks) |
|
98 | RepoModel().delete(self.db_repo, forks=handle_forks) | |
99 |
|
99 | |||
100 |
repo = audit_logger.RepoWrap(repo_id= |
|
100 | repo = audit_logger.RepoWrap(repo_id=None, | |
101 | repo_name=self.db_repo.repo_name) |
|
101 | repo_name=self.db_repo.repo_name) | |
102 | audit_logger.store( |
|
102 | audit_logger.store( | |
103 |
action='repo.delete', |
|
103 | action='repo.delete', | |
|
104 | action_data={'repo_data': repo_data, 'source': 'web_action'}, | |||
104 | user=self._rhodecode_user, repo=repo, commit=False) |
|
105 | user=self._rhodecode_user, repo=repo, commit=False) | |
105 |
|
106 | |||
106 | ScmModel().mark_for_invalidation(self.db_repo_name) |
|
107 | ScmModel().mark_for_invalidation(self.db_repo_name, delete=True) | |
107 | h.flash( |
|
108 | h.flash( | |
108 | _('Deleted repository `%s`') % self.db_repo_name, |
|
109 | _('Deleted repository `%s`') % self.db_repo_name, | |
109 | category='success') |
|
110 | category='success') |
@@ -12,7 +12,6 b'' | |||||
12 | ******************************************************************************/ |
|
12 | ******************************************************************************/ | |
13 | function registerRCRoutes() { |
|
13 | function registerRCRoutes() { | |
14 | // routes registration |
|
14 | // routes registration | |
15 | pyroutes.register('home', '/', []); |
|
|||
16 | pyroutes.register('new_repo', '/_admin/create_repository', []); |
|
15 | pyroutes.register('new_repo', '/_admin/create_repository', []); | |
17 | pyroutes.register('edit_user', '/_admin/users/%(user_id)s/edit', ['user_id']); |
|
16 | pyroutes.register('edit_user', '/_admin/users/%(user_id)s/edit', ['user_id']); | |
18 | pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']); |
|
17 | pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']); | |
@@ -92,6 +91,7 b' function registerRCRoutes() {' | |||||
92 | pyroutes.register('register', '/_admin/register', []); |
|
91 | pyroutes.register('register', '/_admin/register', []); | |
93 | pyroutes.register('reset_password', '/_admin/password_reset', []); |
|
92 | pyroutes.register('reset_password', '/_admin/password_reset', []); | |
94 | pyroutes.register('reset_password_confirmation', '/_admin/password_reset_confirmation', []); |
|
93 | pyroutes.register('reset_password_confirmation', '/_admin/password_reset_confirmation', []); | |
|
94 | pyroutes.register('home', '/', []); | |||
95 | pyroutes.register('user_autocomplete_data', '/_users', []); |
|
95 | pyroutes.register('user_autocomplete_data', '/_users', []); | |
96 | pyroutes.register('user_group_autocomplete_data', '/_user_groups', []); |
|
96 | pyroutes.register('user_group_autocomplete_data', '/_user_groups', []); | |
97 | pyroutes.register('repo_list_data', '/_repos', []); |
|
97 | pyroutes.register('repo_list_data', '/_repos', []); |
General Comments 0
You need to be logged in to leave comments.
Login now