Show More
@@ -1,185 +1,192 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | rhodecode.controllers.forks |
|
4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 | 5 | |
|
6 | 6 | forks controller for rhodecode |
|
7 | 7 | |
|
8 | 8 | :created_on: Apr 23, 2011 |
|
9 | 9 | :author: marcink |
|
10 | 10 | :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
|
11 | 11 | :license: GPLv3, see COPYING for more details. |
|
12 | 12 | """ |
|
13 | 13 | # This program is free software: you can redistribute it and/or modify |
|
14 | 14 | # it under the terms of the GNU General Public License as published by |
|
15 | 15 | # the Free Software Foundation, either version 3 of the License, or |
|
16 | 16 | # (at your option) any later version. |
|
17 | 17 | # |
|
18 | 18 | # This program is distributed in the hope that it will be useful, |
|
19 | 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 | 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 | 21 | # GNU General Public License for more details. |
|
22 | 22 | # |
|
23 | 23 | # You should have received a copy of the GNU General Public License |
|
24 | 24 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25 | 25 | import logging |
|
26 | 26 | import formencode |
|
27 | 27 | import traceback |
|
28 | 28 | from formencode import htmlfill |
|
29 | 29 | |
|
30 | 30 | from pylons import tmpl_context as c, request, url |
|
31 | 31 | from pylons.controllers.util import redirect |
|
32 | 32 | from pylons.i18n.translation import _ |
|
33 | 33 | |
|
34 | 34 | import rhodecode.lib.helpers as h |
|
35 | 35 | |
|
36 | 36 | from rhodecode.lib.helpers import Page |
|
37 | 37 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ |
|
38 | 38 | NotAnonymous, HasRepoPermissionAny, HasPermissionAllDecorator,\ |
|
39 | 39 | HasPermissionAnyDecorator |
|
40 | 40 | from rhodecode.lib.base import BaseRepoController, render |
|
41 | from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User | |
|
41 | from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User,\ | |
|
42 | RhodeCodeUi | |
|
42 | 43 | from rhodecode.model.repo import RepoModel |
|
43 | 44 | from rhodecode.model.forms import RepoForkForm |
|
44 | 45 | from rhodecode.model.scm import ScmModel, GroupList |
|
45 | 46 | from rhodecode.lib.utils2 import safe_int |
|
46 | 47 | |
|
47 | 48 | log = logging.getLogger(__name__) |
|
48 | 49 | |
|
49 | 50 | |
|
50 | 51 | class ForksController(BaseRepoController): |
|
51 | 52 | |
|
52 | 53 | @LoginRequired() |
|
53 | 54 | def __before__(self): |
|
54 | 55 | super(ForksController, self).__before__() |
|
55 | 56 | |
|
56 | 57 | def __load_defaults(self): |
|
57 | 58 | acl_groups = GroupList(RepoGroup.query().all(), |
|
58 | 59 | perm_set=['group.write', 'group.admin']) |
|
59 | 60 | c.repo_groups = RepoGroup.groups_choices(groups=acl_groups) |
|
60 | 61 | c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) |
|
61 | 62 | choices, c.landing_revs = ScmModel().get_repo_landing_revs() |
|
62 | 63 | c.landing_revs_choices = choices |
|
63 | 64 | |
|
64 | 65 | def __load_data(self, repo_name=None): |
|
65 | 66 | """ |
|
66 | 67 | Load defaults settings for edit, and update |
|
67 | 68 | |
|
68 | 69 | :param repo_name: |
|
69 | 70 | """ |
|
70 | 71 | self.__load_defaults() |
|
71 | 72 | |
|
72 | 73 | c.repo_info = db_repo = Repository.get_by_repo_name(repo_name) |
|
73 | 74 | repo = db_repo.scm_instance |
|
74 | 75 | |
|
75 | 76 | if c.repo_info is None: |
|
76 | 77 | h.not_mapped_error(repo_name) |
|
77 | 78 | return redirect(url('repos')) |
|
78 | 79 | |
|
79 | 80 | c.default_user_id = User.get_by_username('default').user_id |
|
80 | 81 | c.in_public_journal = UserFollowing.query()\ |
|
81 | 82 | .filter(UserFollowing.user_id == c.default_user_id)\ |
|
82 | 83 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
|
83 | 84 | |
|
84 | 85 | if c.repo_info.stats: |
|
85 | 86 | last_rev = c.repo_info.stats.stat_on_revision+1 |
|
86 | 87 | else: |
|
87 | 88 | last_rev = 0 |
|
88 | 89 | c.stats_revision = last_rev |
|
89 | 90 | |
|
90 | 91 | c.repo_last_rev = repo.count() if repo.revisions else 0 |
|
91 | 92 | |
|
92 | 93 | if last_rev == 0 or c.repo_last_rev == 0: |
|
93 | 94 | c.stats_percentage = 0 |
|
94 | 95 | else: |
|
95 | 96 | c.stats_percentage = '%.2f' % ((float((last_rev)) / |
|
96 | 97 | c.repo_last_rev) * 100) |
|
97 | 98 | |
|
99 | c.can_update = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active | |
|
100 | ||
|
98 | 101 | defaults = RepoModel()._get_defaults(repo_name) |
|
99 | 102 | # alter the description to indicate a fork |
|
100 | 103 | defaults['description'] = ('fork of repository: %s \n%s' |
|
101 | 104 | % (defaults['repo_name'], |
|
102 | 105 | defaults['description'])) |
|
103 | 106 | # add suffix to fork |
|
104 | 107 | defaults['repo_name'] = '%s-fork' % defaults['repo_name'] |
|
105 | 108 | |
|
106 | 109 | return defaults |
|
107 | 110 | |
|
108 | 111 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
109 | 112 | 'repository.admin') |
|
110 | 113 | def forks(self, repo_name): |
|
111 | 114 | p = safe_int(request.params.get('page', 1), 1) |
|
112 | 115 | repo_id = c.rhodecode_db_repo.repo_id |
|
113 | 116 | d = [] |
|
114 | 117 | for r in Repository.get_repo_forks(repo_id): |
|
115 | 118 | if not HasRepoPermissionAny( |
|
116 | 119 | 'repository.read', 'repository.write', 'repository.admin' |
|
117 | 120 | )(r.repo_name, 'get forks check'): |
|
118 | 121 | continue |
|
119 | 122 | d.append(r) |
|
120 | 123 | c.forks_pager = Page(d, page=p, items_per_page=20) |
|
121 | 124 | |
|
122 | 125 | c.forks_data = render('/forks/forks_data.html') |
|
123 | 126 | |
|
124 | 127 | if request.environ.get('HTTP_X_PARTIAL_XHR'): |
|
125 | 128 | return c.forks_data |
|
126 | 129 | |
|
127 | 130 | return render('/forks/forks.html') |
|
128 | 131 | |
|
129 | 132 | @NotAnonymous() |
|
130 | 133 | @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
|
131 | 134 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
132 | 135 | 'repository.admin') |
|
133 | 136 | def fork(self, repo_name): |
|
134 | 137 | c.repo_info = Repository.get_by_repo_name(repo_name) |
|
135 | 138 | if not c.repo_info: |
|
136 | 139 | h.not_mapped_error(repo_name) |
|
137 | 140 | return redirect(url('home')) |
|
138 | 141 | |
|
139 | 142 | defaults = self.__load_data(repo_name) |
|
140 | 143 | |
|
141 | 144 | return htmlfill.render( |
|
142 | 145 | render('forks/fork.html'), |
|
143 | 146 | defaults=defaults, |
|
144 | 147 | encoding="UTF-8", |
|
145 | 148 | force_defaults=False |
|
146 | 149 | ) |
|
147 | 150 | |
|
148 | 151 | @NotAnonymous() |
|
149 | 152 | @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
|
150 | 153 | @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
|
151 | 154 | 'repository.admin') |
|
152 | 155 | def fork_create(self, repo_name): |
|
153 | 156 | self.__load_defaults() |
|
154 | 157 | c.repo_info = Repository.get_by_repo_name(repo_name) |
|
155 | 158 | _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type}, |
|
156 | 159 | repo_groups=c.repo_groups_choices, |
|
157 | 160 | landing_revs=c.landing_revs_choices)() |
|
158 | 161 | form_result = {} |
|
159 | 162 | try: |
|
160 | 163 | form_result = _form.to_python(dict(request.POST)) |
|
161 | 164 | |
|
165 | # an approximation that is better than nothing | |
|
166 | if not RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active: | |
|
167 | form_result['update_after_clone'] = False | |
|
168 | ||
|
162 | 169 | # create fork is done sometimes async on celery, db transaction |
|
163 | 170 | # management is handled there. |
|
164 | 171 | RepoModel().create_fork(form_result, self.rhodecode_user.user_id) |
|
165 | 172 | fork_url = h.link_to(form_result['repo_name_full'], |
|
166 | 173 | h.url('summary_home', repo_name=form_result['repo_name_full'])) |
|
167 | 174 | |
|
168 | 175 | h.flash(h.literal(_('Forked repository %s as %s') \ |
|
169 | 176 | % (repo_name, fork_url)), |
|
170 | 177 | category='success') |
|
171 | 178 | except formencode.Invalid, errors: |
|
172 | 179 | c.new_repo = errors.value['repo_name'] |
|
173 | 180 | |
|
174 | 181 | return htmlfill.render( |
|
175 | 182 | render('forks/fork.html'), |
|
176 | 183 | defaults=errors.value, |
|
177 | 184 | errors=errors.error_dict or {}, |
|
178 | 185 | prefix_error=False, |
|
179 | 186 | encoding="UTF-8") |
|
180 | 187 | except Exception: |
|
181 | 188 | log.error(traceback.format_exc()) |
|
182 | 189 | h.flash(_('An error occurred during repository forking %s') % |
|
183 | 190 | repo_name, category='error') |
|
184 | 191 | |
|
185 | 192 | return redirect(h.url('summary_home', repo_name=repo_name)) |
@@ -1,100 +1,102 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | <%inherit file="/base/base.html"/> |
|
3 | 3 | |
|
4 | 4 | <%def name="title()"> |
|
5 | 5 | ${_('%s Fork') % c.repo_name} - ${c.rhodecode_name} |
|
6 | 6 | </%def> |
|
7 | 7 | |
|
8 | 8 | <%def name="breadcrumbs_links()"> |
|
9 | 9 | ${h.link_to(_(u'Home'),h.url('/'))} |
|
10 | 10 | » |
|
11 | 11 | ${h.repo_link(c.rhodecode_db_repo.groups_and_repo)} |
|
12 | 12 | » |
|
13 | 13 | ${_('fork')} |
|
14 | 14 | </%def> |
|
15 | 15 | |
|
16 | 16 | <%def name="page_nav()"> |
|
17 | 17 | ${self.menu('')} |
|
18 | 18 | </%def> |
|
19 | 19 | <%def name="main()"> |
|
20 | 20 | <div class="box"> |
|
21 | 21 | <!-- box / title --> |
|
22 | 22 | <div class="title"> |
|
23 | 23 | ${self.breadcrumbs()} |
|
24 | 24 | </div> |
|
25 | 25 | ${h.form(url('repo_fork_create_home',repo_name=c.repo_info.repo_name))} |
|
26 | 26 | <div class="form"> |
|
27 | 27 | <!-- fields --> |
|
28 | 28 | <div class="fields"> |
|
29 | 29 | <div class="field"> |
|
30 | 30 | <div class="label"> |
|
31 | 31 | <label for="repo_name">${_('Fork name')}:</label> |
|
32 | 32 | </div> |
|
33 | 33 | <div class="input"> |
|
34 | 34 | ${h.text('repo_name',class_="small")} |
|
35 | 35 | ${h.hidden('repo_type',c.repo_info.repo_type)} |
|
36 | 36 | ${h.hidden('fork_parent_id',c.repo_info.repo_id)} |
|
37 | 37 | </div> |
|
38 | 38 | </div> |
|
39 | 39 | <div class="field"> |
|
40 | 40 | <div class="label"> |
|
41 | 41 | <label for="landing_rev">${_('Landing revision')}:</label> |
|
42 | 42 | </div> |
|
43 | 43 | <div class="input"> |
|
44 | 44 | ${h.select('landing_rev','',c.landing_revs,class_="medium")} |
|
45 | 45 | <span class="help-block">${_('Default revision for files page, downloads, whoosh and readme')}</span> |
|
46 | 46 | </div> |
|
47 | 47 | </div> |
|
48 | 48 | <div class="field"> |
|
49 | 49 | <div class="label"> |
|
50 | 50 | <label for="repo_group">${_('Repository group')}:</label> |
|
51 | 51 | </div> |
|
52 | 52 | <div class="input"> |
|
53 | 53 | ${h.select('repo_group','',c.repo_groups,class_="medium")} |
|
54 | 54 | <span class="help-block">${_('Optionaly select a group to put this repository into.')}</span> |
|
55 | 55 | </div> |
|
56 | 56 | </div> |
|
57 | 57 | <div class="field"> |
|
58 | 58 | <div class="label label-textarea"> |
|
59 | 59 | <label for="description">${_('Description')}:</label> |
|
60 | 60 | </div> |
|
61 | 61 | <div class="textarea text-area editor"> |
|
62 | 62 | ${h.textarea('description',cols=23,rows=5)} |
|
63 | 63 | <span class="help-block">${_('Keep it short and to the point. Use a README file for longer descriptions.')}</span> |
|
64 | 64 | </div> |
|
65 | 65 | </div> |
|
66 | 66 | <div class="field"> |
|
67 | 67 | <div class="label label-checkbox"> |
|
68 | 68 | <label for="private">${_('Private')}:</label> |
|
69 | 69 | </div> |
|
70 | 70 | <div class="checkboxes"> |
|
71 | 71 | ${h.checkbox('private',value="True")} |
|
72 | 72 | <span class="help-block">${_('Private repositories are only visible to people explicitly added as collaborators.')}</span> |
|
73 | 73 | </div> |
|
74 | 74 | </div> |
|
75 | 75 | <div class="field"> |
|
76 | 76 | <div class="label label-checkbox"> |
|
77 | 77 | <label for="private">${_('Copy permissions')}:</label> |
|
78 | 78 | </div> |
|
79 | 79 | <div class="checkboxes"> |
|
80 | 80 | ${h.checkbox('copy_permissions',value="True", checked="checked")} |
|
81 | 81 | <span class="help-block">${_('Copy permissions from forked repository')}</span> |
|
82 | 82 | </div> |
|
83 | 83 |
|
|
84 | %if c.can_update: | |
|
84 | 85 | <div class="field"> |
|
85 | 86 | <div class="label label-checkbox"> |
|
86 | 87 | <label for="private">${_('Update after clone')}:</label> |
|
87 | 88 | </div> |
|
88 | 89 | <div class="checkboxes"> |
|
89 | 90 | ${h.checkbox('update_after_clone',value="True")} |
|
90 | 91 | <span class="help-block">${_('Checkout source after making a clone')}</span> |
|
91 | 92 | </div> |
|
92 | 93 | </div> |
|
94 | %endif | |
|
93 | 95 | <div class="buttons"> |
|
94 | 96 | ${h.submit('',_('Fork this repository'),class_="ui-btn large")} |
|
95 | 97 | </div> |
|
96 | 98 | </div> |
|
97 | 99 | </div> |
|
98 | 100 | ${h.end_form()} |
|
99 | 101 | </div> |
|
100 | 102 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now