Show More
@@ -29,7 +29,7 b' from rhodecode.lib import audit_logger' | |||
|
29 | 29 | from rhodecode.lib.auth import ( |
|
30 | 30 | LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired, |
|
31 | 31 | HasRepoPermissionAny) |
|
32 | from rhodecode.lib.exceptions import AttachedForksError | |
|
32 | from rhodecode.lib.exceptions import AttachedForksError, AttachedPullRequestsError | |
|
33 | 33 | from rhodecode.lib.utils2 import safe_int |
|
34 | 34 | from rhodecode.lib.vcs import RepositoryError |
|
35 | 35 | from rhodecode.model.db import Session, UserFollowing, User, Repository |
@@ -80,22 +80,23 b' class RepoSettingsView(RepoAppView):' | |||
|
80 | 80 | """ |
|
81 | 81 | _ = self.request.translate |
|
82 | 82 | handle_forks = self.request.POST.get('forks', None) |
|
83 | if handle_forks == 'detach_forks': | |
|
84 | handle_forks = 'detach' | |
|
85 | elif handle_forks == 'delete_forks': | |
|
86 | handle_forks = 'delete' | |
|
83 | 87 | |
|
84 | 88 | try: |
|
89 | old_data = self.db_repo.get_api_data() | |
|
90 | RepoModel().delete(self.db_repo, forks=handle_forks) | |
|
91 | ||
|
85 | 92 | _forks = self.db_repo.forks.count() |
|
86 | 93 | if _forks and handle_forks: |
|
87 | 94 | if handle_forks == 'detach_forks': |
|
88 | handle_forks = 'detach' | |
|
89 | 95 | h.flash(_('Detached %s forks') % _forks, category='success') |
|
90 | 96 | elif handle_forks == 'delete_forks': |
|
91 | handle_forks = 'delete' | |
|
92 | 97 | h.flash(_('Deleted %s forks') % _forks, category='success') |
|
93 | 98 | |
|
94 | old_data = self.db_repo.get_api_data() | |
|
95 | RepoModel().delete(self.db_repo, forks=handle_forks) | |
|
96 | ||
|
97 | repo = audit_logger.RepoWrap(repo_id=None, | |
|
98 | repo_name=self.db_repo.repo_name) | |
|
99 | repo = audit_logger.RepoWrap(repo_id=None, repo_name=self.db_repo.repo_name) | |
|
99 | 100 | audit_logger.store_web( |
|
100 | 101 | 'repo.delete', action_data={'old_data': old_data}, |
|
101 | 102 | user=self._rhodecode_user, repo=repo) |
@@ -118,6 +119,20 b' class RepoSettingsView(RepoAppView):' | |||
|
118 | 119 | # redirect to advanced for forks handle action ? |
|
119 | 120 | raise HTTPFound(repo_advanced_url) |
|
120 | 121 | |
|
122 | except AttachedPullRequestsError: | |
|
123 | repo_advanced_url = h.route_path( | |
|
124 | 'edit_repo_advanced', repo_name=self.db_repo_name, | |
|
125 | _anchor='advanced-delete') | |
|
126 | attached_prs = len(self.db_repo.pull_requests_source + | |
|
127 | self.db_repo.pull_requests_target) | |
|
128 | h.flash( | |
|
129 | _('Cannot delete `{repo}` it still contains {num} attached pull requests. ' | |
|
130 | 'Consider archiving the repository instead.').format( | |
|
131 | repo=self.db_repo_name, num=attached_prs), category='warning') | |
|
132 | ||
|
133 | # redirect to advanced for forks handle action ? | |
|
134 | raise HTTPFound(repo_advanced_url) | |
|
135 | ||
|
121 | 136 | except Exception: |
|
122 | 137 | log.exception("Exception during deletion of repository") |
|
123 | 138 | h.flash(_('An error occurred during deletion of `%s`') |
@@ -70,6 +70,10 b' class AttachedForksError(Exception):' | |||
|
70 | 70 | pass |
|
71 | 71 | |
|
72 | 72 | |
|
73 | class AttachedPullRequestsError(Exception): | |
|
74 | pass | |
|
75 | ||
|
76 | ||
|
73 | 77 | class RepoGroupAssignmentError(Exception): |
|
74 | 78 | pass |
|
75 | 79 |
@@ -32,7 +32,7 b' from zope.cachedescriptors.property impo' | |||
|
32 | 32 | from rhodecode import events |
|
33 | 33 | from rhodecode.lib.auth import HasUserGroupPermissionAny |
|
34 | 34 | from rhodecode.lib.caching_query import FromCache |
|
35 | from rhodecode.lib.exceptions import AttachedForksError | |
|
35 | from rhodecode.lib.exceptions import AttachedForksError, AttachedPullRequestsError | |
|
36 | 36 | from rhodecode.lib.hooks_base import log_delete_repository |
|
37 | 37 | from rhodecode.lib.user_log_filter import user_log_filter |
|
38 | 38 | from rhodecode.lib.utils import make_db_config |
@@ -608,7 +608,7 b' class RepoModel(BaseModel):' | |||
|
608 | 608 | from rhodecode.lib.celerylib import tasks, run_task |
|
609 | 609 | return run_task(tasks.create_repo_fork, form_data, cur_user) |
|
610 | 610 | |
|
611 | def delete(self, repo, forks=None, fs_remove=True, cur_user=None): | |
|
611 | def delete(self, repo, forks=None, pull_requests=None, fs_remove=True, cur_user=None): | |
|
612 | 612 | """ |
|
613 | 613 | Delete given repository, forks parameter defines what do do with |
|
614 | 614 | attached forks. Throws AttachedForksError if deleted repo has attached |
@@ -632,6 +632,12 b' class RepoModel(BaseModel):' | |||
|
632 | 632 | elif [f for f in repo.forks]: |
|
633 | 633 | raise AttachedForksError() |
|
634 | 634 | |
|
635 | # check for pull requests | |
|
636 | pr_sources = repo.pull_requests_source | |
|
637 | pr_targets = repo.pull_requests_target | |
|
638 | if pull_requests != 'delete' and (pr_sources or pr_targets): | |
|
639 | raise AttachedPullRequestsError() | |
|
640 | ||
|
635 | 641 | old_repo_dict = repo.get_dict() |
|
636 | 642 | events.trigger(events.RepoPreDeleteEvent(repo)) |
|
637 | 643 | try: |
@@ -7,6 +7,8 b'' | |||
|
7 | 7 | (_('Updated on'), h.format_date(c.rhodecode_db_repo.updated_on), '', ''), |
|
8 | 8 | (_('Cached Commit id'), lambda: h.link_to(c.rhodecode_db_repo.changeset_cache.get('short_id'), h.route_path('repo_commit',repo_name=c.repo_name,commit_id=c.rhodecode_db_repo.changeset_cache.get('raw_id'))), '', ''), |
|
9 | 9 | (_('Attached scoped tokens'), len(c.rhodecode_db_repo.scoped_tokens), '', [x.user for x in c.rhodecode_db_repo.scoped_tokens]), |
|
10 | (_('Pull requests source'), len(c.rhodecode_db_repo.pull_requests_source), '', ['pr_id:{}, repo:{}'.format(x.pull_request_id,x.source_repo.repo_name) for x in c.rhodecode_db_repo.pull_requests_source]), | |
|
11 | (_('Pull requests target'), len(c.rhodecode_db_repo.pull_requests_target), '', ['pr_id:{}, repo:{}'.format(x.pull_request_id,x.target_repo.repo_name) for x in c.rhodecode_db_repo.pull_requests_target]), | |
|
10 | 12 | ] |
|
11 | 13 | %> |
|
12 | 14 | |
@@ -131,6 +133,18 b'' | |||
|
131 | 133 | %endif |
|
132 | 134 | </td> |
|
133 | 135 | </tr> |
|
136 | <% attached_prs = len(c.rhodecode_db_repo.pull_requests_source + c.rhodecode_db_repo.pull_requests_target) %> | |
|
137 | % if c.rhodecode_db_repo.pull_requests_source or c.rhodecode_db_repo.pull_requests_target: | |
|
138 | <tr> | |
|
139 | <td> | |
|
140 | ${_ungettext('This repository has %s attached pull request.', 'This repository has %s attached pull requests.', attached_prs) % attached_prs} | |
|
141 | <br/> | |
|
142 | ${_('Consider to archive this repository instead.')} | |
|
143 | </td> | |
|
144 | <td></td> | |
|
145 | <td></td> | |
|
146 | </tr> | |
|
147 | % endif | |
|
134 | 148 | </table> |
|
135 | 149 | <div style="margin: 0 0 20px 0" class="fake-space"></div> |
|
136 | 150 |
@@ -226,7 +226,7 b' class Fixture(object):' | |||
|
226 | 226 | return r |
|
227 | 227 | |
|
228 | 228 | def destroy_repo(self, repo_name, **kwargs): |
|
229 | RepoModel().delete(repo_name, **kwargs) | |
|
229 | RepoModel().delete(repo_name, pull_requests='delete', **kwargs) | |
|
230 | 230 | Session().commit() |
|
231 | 231 | |
|
232 | 232 | def destroy_repo_on_filesystem(self, repo_name): |
General Comments 0
You need to be logged in to leave comments.
Login now