annotate rhodecode/controllers/pullrequests.py @ 2496:fddd8e3fc157 beta

use get_or_404 where possible
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 20 Jun 2012 21:42:05 +0200
parents a0adf8db1416
children 5a826060251f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.controllers.pullrequests
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 pull requests controller for rhodecode for initializing pull requests
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :created_on: May 7, 2012
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :author: marcink
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :license: GPLv3, see COPYING for more details.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 """
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software: you can redistribute it and/or modify
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # it under the terms of the GNU General Public License as published by
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # (at your option) any later version.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 import logging
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import traceback
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
27
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
28 from webob.exc import HTTPNotFound, HTTPForbidden
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
29 from collections import defaultdict
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
30 from itertools import groupby
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from pylons import request, response, session, tmpl_context as c, url
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from pylons.controllers.util import abort, redirect
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from pylons.i18n.translation import _
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
35 from pylons.decorators import jsonify
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.base import BaseRepoController, render
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
39 from rhodecode.lib import helpers as h
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
40 from rhodecode.lib import diffs
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
41 from rhodecode.lib.utils import action_logger
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
42 from rhodecode.model.db import User, PullRequest, ChangesetStatus,\
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
43 ChangesetComment
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
44 from rhodecode.model.pull_request import PullRequestModel
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
45 from rhodecode.model.meta import Session
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
46 from rhodecode.model.repo import RepoModel
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
47 from rhodecode.model.comment import ChangesetCommentsModel
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
48 from rhodecode.model.changeset_status import ChangesetStatusModel
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 log = logging.getLogger(__name__)
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 class PullrequestsController(BaseRepoController):
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 @LoginRequired()
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 'repository.admin')
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 def __before__(self):
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 super(PullrequestsController, self).__before__()
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
61 def _get_repo_refs(self, repo):
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 hist_l = []
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
64 branches_group = ([('branch:%s:%s' % (k, v), k) for
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
65 k, v in repo.branches.iteritems()], _("Branches"))
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
66 bookmarks_group = ([('book:%s:%s' % (k, v), k) for
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
67 k, v in repo.bookmarks.iteritems()], _("Bookmarks"))
2478
8eab81115660 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2444
diff changeset
68 tags_group = ([('tag:%s:%s' % (k, v), k) for
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
69 k, v in repo.tags.iteritems()], _("Tags"))
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 hist_l.append(bookmarks_group)
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 hist_l.append(branches_group)
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 hist_l.append(tags_group)
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 return hist_l
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
77 def show_all(self, repo_name):
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
78 c.pull_requests = PullRequestModel().get_all(repo_name)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
79 c.repo_name = repo_name
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
80 return render('/pullrequests/pullrequest_show_all.html')
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
81
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 def index(self):
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
83 org_repo = c.rhodecode_db_repo
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
84
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
85 if org_repo.scm_instance.alias != 'hg':
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
86 log.error('Review not available for GIT REPOS')
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
87 raise HTTPNotFound
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
88
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 c.org_refs = self._get_repo_refs(c.rhodecode_repo)
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
90 c.org_repos = []
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
91 c.other_repos = []
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
92 c.org_repos.append((org_repo.repo_name, '%s/%s' % (
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
93 org_repo.user.username, c.repo_name))
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
94 )
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
95
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
96 c.other_refs = c.org_refs
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
97 c.other_repos.extend(c.org_repos)
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
98 c.default_pull_request = org_repo.repo_name
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
99 #gather forks and add to this list
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
100 for fork in org_repo.forks:
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
101 c.other_repos.append((fork.repo_name, '%s/%s' % (
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
102 fork.user.username, fork.repo_name))
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
103 )
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
104 #add parents of this fork also
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
105 if org_repo.parent:
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
106 c.default_pull_request = org_repo.parent.repo_name
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
107 c.other_repos.append((org_repo.parent.repo_name, '%s/%s' % (
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
108 org_repo.parent.user.username,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
109 org_repo.parent.repo_name))
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
110 )
2395
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
111
b262e349a7a5 created pull-request overview
Marcin Kuzminski <marcin@python-works.com>
parents: 2244
diff changeset
112 c.review_members = []
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
113 c.available_members = []
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
114 for u in User.query().filter(User.username != 'default').all():
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
115 uname = u.username
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
116 if org_repo.user == u:
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
117 uname = _('%s (owner)' % u.username)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
118 # auto add owner to pull-request recipients
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
119 c.review_members.append([u.user_id, uname])
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
120 c.available_members.append([u.user_id, uname])
2244
77e376fdc4c6 pull requests draft UI
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
121 return render('/pullrequests/pullrequest.html')
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
122
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
123 def create(self, repo_name):
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
124 req_p = request.POST
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
125 org_repo = req_p['org_repo']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
126 org_ref = req_p['org_ref']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
127 other_repo = req_p['other_repo']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
128 other_ref = req_p['other_ref']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
129 revisions = req_p.getall('revisions')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
130 reviewers = req_p.getall('review_members')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
131 #TODO: wrap this into a FORM !!!
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
132
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
133 title = req_p['pullrequest_title']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
134 description = req_p['pullrequest_desc']
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
135
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
136 try:
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
137 model = PullRequestModel()
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
138 model.create(self.rhodecode_user.user_id, org_repo,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
139 org_ref, other_repo, other_ref, revisions,
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
140 reviewers, title, description)
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
141 Session.commit()
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
142 h.flash(_('Pull request send'), category='success')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
143 except Exception:
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
144 raise
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
145 h.flash(_('Error occured during sending pull request'),
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
146 category='error')
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
147 log.error(traceback.format_exc())
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
148
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
149 return redirect(url('changelog_home', repo_name=repo_name))
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
150
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
151 def _load_compare_data(self, pull_request):
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
152 """
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
153 Load context data needed for generating compare diff
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
154
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
155 :param pull_request:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
156 :type pull_request:
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
157 """
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
158
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
159 org_repo = pull_request.org_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
160 org_ref_type, org_ref_, org_ref = pull_request.org_ref.split(':')
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
161 other_repo = pull_request.other_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
162 other_ref_type, other_ref, other_ref_ = pull_request.other_ref.split(':')
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
163
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
164 org_ref = (org_ref_type, org_ref)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
165 other_ref = (other_ref_type, other_ref)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
166
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
167 c.org_repo = org_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
168 c.other_repo = other_repo
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
169
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
170 c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
171 org_repo, org_ref, other_repo, other_ref
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
172 )
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
173
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
174 c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
175 c.cs_ranges])
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
176 # defines that we need hidden inputs with changesets
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
177 c.as_form = request.GET.get('as_form', False)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
178
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
179 c.org_ref = org_ref[1]
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
180 c.other_ref = other_ref[1]
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
181 # diff needs to have swapped org with other to generate proper diff
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
182 _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
183 discovery_data)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
184 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
185 _parsed = diff_processor.prepare()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
186
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
187 c.files = []
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
188 c.changes = {}
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
189
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
190 for f in _parsed:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
191 fid = h.FID('', f['filename'])
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
192 c.files.append([fid, f['operation'], f['filename'], f['stats']])
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
193 diff = diff_processor.as_html(enable_comments=True,
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
194 diff_lines=[f])
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
195 c.changes[fid] = [f['operation'], f['filename'], diff]
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
196
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
197 def show(self, repo_name, pull_request_id):
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
198 repo_model = RepoModel()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
199 c.users_array = repo_model.get_users_js()
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
200 c.users_groups_array = repo_model.get_users_groups_js()
2496
fddd8e3fc157 use get_or_404 where possible
Marcin Kuzminski <marcin@python-works.com>
parents: 2489
diff changeset
201 c.pull_request = PullRequest.get_or_404(pull_request_id)
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
202
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
203 cc_model = ChangesetCommentsModel()
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
204 cs_model = ChangesetStatusModel()
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
205 _cs_statuses = cs_model.get_statuses(c.pull_request.org_repo,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
206 pull_request=c.pull_request,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
207 with_revisions=True)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
208
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
209 cs_statuses = defaultdict(list)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
210 for st in _cs_statuses:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
211 cs_statuses[st.author.username] += [st]
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
212
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
213 c.pull_request_reviewers = []
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
214 for o in c.pull_request.reviewers:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
215 st = cs_statuses.get(o.user.username, None)
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
216 if st:
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
217 sorter = lambda k: k.version
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
218 st = [(x, list(y)[0])
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
219 for x, y in (groupby(sorted(st, key=sorter), sorter))]
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
220 c.pull_request_reviewers.append([o.user, st])
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
221
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
222 # pull_requests repo_name we opened it against
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
223 # ie. other_repo must match
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
224 if repo_name != c.pull_request.other_repo.repo_name:
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
225 raise HTTPNotFound
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
226
2442
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
227 # load compare data into template context
3bf057a7f7e8 small refactoring, moved shared for diff generation of code into pull-request model
Marcin Kuzminski <marcin@python-works.com>
parents: 2440
diff changeset
228 self._load_compare_data(c.pull_request)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
229
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
230 # inline comments
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
231 c.inline_cnt = 0
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
232 c.inline_comments = cc_model.get_inline_comments(
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
233 c.rhodecode_db_repo.repo_id,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
234 pull_request=pull_request_id)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
235 # count inline comments
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
236 for __, lines in c.inline_comments:
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
237 for comments in lines.values():
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
238 c.inline_cnt += len(comments)
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
239 # comments
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
240 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
241 pull_request=pull_request_id)
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
242
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
243 # changeset(pull-request) status
2481
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
244 c.current_changeset_status = cs_model.calculate_status(
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
245 c.pull_request_reviewers
4d3032431d4f Adde pull request voting recalculation
Marcin Kuzminski <marcin@python-works.com>
parents: 2478
diff changeset
246 )
2440
1bc579bcd67a - pull request generates overview based on it's params
Marcin Kuzminski <marcin@python-works.com>
parents: 2434
diff changeset
247 c.changeset_statuses = ChangesetStatus.STATUSES
2487
995d938ce14b Fixed origin repo in pull-request view
Marcin Kuzminski <marcin@python-works.com>
parents: 2481
diff changeset
248 c.target_repo = c.pull_request.org_repo.repo_name
2434
f29469677319 Added basic models for saving open pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2395
diff changeset
249 return render('/pullrequests/pullrequest_show.html')
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
250
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
251 @jsonify
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
252 def comment(self, repo_name, pull_request_id):
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
253
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
254 status = request.POST.get('changeset_status')
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
255 change_status = request.POST.get('change_changeset_status')
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
256
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
257 comm = ChangesetCommentsModel().create(
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
258 text=request.POST.get('text'),
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
259 repo_id=c.rhodecode_db_repo.repo_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
260 user_id=c.rhodecode_user.user_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
261 pull_request=pull_request_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
262 f_path=request.POST.get('f_path'),
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
263 line_no=request.POST.get('line'),
2478
8eab81115660 white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2444
diff changeset
264 status_change=(ChangesetStatus.get_status_lbl(status)
2443
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
265 if status and change_status else None)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
266 )
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
267
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
268 # get status if set !
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
269 if status and change_status:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
270 ChangesetStatusModel().set_status(
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
271 c.rhodecode_db_repo.repo_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
272 status,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
273 c.rhodecode_user.user_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
274 comm,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
275 pull_request=pull_request_id
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
276 )
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
277 action_logger(self.rhodecode_user,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
278 'user_commented_pull_request:%s' % pull_request_id,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
279 c.rhodecode_db_repo, self.ip_addr, self.sa)
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
280
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
281 Session.commit()
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
282
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
283 if not request.environ.get('HTTP_X_PARTIAL_XHR'):
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
284 return redirect(h.url('pullrequest_show', repo_name=repo_name,
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
285 pull_request_id=pull_request_id))
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
286
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
287 data = {
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
288 'target_id': h.safeid(h.safe_unicode(request.POST.get('f_path'))),
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
289 }
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
290 if comm:
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
291 c.co = comm
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
292 data.update(comm.get_dict())
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
293 data.update({'rendered_text':
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
294 render('changeset/changeset_comment_block.html')})
fd0a822481ec - added commenting to pull requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2442
diff changeset
295
2444
b45e9fd75ac0 data checks
Marcin Kuzminski <marcin@python-works.com>
parents: 2443
diff changeset
296 return data
2489
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
297
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
298 @jsonify
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
299 def delete_comment(self, repo_name, comment_id):
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
300 co = ChangesetComment.get(comment_id)
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
301 owner = lambda: co.author.user_id == c.rhodecode_user.user_id
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
302 if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
303 ChangesetCommentsModel().delete(comment=co)
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
304 Session.commit()
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
305 return True
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
306 else:
a0adf8db1416 Enabled inline comments in pull-requests
Marcin Kuzminski <marcin@python-works.com>
parents: 2487
diff changeset
307 raise HTTPForbidden()