Mercurial > kallithea
annotate rhodecode/controllers/forks.py @ 3705:f37d7514e7ab beta
always use json from compat module
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 07 Apr 2013 19:55:30 +0200 |
parents | 6c88624c719b |
children | 7e3d89d9d3a2 da36ba4afecf |
rev | line source |
---|---|
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.controllers.forks |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 forks controller for rhodecode |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Apr 23, 2011 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1807
diff
changeset
|
10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # (at your option) any later version. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 import logging |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
26 import formencode |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
27 import traceback |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
28 from formencode import htmlfill |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
30 from pylons import tmpl_context as c, request, url |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
31 from pylons.controllers.util import redirect |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
32 from pylons.i18n.translation import _ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
33 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
34 import rhodecode.lib.helpers as h |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from rhodecode.lib.helpers import Page |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
37 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
38 NotAnonymous, HasRepoPermissionAny, HasPermissionAllDecorator,\ |
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
39 HasPermissionAnyDecorator |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 from rhodecode.lib.base import BaseRepoController, render |
3571
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
41 from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User,\ |
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
42 RhodeCodeUi |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
43 from rhodecode.model.repo import RepoModel |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
44 from rhodecode.model.forms import RepoForkForm |
3239
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3236
diff
changeset
|
45 from rhodecode.model.scm import ScmModel, GroupList |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
46 from rhodecode.lib.utils2 import safe_int |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 log = logging.getLogger(__name__) |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 class ForksController(BaseRepoController): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 @LoginRequired() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 def __before__(self): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 super(ForksController, self).__before__() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
57 def __load_defaults(self): |
3239
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3236
diff
changeset
|
58 acl_groups = GroupList(RepoGroup.query().all(), |
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3236
diff
changeset
|
59 perm_set=['group.write', 'group.admin']) |
a9565b8b429b
filter out repo groups choices to only ones that you have write+ access to. Before it was read+ access and you got proper
Marcin Kuzminski <marcin@python-works.com>
parents:
3236
diff
changeset
|
60 c.repo_groups = RepoGroup.groups_choices(groups=acl_groups) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
61 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) |
2485
133209bf300c
added landing revision into fork create form
Marcin Kuzminski <marcin@python-works.com>
parents:
2176
diff
changeset
|
62 choices, c.landing_revs = ScmModel().get_repo_landing_revs() |
133209bf300c
added landing revision into fork create form
Marcin Kuzminski <marcin@python-works.com>
parents:
2176
diff
changeset
|
63 c.landing_revs_choices = choices |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
64 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
65 def __load_data(self, repo_name=None): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
66 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
67 Load defaults settings for edit, and update |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
68 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
69 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
70 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
71 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
72 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
73 c.repo_info = db_repo = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
74 repo = db_repo.scm_instance |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
75 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
76 if c.repo_info is None: |
3110
144128efc6ab
- #683 fixed difference between messages about not mapped repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
77 h.not_mapped_error(repo_name) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
78 return redirect(url('repos')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
79 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
80 c.default_user_id = User.get_by_username('default').user_id |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
81 c.in_public_journal = UserFollowing.query()\ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
82 .filter(UserFollowing.user_id == c.default_user_id)\ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
83 .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
84 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
85 if c.repo_info.stats: |
1807
1635a21485d6
- fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
86 last_rev = c.repo_info.stats.stat_on_revision+1 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
87 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
88 last_rev = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
89 c.stats_revision = last_rev |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
90 |
1807
1635a21485d6
- fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
91 c.repo_last_rev = repo.count() if repo.revisions else 0 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
92 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
93 if last_rev == 0 or c.repo_last_rev == 0: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
94 c.stats_percentage = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
95 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
96 c.stats_percentage = '%.2f' % ((float((last_rev)) / |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
97 c.repo_last_rev) * 100) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
98 |
3571
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
99 c.can_update = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active |
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
100 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
101 defaults = RepoModel()._get_defaults(repo_name) |
3236 | 102 # alter the description to indicate a fork |
103 defaults['description'] = ('fork of repository: %s \n%s' | |
104 % (defaults['repo_name'], | |
105 defaults['description'])) | |
3010
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2845
diff
changeset
|
106 # add suffix to fork |
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2845
diff
changeset
|
107 defaults['repo_name'] = '%s-fork' % defaults['repo_name'] |
3236 | 108 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
109 return defaults |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
110 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
111 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
112 'repository.admin') |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 def forks(self, repo_name): |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
114 p = safe_int(request.params.get('page', 1), 1) |
1375
f9559677c953
added tests for forks and followers pages
Marcin Kuzminski <marcin@python-works.com>
parents:
1301
diff
changeset
|
115 repo_id = c.rhodecode_db_repo.repo_id |
2176
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
116 d = [] |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
117 for r in Repository.get_repo_forks(repo_id): |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
118 if not HasRepoPermissionAny( |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
119 'repository.read', 'repository.write', 'repository.admin' |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
120 )(r.repo_name, 'get forks check'): |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
121 continue |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
122 d.append(r) |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 c.forks_pager = Page(d, page=p, items_per_page=20) |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 c.forks_data = render('/forks/forks_data.html') |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 |
1421
c6b811f11c94
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
Marcin Kuzminski <marcin@python-works.com>
parents:
1375
diff
changeset
|
127 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 return c.forks_data |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 return render('/forks/forks.html') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
131 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
132 @NotAnonymous() |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
133 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
134 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
135 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
136 def fork(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
137 c.repo_info = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
138 if not c.repo_info: |
3110
144128efc6ab
- #683 fixed difference between messages about not mapped repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
3010
diff
changeset
|
139 h.not_mapped_error(repo_name) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
140 return redirect(url('home')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
141 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
142 defaults = self.__load_data(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
143 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
144 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
145 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
146 defaults=defaults, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
147 encoding="UTF-8", |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
148 force_defaults=False |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
149 ) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
150 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
151 @NotAnonymous() |
2709
d2d35cf2b351
RhodeCode now has a option to explicitly set forking permissions. ref #508
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
152 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
153 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
154 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
155 def fork_create(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
156 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
157 c.repo_info = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
158 _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type}, |
2485
133209bf300c
added landing revision into fork create form
Marcin Kuzminski <marcin@python-works.com>
parents:
2176
diff
changeset
|
159 repo_groups=c.repo_groups_choices, |
133209bf300c
added landing revision into fork create form
Marcin Kuzminski <marcin@python-works.com>
parents:
2176
diff
changeset
|
160 landing_revs=c.landing_revs_choices)() |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
161 form_result = {} |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
162 try: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
163 form_result = _form.to_python(dict(request.POST)) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
164 |
3571
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
165 # an approximation that is better than nothing |
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
166 if not RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE).ui_active: |
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
167 form_result['update_after_clone'] = False |
6c88624c719b
fork: 'Update after clone' only makes sense if the update hook will maintain it
Mads Kiilerich <madski@unity3d.com>
parents:
3566
diff
changeset
|
168 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
169 # create fork is done sometimes async on celery, db transaction |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
170 # management is handled there. |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2485
diff
changeset
|
171 RepoModel().create_fork(form_result, self.rhodecode_user.user_id) |
3566
5068bb494129
stay on repo after forking and show full path to new fork
Mads Kiilerich <madski@unity3d.com>
parents:
3565
diff
changeset
|
172 fork_url = h.link_to(form_result['repo_name_full'], |
3547
b7f489714639
linkify names on fork/create repos in tooltip messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
173 h.url('summary_home', repo_name=form_result['repo_name_full'])) |
b7f489714639
linkify names on fork/create repos in tooltip messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
174 |
3565
a8f2d78d14ea
consistently capitalize initial letter in flash messages
Mads Kiilerich <madski@unity3d.com>
parents:
3547
diff
changeset
|
175 h.flash(h.literal(_('Forked repository %s as %s') \ |
3547
b7f489714639
linkify names on fork/create repos in tooltip messages
Marcin Kuzminski <marcin@python-works.com>
parents:
3239
diff
changeset
|
176 % (repo_name, fork_url)), |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
177 category='success') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
178 except formencode.Invalid, errors: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
179 c.new_repo = errors.value['repo_name'] |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
180 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
181 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
182 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
183 defaults=errors.value, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
184 errors=errors.error_dict or {}, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
185 prefix_error=False, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
186 encoding="UTF-8") |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
187 except Exception: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
188 log.error(traceback.format_exc()) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
189 h.flash(_('An error occurred during repository forking %s') % |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
190 repo_name, category='error') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
191 |
3566
5068bb494129
stay on repo after forking and show full path to new fork
Mads Kiilerich <madski@unity3d.com>
parents:
3565
diff
changeset
|
192 return redirect(h.url('summary_home', repo_name=repo_name)) |