comparison rhodecode/controllers/pullrequests.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents b622e6849b67
children 7e5f8c12a3fc
comparison
equal deleted inserted replaced
4115:8b7294a804a0 4116:ffd45b185016
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.controllers.pullrequests
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
6 pull requests controller for rhodecode for initializing pull requests
7
8 :created_on: May 7, 2012
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
13 # This program is free software: you can redistribute it and/or modify 2 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by 3 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or 4 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version. 5 # (at your option) any later version.
17 # 6 #
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details. 10 # GNU General Public License for more details.
22 # 11 #
23 # You should have received a copy of the GNU General Public License 12 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
15 rhodecode.controllers.pullrequests
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
18 pull requests controller for rhodecode for initializing pull requests
19
20 :created_on: May 7, 2012
21 :author: marcink
22 :copyright: (c) 2013 RhodeCode GmbH.
23 :license: GPLv3, see LICENSE for more details.
24 """
25
25 import logging 26 import logging
26 import traceback 27 import traceback
27 import formencode 28 import formencode
28 29
29 from webob.exc import HTTPNotFound, HTTPForbidden 30 from webob.exc import HTTPNotFound, HTTPForbidden
61 62
62 def __before__(self): 63 def __before__(self):
63 super(PullrequestsController, self).__before__() 64 super(PullrequestsController, self).__before__()
64 repo_model = RepoModel() 65 repo_model = RepoModel()
65 c.users_array = repo_model.get_users_js() 66 c.users_array = repo_model.get_users_js()
66 c.users_groups_array = repo_model.get_users_groups_js() 67 c.user_groups_array = repo_model.get_user_groups_js()
67 68
68 def _get_repo_refs(self, repo, rev=None, branch=None, branch_rev=None): 69 def _get_repo_refs(self, repo, rev=None, branch=None, branch_rev=None):
69 """return a structure with repo's interesting changesets, suitable for 70 """return a structure with repo's interesting changesets, suitable for
70 the selectors in pullrequest.html 71 the selectors in pullrequest.html
71 72
104 if rev == branchrev: 105 if rev == branchrev:
105 selected = n 106 selected = n
106 if branch == abranch: 107 if branch == abranch:
107 selected = n 108 selected = n
108 branch = None 109 branch = None
109 if branch: # branch not in list - it is probably closed 110
111 if branch: # branch not in list - it is probably closed
110 revs = repo._repo.revs('max(branch(%s))', branch) 112 revs = repo._repo.revs('max(branch(%s))', branch)
111 if revs: 113 if revs:
112 cs = repo.get_changeset(revs[0]) 114 cs = repo.get_changeset(revs[0])
113 selected = 'branch:%s:%s' % (branch, cs.raw_id) 115 selected = 'branch:%s:%s' % (branch, cs.raw_id)
114 branches.append((selected, branch)) 116 branches.append((selected, branch))
122 124
123 tags = [] 125 tags = []
124 for tag, tagrev in repo.tags.iteritems(): 126 for tag, tagrev in repo.tags.iteritems():
125 n = 'tag:%s:%s' % (tag, tagrev) 127 n = 'tag:%s:%s' % (tag, tagrev)
126 tags.append((n, tag)) 128 tags.append((n, tag))
127 if rev == tagrev and tag != 'tip': # tip is not a real tag - and its branch is better 129 if rev == tagrev and tag != 'tip': # tip is not a real tag - and its branch is better
128 selected = n 130 selected = n
129 131
130 # prio 1: rev was selected as existing entry above 132 # prio 1: rev was selected as existing entry above
131 133
132 # prio 2: create special entry for rev; rev _must_ be used 134 # prio 2: create special entry for rev; rev _must_ be used
139 if peers and not selected: 141 if peers and not selected:
140 selected = peers[0][0][0] 142 selected = peers[0][0][0]
141 143
142 # prio 4: tip revision 144 # prio 4: tip revision
143 if not selected: 145 if not selected:
144 selected = 'tag:tip:%s' % repo.tags['tip'] 146 if h.is_hg(repo):
147 selected = 'tag:tip:%s' % repo.tags['tip']
148 else:
149 if 'master' in repo.branches:
150 selected = 'branch:master:%s' % repo.branches['master']
151 else:
152 k, v = repo.branches.items()[0]
153 selected = 'branch:%s:%s' % (k, v)
145 154
146 groups = [(specials, _("Special")), 155 groups = [(specials, _("Special")),
147 (peers, _("Peer branches")), 156 (peers, _("Peer branches")),
148 (bookmarks, _("Bookmarks")), 157 (bookmarks, _("Bookmarks")),
149 (branches, _("Branches")), 158 (branches, _("Branches")),
153 162
154 def _get_is_allowed_change_status(self, pull_request): 163 def _get_is_allowed_change_status(self, pull_request):
155 owner = self.rhodecode_user.user_id == pull_request.user_id 164 owner = self.rhodecode_user.user_id == pull_request.user_id
156 reviewer = self.rhodecode_user.user_id in [x.user_id for x in 165 reviewer = self.rhodecode_user.user_id in [x.user_id for x in
157 pull_request.reviewers] 166 pull_request.reviewers]
158 return (self.rhodecode_user.admin or owner or reviewer) 167 return self.rhodecode_user.admin or owner or reviewer
159 168
160 def _load_compare_data(self, pull_request, enable_comments=True): 169 def _load_compare_data(self, pull_request, enable_comments=True):
161 """ 170 """
162 Load context data needed for generating compare diff 171 Load context data needed for generating compare diff
163 172
245 @NotAnonymous() 254 @NotAnonymous()
246 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 255 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
247 'repository.admin') 256 'repository.admin')
248 def index(self): 257 def index(self):
249 org_repo = c.rhodecode_db_repo 258 org_repo = c.rhodecode_db_repo
250
251 if org_repo.scm_instance.alias != 'hg':
252 log.error('Review not available for GIT REPOS')
253 raise HTTPNotFound
254 259
255 try: 260 try:
256 org_repo.scm_instance.get_changeset() 261 org_repo.scm_instance.get_changeset()
257 except EmptyRepositoryError, e: 262 except EmptyRepositoryError, e:
258 h.flash(h.literal(_('There are no changesets yet')), 263 h.flash(h.literal(_('There are no changesets yet')),
364 pull_request = PullRequest.get_or_404(pull_request_id) 369 pull_request = PullRequest.get_or_404(pull_request_id)
365 if pull_request.is_closed(): 370 if pull_request.is_closed():
366 raise HTTPForbidden() 371 raise HTTPForbidden()
367 #only owner or admin can update it 372 #only owner or admin can update it
368 owner = pull_request.author.user_id == c.rhodecode_user.user_id 373 owner = pull_request.author.user_id == c.rhodecode_user.user_id
369 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: 374 repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
375 if h.HasPermissionAny('hg.admin') or repo_admin or owner:
370 reviewers_ids = map(int, filter(lambda v: v not in [None, ''], 376 reviewers_ids = map(int, filter(lambda v: v not in [None, ''],
371 request.POST.get('reviewers_ids', '').split(','))) 377 request.POST.get('reviewers_ids', '').split(',')))
372 378
373 PullRequestModel().update_reviewers(pull_request_id, reviewers_ids) 379 PullRequestModel().update_reviewers(pull_request_id, reviewers_ids)
374 Session().commit() 380 Session().commit()
375 return True 381 return True
376 raise HTTPForbidden() 382 raise HTTPForbidden()
386 if pull_request.author.user_id == c.rhodecode_user.user_id: 392 if pull_request.author.user_id == c.rhodecode_user.user_id:
387 PullRequestModel().delete(pull_request) 393 PullRequestModel().delete(pull_request)
388 Session().commit() 394 Session().commit()
389 h.flash(_('Successfully deleted pull request'), 395 h.flash(_('Successfully deleted pull request'),
390 category='success') 396 category='success')
391 return redirect(url('admin_settings_my_account', anchor='pullrequests')) 397 return redirect(url('my_account_pullrequests'))
392 raise HTTPForbidden() 398 raise HTTPForbidden()
393 399
394 @LoginRequired() 400 @LoginRequired()
395 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', 401 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
396 'repository.admin') 402 'repository.admin')
397 def show(self, repo_name, pull_request_id): 403 def show(self, repo_name, pull_request_id):
398 repo_model = RepoModel() 404 repo_model = RepoModel()
399 c.users_array = repo_model.get_users_js() 405 c.users_array = repo_model.get_users_js()
400 c.users_groups_array = repo_model.get_users_groups_js() 406 c.user_groups_array = repo_model.get_user_groups_js()
401 c.pull_request = PullRequest.get_or_404(pull_request_id) 407 c.pull_request = PullRequest.get_or_404(pull_request_id)
402 c.allowed_to_change_status = self._get_is_allowed_change_status(c.pull_request) 408 c.allowed_to_change_status = self._get_is_allowed_change_status(c.pull_request)
403 cc_model = ChangesetCommentsModel() 409 cc_model = ChangesetCommentsModel()
404 cs_model = ChangesetStatusModel() 410 cs_model = ChangesetStatusModel()
405 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo, 411 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
542 if co.pull_request.is_closed(): 548 if co.pull_request.is_closed():
543 #don't allow deleting comments on closed pull request 549 #don't allow deleting comments on closed pull request
544 raise HTTPForbidden() 550 raise HTTPForbidden()
545 551
546 owner = co.author.user_id == c.rhodecode_user.user_id 552 owner = co.author.user_id == c.rhodecode_user.user_id
547 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner: 553 repo_admin = h.HasRepoPermissionAny('repository.admin')(c.repo_name)
554 if h.HasPermissionAny('hg.admin') or repo_admin or owner:
548 ChangesetCommentsModel().delete(comment=co) 555 ChangesetCommentsModel().delete(comment=co)
549 Session().commit() 556 Session().commit()
550 return True 557 return True
551 else: 558 else:
552 raise HTTPForbidden() 559 raise HTTPForbidden()