##// END OF EJS Templates
repo-settings: fix error on passing in _anchor into wrong call....
marcink -
r2171:01313011 default
parent child Browse files
Show More
@@ -1,223 +1,223 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pyramid.view import view_config
24 24 from pyramid.httpexceptions import HTTPFound
25 25
26 26 from rhodecode.apps._base import RepoAppView
27 27 from rhodecode.lib import helpers as h
28 28 from rhodecode.lib import audit_logger
29 29 from rhodecode.lib.auth import (
30 30 LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
31 31 from rhodecode.lib.exceptions import AttachedForksError
32 32 from rhodecode.lib.utils2 import safe_int
33 33 from rhodecode.lib.vcs import RepositoryError
34 34 from rhodecode.model.db import Session, UserFollowing, User, Repository
35 35 from rhodecode.model.repo import RepoModel
36 36 from rhodecode.model.scm import ScmModel
37 37
38 38 log = logging.getLogger(__name__)
39 39
40 40
41 41 class RepoSettingsView(RepoAppView):
42 42
43 43 def load_default_context(self):
44 44 c = self._get_local_tmpl_context()
45 45
46 46 self._register_global_c(c)
47 47 return c
48 48
49 49 @LoginRequired()
50 50 @HasRepoPermissionAnyDecorator('repository.admin')
51 51 @view_config(
52 52 route_name='edit_repo_advanced', request_method='GET',
53 53 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
54 54 def edit_advanced(self):
55 55 c = self.load_default_context()
56 56 c.active = 'advanced'
57 57
58 58 c.default_user_id = User.get_default_user().user_id
59 59 c.in_public_journal = UserFollowing.query() \
60 60 .filter(UserFollowing.user_id == c.default_user_id) \
61 61 .filter(UserFollowing.follows_repository == self.db_repo).scalar()
62 62
63 63 c.has_origin_repo_read_perm = False
64 64 if self.db_repo.fork:
65 65 c.has_origin_repo_read_perm = h.HasRepoPermissionAny(
66 66 'repository.write', 'repository.read', 'repository.admin')(
67 67 self.db_repo.fork.repo_name, 'repo set as fork page')
68 68
69 69 return self._get_template_context(c)
70 70
71 71 @LoginRequired()
72 72 @HasRepoPermissionAnyDecorator('repository.admin')
73 73 @CSRFRequired()
74 74 @view_config(
75 75 route_name='edit_repo_advanced_delete', request_method='POST',
76 76 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
77 77 def edit_advanced_delete(self):
78 78 """
79 79 Deletes the repository, or shows warnings if deletion is not possible
80 80 because of attached forks or other errors.
81 81 """
82 82 _ = self.request.translate
83 83 handle_forks = self.request.POST.get('forks', None)
84 84
85 85 try:
86 86 _forks = self.db_repo.forks.count()
87 87 if _forks and handle_forks:
88 88 if handle_forks == 'detach_forks':
89 89 handle_forks = 'detach'
90 90 h.flash(_('Detached %s forks') % _forks, category='success')
91 91 elif handle_forks == 'delete_forks':
92 92 handle_forks = 'delete'
93 93 h.flash(_('Deleted %s forks') % _forks, category='success')
94 94
95 95 old_data = self.db_repo.get_api_data()
96 96 RepoModel().delete(self.db_repo, forks=handle_forks)
97 97
98 98 repo = audit_logger.RepoWrap(repo_id=None,
99 99 repo_name=self.db_repo.repo_name)
100 100 audit_logger.store_web(
101 101 'repo.delete', action_data={'old_data': old_data},
102 102 user=self._rhodecode_user, repo=repo)
103 103
104 104 ScmModel().mark_for_invalidation(self.db_repo_name, delete=True)
105 105 h.flash(
106 106 _('Deleted repository `%s`') % self.db_repo_name,
107 107 category='success')
108 108 Session().commit()
109 109 except AttachedForksError:
110 110 repo_advanced_url = h.route_path(
111 111 'edit_repo_advanced', repo_name=self.db_repo_name,
112 112 _anchor='advanced-delete')
113 113 delete_anchor = h.link_to(_('detach or delete'), repo_advanced_url)
114 114 h.flash(_('Cannot delete `{repo}` it still contains attached forks. '
115 115 'Try using {delete_or_detach} option.')
116 116 .format(repo=self.db_repo_name, delete_or_detach=delete_anchor),
117 117 category='warning')
118 118
119 119 # redirect to advanced for forks handle action ?
120 120 raise HTTPFound(repo_advanced_url)
121 121
122 122 except Exception:
123 123 log.exception("Exception during deletion of repository")
124 124 h.flash(_('An error occurred during deletion of `%s`')
125 125 % self.db_repo_name, category='error')
126 126 # redirect to advanced for more deletion options
127 127 raise HTTPFound(
128 h.route_path('edit_repo_advanced', repo_name=self.db_repo_name),
129 _anchor='advanced-delete')
128 h.route_path('edit_repo_advanced', repo_name=self.db_repo_name,
129 _anchor='advanced-delete'))
130 130
131 131 raise HTTPFound(h.route_path('home'))
132 132
133 133 @LoginRequired()
134 134 @HasRepoPermissionAnyDecorator('repository.admin')
135 135 @CSRFRequired()
136 136 @view_config(
137 137 route_name='edit_repo_advanced_journal', request_method='POST',
138 138 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
139 139 def edit_advanced_journal(self):
140 140 """
141 141 Set's this repository to be visible in public journal,
142 142 in other words making default user to follow this repo
143 143 """
144 144 _ = self.request.translate
145 145
146 146 try:
147 147 user_id = User.get_default_user().user_id
148 148 ScmModel().toggle_following_repo(self.db_repo.repo_id, user_id)
149 149 h.flash(_('Updated repository visibility in public journal'),
150 150 category='success')
151 151 Session().commit()
152 152 except Exception:
153 153 h.flash(_('An error occurred during setting this '
154 154 'repository in public journal'),
155 155 category='error')
156 156
157 157 raise HTTPFound(
158 158 h.route_path('edit_repo_advanced', repo_name=self.db_repo_name))
159 159
160 160 @LoginRequired()
161 161 @HasRepoPermissionAnyDecorator('repository.admin')
162 162 @CSRFRequired()
163 163 @view_config(
164 164 route_name='edit_repo_advanced_fork', request_method='POST',
165 165 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
166 166 def edit_advanced_fork(self):
167 167 """
168 168 Mark given repository as a fork of another
169 169 """
170 170 _ = self.request.translate
171 171
172 172 new_fork_id = self.request.POST.get('id_fork_of')
173 173 try:
174 174
175 175 if new_fork_id and not new_fork_id.isdigit():
176 176 log.error('Given fork id %s is not an INT', new_fork_id)
177 177
178 178 fork_id = safe_int(new_fork_id)
179 179 repo = ScmModel().mark_as_fork(
180 180 self.db_repo_name, fork_id, self._rhodecode_user.user_id)
181 181 fork = repo.fork.repo_name if repo.fork else _('Nothing')
182 182 Session().commit()
183 183 h.flash(_('Marked repo %s as fork of %s') % (self.db_repo_name, fork),
184 184 category='success')
185 185 except RepositoryError as e:
186 186 log.exception("Repository Error occurred")
187 187 h.flash(str(e), category='error')
188 188 except Exception as e:
189 189 log.exception("Exception while editing fork")
190 190 h.flash(_('An error occurred during this operation'),
191 191 category='error')
192 192
193 193 raise HTTPFound(
194 194 h.route_path('edit_repo_advanced', repo_name=self.db_repo_name))
195 195
196 196 @LoginRequired()
197 197 @HasRepoPermissionAnyDecorator('repository.admin')
198 198 @CSRFRequired()
199 199 @view_config(
200 200 route_name='edit_repo_advanced_locking', request_method='POST',
201 201 renderer='rhodecode:templates/admin/repos/repo_edit.mako')
202 202 def edit_advanced_locking(self):
203 203 """
204 204 Toggle locking of repository
205 205 """
206 206 _ = self.request.translate
207 207 set_lock = self.request.POST.get('set_lock')
208 208 set_unlock = self.request.POST.get('set_unlock')
209 209
210 210 try:
211 211 if set_lock:
212 212 Repository.lock(self.db_repo, self._rhodecode_user.user_id,
213 213 lock_reason=Repository.LOCK_WEB)
214 214 h.flash(_('Locked repository'), category='success')
215 215 elif set_unlock:
216 216 Repository.unlock(self.db_repo)
217 217 h.flash(_('Unlocked repository'), category='success')
218 218 except Exception as e:
219 219 log.exception("Exception during unlocking")
220 220 h.flash(_('An error occurred during unlocking'), category='error')
221 221
222 222 raise HTTPFound(
223 223 h.route_path('edit_repo_advanced', repo_name=self.db_repo_name))
General Comments 0
You need to be logged in to leave comments. Login now