Mercurial > kallithea
annotate rhodecode/controllers/forks.py @ 3503:7adeca7b99c2 beta
root.html: IE do not like extra ',' in maps
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 07 Mar 2013 15:23:36 +0100 |
parents | a9565b8b429b |
children | b7f489714639 |
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 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
41 from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
42 from rhodecode.model.repo import RepoModel |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
43 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
|
44 from rhodecode.model.scm import ScmModel, GroupList |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
45 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
|
46 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 log = logging.getLogger(__name__) |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 |
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 class ForksController(BaseRepoController): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 @LoginRequired() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 def __before__(self): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 super(ForksController, self).__before__() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 c.landing_revs_choices = choices |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
63 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
64 def __load_data(self, repo_name=None): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
65 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
66 Load defaults settings for edit, and update |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
67 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
68 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
69 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
70 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
71 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
72 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
|
73 repo = db_repo.scm_instance |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
74 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
75 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
|
76 h.not_mapped_error(repo_name) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
77 return redirect(url('repos')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
78 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
79 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
|
80 c.in_public_journal = UserFollowing.query()\ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
81 .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
|
82 .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
|
83 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
84 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
|
85 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
|
86 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
87 last_rev = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
88 c.stats_revision = last_rev |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
89 |
1807
1635a21485d6
- fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
90 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
|
91 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
92 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
|
93 c.stats_percentage = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
94 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
95 c.stats_percentage = '%.2f' % ((float((last_rev)) / |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
96 c.repo_last_rev) * 100) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
97 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
98 defaults = RepoModel()._get_defaults(repo_name) |
3236 | 99 # alter the description to indicate a fork |
100 defaults['description'] = ('fork of repository: %s \n%s' | |
101 % (defaults['repo_name'], | |
102 defaults['description'])) | |
3010
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2845
diff
changeset
|
103 # add suffix to fork |
bf96fd1920c1
Enabled compare engine for tags
Marcin Kuzminski <marcin@python-works.com>
parents:
2845
diff
changeset
|
104 defaults['repo_name'] = '%s-fork' % defaults['repo_name'] |
3236 | 105 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
106 return defaults |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
107 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
108 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
109 'repository.admin') |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 def forks(self, repo_name): |
2845
6b176c679896
failsafe the GET `page` argument
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
111 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
|
112 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
|
113 d = [] |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
114 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
|
115 if not HasRepoPermissionAny( |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
116 'repository.read', 'repository.write', 'repository.admin' |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
117 )(r.repo_name, 'get forks check'): |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
118 continue |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
119 d.append(r) |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 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
|
121 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 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
|
123 |
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
|
124 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
|
125 return c.forks_data |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 return render('/forks/forks.html') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
128 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
129 @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
|
130 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
131 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
132 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
133 def fork(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
134 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
|
135 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
|
136 h.not_mapped_error(repo_name) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
137 return redirect(url('home')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
138 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
139 defaults = self.__load_data(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
140 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
141 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
142 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
143 defaults=defaults, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
144 encoding="UTF-8", |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
145 force_defaults=False |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
146 ) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
147 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
148 @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
|
149 @HasPermissionAnyDecorator('hg.admin', 'hg.fork.repository') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
150 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
151 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
152 def fork_create(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
153 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
154 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
|
155 _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
|
156 repo_groups=c.repo_groups_choices, |
133209bf300c
added landing revision into fork create form
Marcin Kuzminski <marcin@python-works.com>
parents:
2176
diff
changeset
|
157 landing_revs=c.landing_revs_choices)() |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
158 form_result = {} |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
159 try: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
160 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
|
161 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
162 # 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
|
163 # 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
|
164 RepoModel().create_fork(form_result, self.rhodecode_user.user_id) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
165 h.flash(_('forked %s repository as %s') \ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
166 % (repo_name, form_result['repo_name']), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
167 category='success') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
168 except formencode.Invalid, errors: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
169 c.new_repo = errors.value['repo_name'] |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
170 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
171 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
172 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
173 defaults=errors.value, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
174 errors=errors.error_dict or {}, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
175 prefix_error=False, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
176 encoding="UTF-8") |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
177 except Exception: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
178 log.error(traceback.format_exc()) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
179 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
|
180 repo_name, category='error') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
181 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
182 return redirect(url('home')) |