Show More
The requested changes are too big and content was truncated. Show full diff
@@ -0,0 +1,43 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | import logging | |
|
4 | from sqlalchemy import * | |
|
5 | ||
|
6 | from alembic.migration import MigrationContext | |
|
7 | from alembic.operations import Operations | |
|
8 | from sqlalchemy import BigInteger | |
|
9 | ||
|
10 | from rhodecode.lib.dbmigrate.versions import _reset_base | |
|
11 | from rhodecode.model import init_model_encryption | |
|
12 | ||
|
13 | ||
|
14 | log = logging.getLogger(__name__) | |
|
15 | ||
|
16 | ||
|
17 | def upgrade(migrate_engine): | |
|
18 | """ | |
|
19 | Upgrade operations go here. | |
|
20 | Don't create your own engine; bind migrate_engine to your metadata | |
|
21 | """ | |
|
22 | _reset_base(migrate_engine) | |
|
23 | from rhodecode.lib.dbmigrate.schema import db_4_18_0_1 as db | |
|
24 | ||
|
25 | init_model_encryption(db) | |
|
26 | ||
|
27 | context = MigrationContext.configure(migrate_engine.connect()) | |
|
28 | op = Operations(context) | |
|
29 | ||
|
30 | comments = db.ChangesetComment.__table__ | |
|
31 | ||
|
32 | with op.batch_alter_table(comments.name) as batch_op: | |
|
33 | new_column = Column('immutable_state', Unicode(128), nullable=True) | |
|
34 | batch_op.add_column(new_column) | |
|
35 | ||
|
36 | ||
|
37 | def downgrade(migrate_engine): | |
|
38 | meta = MetaData() | |
|
39 | meta.bind = migrate_engine | |
|
40 | ||
|
41 | ||
|
42 | def fixups(models, _SESSION): | |
|
43 | pass |
@@ -1,60 +1,60 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | from collections import OrderedDict |
|
23 | 23 | |
|
24 | 24 | import sys |
|
25 | 25 | import platform |
|
26 | 26 | |
|
27 | 27 | VERSION = tuple(open(os.path.join( |
|
28 | 28 | os.path.dirname(__file__), 'VERSION')).read().split('.')) |
|
29 | 29 | |
|
30 | 30 | BACKENDS = OrderedDict() |
|
31 | 31 | |
|
32 | 32 | BACKENDS['hg'] = 'Mercurial repository' |
|
33 | 33 | BACKENDS['git'] = 'Git repository' |
|
34 | 34 | BACKENDS['svn'] = 'Subversion repository' |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | CELERY_ENABLED = False |
|
38 | 38 | CELERY_EAGER = False |
|
39 | 39 | |
|
40 | 40 | # link to config for pyramid |
|
41 | 41 | CONFIG = {} |
|
42 | 42 | |
|
43 | 43 | # Populated with the settings dictionary from application init in |
|
44 | 44 | # rhodecode.conf.environment.load_pyramid_environment |
|
45 | 45 | PYRAMID_SETTINGS = {} |
|
46 | 46 | |
|
47 | 47 | # Linked module for extensions |
|
48 | 48 | EXTENSIONS = {} |
|
49 | 49 | |
|
50 | 50 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
51 |
__dbversion__ = 10 |
|
|
51 | __dbversion__ = 106 # defines current db version for migrations | |
|
52 | 52 | __platform__ = platform.system() |
|
53 | 53 | __license__ = 'AGPLv3, and Commercial License' |
|
54 | 54 | __author__ = 'RhodeCode GmbH' |
|
55 | 55 | __url__ = 'https://code.rhodecode.com' |
|
56 | 56 | |
|
57 | 57 | is_windows = __platform__ in ['Windows'] |
|
58 | 58 | is_unix = not is_windows |
|
59 | 59 | is_test = False |
|
60 | 60 | disable_error_handler = False |
@@ -1,402 +1,402 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2016-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | import logging |
|
23 | 23 | import datetime |
|
24 | 24 | |
|
25 | 25 | from pyramid.view import view_config |
|
26 | 26 | from pyramid.renderers import render_to_response |
|
27 | 27 | from rhodecode.apps._base import BaseAppView |
|
28 | 28 | from rhodecode.lib.celerylib import run_task, tasks |
|
29 | 29 | from rhodecode.lib.utils2 import AttributeDict |
|
30 | 30 | from rhodecode.model.db import User |
|
31 | 31 | from rhodecode.model.notification import EmailNotificationModel |
|
32 | 32 | |
|
33 | 33 | log = logging.getLogger(__name__) |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | class DebugStyleView(BaseAppView): |
|
37 | 37 | def load_default_context(self): |
|
38 | 38 | c = self._get_local_tmpl_context() |
|
39 | 39 | |
|
40 | 40 | return c |
|
41 | 41 | |
|
42 | 42 | @view_config( |
|
43 | 43 | route_name='debug_style_home', request_method='GET', |
|
44 | 44 | renderer=None) |
|
45 | 45 | def index(self): |
|
46 | 46 | c = self.load_default_context() |
|
47 | 47 | c.active = 'index' |
|
48 | 48 | |
|
49 | 49 | return render_to_response( |
|
50 | 50 | 'debug_style/index.html', self._get_template_context(c), |
|
51 | 51 | request=self.request) |
|
52 | 52 | |
|
53 | 53 | @view_config( |
|
54 | 54 | route_name='debug_style_email', request_method='GET', |
|
55 | 55 | renderer=None) |
|
56 | 56 | @view_config( |
|
57 | 57 | route_name='debug_style_email_plain_rendered', request_method='GET', |
|
58 | 58 | renderer=None) |
|
59 | 59 | def render_email(self): |
|
60 | 60 | c = self.load_default_context() |
|
61 | 61 | email_id = self.request.matchdict['email_id'] |
|
62 | 62 | c.active = 'emails' |
|
63 | 63 | |
|
64 | 64 | pr = AttributeDict( |
|
65 | 65 | pull_request_id=123, |
|
66 | 66 | title='digital_ocean: fix redis, elastic search start on boot, ' |
|
67 | 67 | 'fix fd limits on supervisor, set postgres 11 version', |
|
68 | 68 | description=''' |
|
69 | 69 | Check if we should use full-topic or mini-topic. |
|
70 | 70 | |
|
71 | 71 | - full topic produces some problems with merge states etc |
|
72 | 72 | - server-mini-topic needs probably tweeks. |
|
73 | 73 | ''', |
|
74 | 74 | repo_name='foobar', |
|
75 | 75 | source_ref_parts=AttributeDict(type='branch', name='fix-ticket-2000'), |
|
76 | 76 | target_ref_parts=AttributeDict(type='branch', name='master'), |
|
77 | 77 | ) |
|
78 | 78 | target_repo = AttributeDict(repo_name='repo_group/target_repo') |
|
79 | 79 | source_repo = AttributeDict(repo_name='repo_group/source_repo') |
|
80 | 80 | user = User.get_by_username(self.request.GET.get('user')) or self._rhodecode_db_user |
|
81 | 81 | # file/commit changes for PR update |
|
82 | 82 | commit_changes = AttributeDict({ |
|
83 | 83 | 'added': ['aaaaaaabbbbb', 'cccccccddddddd'], |
|
84 | 84 | 'removed': ['eeeeeeeeeee'], |
|
85 | 85 | }) |
|
86 | 86 | file_changes = AttributeDict({ |
|
87 | 87 | 'added': ['a/file1.md', 'file2.py'], |
|
88 | 88 | 'modified': ['b/modified_file.rst'], |
|
89 | 89 | 'removed': ['.idea'], |
|
90 | 90 | }) |
|
91 | 91 | |
|
92 | 92 | exc_traceback = { |
|
93 | 93 | 'exc_utc_date': '2020-03-26T12:54:50.683281', |
|
94 | 94 | 'exc_id': 139638856342656, |
|
95 | 95 | 'exc_timestamp': '1585227290.683288', |
|
96 | 96 | 'version': 'v1', |
|
97 | 97 | 'exc_message': 'Traceback (most recent call last):\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/tweens.py", line 41, in excview_tween\n response = handler(request)\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/router.py", line 148, in handle_request\n registry, request, context, context_iface, view_name\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/view.py", line 667, in _call_view\n response = view_callable(context, request)\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/config/views.py", line 188, in attr_view\n return view(context, request)\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/config/views.py", line 214, in predicate_wrapper\n return view(context, request)\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/viewderivers.py", line 401, in viewresult_to_response\n result = view(context, request)\n File "/nix/store/s43k2r9rysfbzmsjdqnxgzvvb7zjhkxb-python2.7-pyramid-1.10.4/lib/python2.7/site-packages/pyramid/viewderivers.py", line 132, in _class_view\n response = getattr(inst, attr)()\n File "/mnt/hgfs/marcink/workspace/rhodecode-enterprise-ce/rhodecode/apps/debug_style/views.py", line 355, in render_email\n template_type, **email_kwargs.get(email_id, {}))\n File "/mnt/hgfs/marcink/workspace/rhodecode-enterprise-ce/rhodecode/model/notification.py", line 402, in render_email\n body = email_template.render(None, **_kwargs)\n File "/mnt/hgfs/marcink/workspace/rhodecode-enterprise-ce/rhodecode/lib/partial_renderer.py", line 95, in render\n return self._render_with_exc(tmpl, args, kwargs)\n File "/mnt/hgfs/marcink/workspace/rhodecode-enterprise-ce/rhodecode/lib/partial_renderer.py", line 79, in _render_with_exc\n return render_func.render(*args, **kwargs)\n File "/nix/store/dakh34sxz4yfr435c0cwjz0sd6hnd5g3-python2.7-mako-1.1.0/lib/python2.7/site-packages/mako/template.py", line 476, in render\n return runtime._render(self, self.callable_, args, data)\n File "/nix/store/dakh34sxz4yfr435c0cwjz0sd6hnd5g3-python2.7-mako-1.1.0/lib/python2.7/site-packages/mako/runtime.py", line 883, in _render\n **_kwargs_for_callable(callable_, data)\n File "/nix/store/dakh34sxz4yfr435c0cwjz0sd6hnd5g3-python2.7-mako-1.1.0/lib/python2.7/site-packages/mako/runtime.py", line 920, in _render_context\n _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)\n File "/nix/store/dakh34sxz4yfr435c0cwjz0sd6hnd5g3-python2.7-mako-1.1.0/lib/python2.7/site-packages/mako/runtime.py", line 947, in _exec_template\n callable_(context, *args, **kwargs)\n File "rhodecode_templates_email_templates_base_mako", line 63, in render_body\n File "rhodecode_templates_email_templates_exception_tracker_mako", line 43, in render_body\nAttributeError: \'str\' object has no attribute \'get\'\n', |
|
98 | 98 | 'exc_type': 'AttributeError' |
|
99 | 99 | } |
|
100 | 100 | email_kwargs = { |
|
101 | 101 | 'test': {}, |
|
102 | 102 | 'message': { |
|
103 | 103 | 'body': 'message body !' |
|
104 | 104 | }, |
|
105 | 105 | 'email_test': { |
|
106 | 106 | 'user': user, |
|
107 | 107 | 'date': datetime.datetime.now(), |
|
108 | 108 | }, |
|
109 | 109 | 'exception': { |
|
110 | 110 | 'email_prefix': '[RHODECODE ERROR]', |
|
111 | 111 | 'exc_id': exc_traceback['exc_id'], |
|
112 | 112 | 'exc_url': 'http://server-url/{}'.format(exc_traceback['exc_id']), |
|
113 | 113 | 'exc_type_name': 'NameError', |
|
114 | 114 | 'exc_traceback': exc_traceback, |
|
115 | 115 | }, |
|
116 | 116 | 'password_reset': { |
|
117 | 117 | 'password_reset_url': 'http://example.com/reset-rhodecode-password/token', |
|
118 | 118 | |
|
119 | 119 | 'user': user, |
|
120 | 120 | 'date': datetime.datetime.now(), |
|
121 | 121 | 'email': 'test@rhodecode.com', |
|
122 | 122 | 'first_admin_email': User.get_first_super_admin().email |
|
123 | 123 | }, |
|
124 | 124 | 'password_reset_confirmation': { |
|
125 | 125 | 'new_password': 'new-password-example', |
|
126 | 126 | 'user': user, |
|
127 | 127 | 'date': datetime.datetime.now(), |
|
128 | 128 | 'email': 'test@rhodecode.com', |
|
129 | 129 | 'first_admin_email': User.get_first_super_admin().email |
|
130 | 130 | }, |
|
131 | 131 | 'registration': { |
|
132 | 132 | 'user': user, |
|
133 | 133 | 'date': datetime.datetime.now(), |
|
134 | 134 | }, |
|
135 | 135 | |
|
136 | 136 | 'pull_request_comment': { |
|
137 | 137 | 'user': user, |
|
138 | 138 | |
|
139 | 139 | 'status_change': None, |
|
140 | 140 | 'status_change_type': None, |
|
141 | 141 | |
|
142 | 142 | 'pull_request': pr, |
|
143 | 143 | 'pull_request_commits': [], |
|
144 | 144 | |
|
145 | 145 | 'pull_request_target_repo': target_repo, |
|
146 | 146 | 'pull_request_target_repo_url': 'http://target-repo/url', |
|
147 | 147 | |
|
148 | 148 | 'pull_request_source_repo': source_repo, |
|
149 | 149 | 'pull_request_source_repo_url': 'http://source-repo/url', |
|
150 | 150 | |
|
151 | 151 | 'pull_request_url': 'http://localhost/pr1', |
|
152 | 152 | 'pr_comment_url': 'http://comment-url', |
|
153 | 153 | 'pr_comment_reply_url': 'http://comment-url#reply', |
|
154 | 154 | |
|
155 | 155 | 'comment_file': None, |
|
156 | 156 | 'comment_line': None, |
|
157 | 157 | 'comment_type': 'note', |
|
158 | 158 | 'comment_body': 'This is my comment body. *I like !*', |
|
159 | 159 | 'comment_id': 2048, |
|
160 | 160 | 'renderer_type': 'markdown', |
|
161 | 161 | 'mention': True, |
|
162 | 162 | |
|
163 | 163 | }, |
|
164 | 164 | 'pull_request_comment+status': { |
|
165 | 165 | 'user': user, |
|
166 | 166 | |
|
167 | 167 | 'status_change': 'approved', |
|
168 | 168 | 'status_change_type': 'approved', |
|
169 | 169 | |
|
170 | 170 | 'pull_request': pr, |
|
171 | 171 | 'pull_request_commits': [], |
|
172 | 172 | |
|
173 | 173 | 'pull_request_target_repo': target_repo, |
|
174 | 174 | 'pull_request_target_repo_url': 'http://target-repo/url', |
|
175 | 175 | |
|
176 | 176 | 'pull_request_source_repo': source_repo, |
|
177 | 177 | 'pull_request_source_repo_url': 'http://source-repo/url', |
|
178 | 178 | |
|
179 | 179 | 'pull_request_url': 'http://localhost/pr1', |
|
180 | 180 | 'pr_comment_url': 'http://comment-url', |
|
181 | 181 | 'pr_comment_reply_url': 'http://comment-url#reply', |
|
182 | 182 | |
|
183 | 183 | 'comment_type': 'todo', |
|
184 | 184 | 'comment_file': None, |
|
185 | 185 | 'comment_line': None, |
|
186 | 186 | 'comment_body': ''' |
|
187 | 187 | I think something like this would be better |
|
188 | 188 | |
|
189 | 189 | ```py |
|
190 | 190 | |
|
191 | 191 | def db(): |
|
192 | 192 | global connection |
|
193 | 193 | return connection |
|
194 | 194 | |
|
195 | 195 | ``` |
|
196 | 196 | |
|
197 | 197 | ''', |
|
198 | 198 | 'comment_id': 2048, |
|
199 | 199 | 'renderer_type': 'markdown', |
|
200 | 200 | 'mention': True, |
|
201 | 201 | |
|
202 | 202 | }, |
|
203 | 203 | 'pull_request_comment+file': { |
|
204 | 204 | 'user': user, |
|
205 | 205 | |
|
206 | 206 | 'status_change': None, |
|
207 | 207 | 'status_change_type': None, |
|
208 | 208 | |
|
209 | 209 | 'pull_request': pr, |
|
210 | 210 | 'pull_request_commits': [], |
|
211 | 211 | |
|
212 | 212 | 'pull_request_target_repo': target_repo, |
|
213 | 213 | 'pull_request_target_repo_url': 'http://target-repo/url', |
|
214 | 214 | |
|
215 | 215 | 'pull_request_source_repo': source_repo, |
|
216 | 216 | 'pull_request_source_repo_url': 'http://source-repo/url', |
|
217 | 217 | |
|
218 | 218 | 'pull_request_url': 'http://localhost/pr1', |
|
219 | 219 | |
|
220 | 220 | 'pr_comment_url': 'http://comment-url', |
|
221 | 221 | 'pr_comment_reply_url': 'http://comment-url#reply', |
|
222 | 222 | |
|
223 |
'comment_file': 'rhodecode/model/ |
|
|
223 | 'comment_file': 'rhodecode/model/get_flow_commits', | |
|
224 | 224 | 'comment_line': 'o1210', |
|
225 | 225 | 'comment_type': 'todo', |
|
226 | 226 | 'comment_body': ''' |
|
227 | 227 | I like this ! |
|
228 | 228 | |
|
229 | 229 | But please check this code:: |
|
230 | 230 | |
|
231 | 231 | def main(): |
|
232 | 232 | print 'ok' |
|
233 | 233 | |
|
234 | 234 | This should work better ! |
|
235 | 235 | ''', |
|
236 | 236 | 'comment_id': 2048, |
|
237 | 237 | 'renderer_type': 'rst', |
|
238 | 238 | 'mention': True, |
|
239 | 239 | |
|
240 | 240 | }, |
|
241 | 241 | |
|
242 | 242 | 'pull_request_update': { |
|
243 | 243 | 'updating_user': user, |
|
244 | 244 | |
|
245 | 245 | 'status_change': None, |
|
246 | 246 | 'status_change_type': None, |
|
247 | 247 | |
|
248 | 248 | 'pull_request': pr, |
|
249 | 249 | 'pull_request_commits': [], |
|
250 | 250 | |
|
251 | 251 | 'pull_request_target_repo': target_repo, |
|
252 | 252 | 'pull_request_target_repo_url': 'http://target-repo/url', |
|
253 | 253 | |
|
254 | 254 | 'pull_request_source_repo': source_repo, |
|
255 | 255 | 'pull_request_source_repo_url': 'http://source-repo/url', |
|
256 | 256 | |
|
257 | 257 | 'pull_request_url': 'http://localhost/pr1', |
|
258 | 258 | |
|
259 | 259 | # update comment links |
|
260 | 260 | 'pr_comment_url': 'http://comment-url', |
|
261 | 261 | 'pr_comment_reply_url': 'http://comment-url#reply', |
|
262 | 262 | 'ancestor_commit_id': 'f39bd443', |
|
263 | 263 | 'added_commits': commit_changes.added, |
|
264 | 264 | 'removed_commits': commit_changes.removed, |
|
265 | 265 | 'changed_files': (file_changes.added + file_changes.modified + file_changes.removed), |
|
266 | 266 | 'added_files': file_changes.added, |
|
267 | 267 | 'modified_files': file_changes.modified, |
|
268 | 268 | 'removed_files': file_changes.removed, |
|
269 | 269 | }, |
|
270 | 270 | |
|
271 | 271 | 'cs_comment': { |
|
272 | 272 | 'user': user, |
|
273 | 273 | 'commit': AttributeDict(idx=123, raw_id='a'*40, message='Commit message'), |
|
274 | 274 | 'status_change': None, |
|
275 | 275 | 'status_change_type': None, |
|
276 | 276 | |
|
277 | 277 | 'commit_target_repo_url': 'http://foo.example.com/#comment1', |
|
278 | 278 | 'repo_name': 'test-repo', |
|
279 | 279 | 'comment_type': 'note', |
|
280 | 280 | 'comment_file': None, |
|
281 | 281 | 'comment_line': None, |
|
282 | 282 | 'commit_comment_url': 'http://comment-url', |
|
283 | 283 | 'commit_comment_reply_url': 'http://comment-url#reply', |
|
284 | 284 | 'comment_body': 'This is my comment body. *I like !*', |
|
285 | 285 | 'comment_id': 2048, |
|
286 | 286 | 'renderer_type': 'markdown', |
|
287 | 287 | 'mention': True, |
|
288 | 288 | }, |
|
289 | 289 | 'cs_comment+status': { |
|
290 | 290 | 'user': user, |
|
291 | 291 | 'commit': AttributeDict(idx=123, raw_id='a' * 40, message='Commit message'), |
|
292 | 292 | 'status_change': 'approved', |
|
293 | 293 | 'status_change_type': 'approved', |
|
294 | 294 | |
|
295 | 295 | 'commit_target_repo_url': 'http://foo.example.com/#comment1', |
|
296 | 296 | 'repo_name': 'test-repo', |
|
297 | 297 | 'comment_type': 'note', |
|
298 | 298 | 'comment_file': None, |
|
299 | 299 | 'comment_line': None, |
|
300 | 300 | 'commit_comment_url': 'http://comment-url', |
|
301 | 301 | 'commit_comment_reply_url': 'http://comment-url#reply', |
|
302 | 302 | 'comment_body': ''' |
|
303 | 303 | Hello **world** |
|
304 | 304 | |
|
305 | 305 | This is a multiline comment :) |
|
306 | 306 | |
|
307 | 307 | - list |
|
308 | 308 | - list2 |
|
309 | 309 | ''', |
|
310 | 310 | 'comment_id': 2048, |
|
311 | 311 | 'renderer_type': 'markdown', |
|
312 | 312 | 'mention': True, |
|
313 | 313 | }, |
|
314 | 314 | 'cs_comment+file': { |
|
315 | 315 | 'user': user, |
|
316 | 316 | 'commit': AttributeDict(idx=123, raw_id='a' * 40, message='Commit message'), |
|
317 | 317 | 'status_change': None, |
|
318 | 318 | 'status_change_type': None, |
|
319 | 319 | |
|
320 | 320 | 'commit_target_repo_url': 'http://foo.example.com/#comment1', |
|
321 | 321 | 'repo_name': 'test-repo', |
|
322 | 322 | |
|
323 | 323 | 'comment_type': 'note', |
|
324 | 324 | 'comment_file': 'test-file.py', |
|
325 | 325 | 'comment_line': 'n100', |
|
326 | 326 | |
|
327 | 327 | 'commit_comment_url': 'http://comment-url', |
|
328 | 328 | 'commit_comment_reply_url': 'http://comment-url#reply', |
|
329 | 329 | 'comment_body': 'This is my comment body. *I like !*', |
|
330 | 330 | 'comment_id': 2048, |
|
331 | 331 | 'renderer_type': 'markdown', |
|
332 | 332 | 'mention': True, |
|
333 | 333 | }, |
|
334 | 334 | |
|
335 | 335 | 'pull_request': { |
|
336 | 336 | 'user': user, |
|
337 | 337 | 'pull_request': pr, |
|
338 | 338 | 'pull_request_commits': [ |
|
339 | 339 | ('472d1df03bf7206e278fcedc6ac92b46b01c4e21', '''\ |
|
340 | 340 | my-account: moved email closer to profile as it's similar data just moved outside. |
|
341 | 341 | '''), |
|
342 | 342 | ('cbfa3061b6de2696c7161ed15ba5c6a0045f90a7', '''\ |
|
343 | 343 | users: description edit fixes |
|
344 | 344 | |
|
345 | 345 | - tests |
|
346 | 346 | - added metatags info |
|
347 | 347 | '''), |
|
348 | 348 | ], |
|
349 | 349 | |
|
350 | 350 | 'pull_request_target_repo': target_repo, |
|
351 | 351 | 'pull_request_target_repo_url': 'http://target-repo/url', |
|
352 | 352 | |
|
353 | 353 | 'pull_request_source_repo': source_repo, |
|
354 | 354 | 'pull_request_source_repo_url': 'http://source-repo/url', |
|
355 | 355 | |
|
356 | 356 | 'pull_request_url': 'http://code.rhodecode.com/_pull-request/123', |
|
357 | 357 | } |
|
358 | 358 | |
|
359 | 359 | } |
|
360 | 360 | |
|
361 | 361 | template_type = email_id.split('+')[0] |
|
362 | 362 | (c.subject, c.headers, c.email_body, |
|
363 | 363 | c.email_body_plaintext) = EmailNotificationModel().render_email( |
|
364 | 364 | template_type, **email_kwargs.get(email_id, {})) |
|
365 | 365 | |
|
366 | 366 | test_email = self.request.GET.get('email') |
|
367 | 367 | if test_email: |
|
368 | 368 | recipients = [test_email] |
|
369 | 369 | run_task(tasks.send_email, recipients, c.subject, |
|
370 | 370 | c.email_body_plaintext, c.email_body) |
|
371 | 371 | |
|
372 | 372 | if self.request.matched_route.name == 'debug_style_email_plain_rendered': |
|
373 | 373 | template = 'debug_style/email_plain_rendered.mako' |
|
374 | 374 | else: |
|
375 | 375 | template = 'debug_style/email.mako' |
|
376 | 376 | return render_to_response( |
|
377 | 377 | template, self._get_template_context(c), |
|
378 | 378 | request=self.request) |
|
379 | 379 | |
|
380 | 380 | @view_config( |
|
381 | 381 | route_name='debug_style_template', request_method='GET', |
|
382 | 382 | renderer=None) |
|
383 | 383 | def template(self): |
|
384 | 384 | t_path = self.request.matchdict['t_path'] |
|
385 | 385 | c = self.load_default_context() |
|
386 | 386 | c.active = os.path.splitext(t_path)[0] |
|
387 | 387 | c.came_from = '' |
|
388 | 388 | c.email_types = { |
|
389 | 389 | 'cs_comment+file': {}, |
|
390 | 390 | 'cs_comment+status': {}, |
|
391 | 391 | |
|
392 | 392 | 'pull_request_comment+file': {}, |
|
393 | 393 | 'pull_request_comment+status': {}, |
|
394 | 394 | |
|
395 | 395 | 'pull_request_update': {}, |
|
396 | 396 | } |
|
397 | 397 | c.email_types.update(EmailNotificationModel.email_types) |
|
398 | 398 | |
|
399 | 399 | return render_to_response( |
|
400 | 400 | 'debug_style/' + t_path, self._get_template_context(c), |
|
401 | 401 | request=self.request) |
|
402 | 402 |
@@ -1,320 +1,348 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 | 23 | from rhodecode.tests import TestController |
|
24 | 24 | |
|
25 |
from rhodecode.model.db import |
|
|
26 | ChangesetComment, Notification, UserNotification) | |
|
25 | from rhodecode.model.db import ChangesetComment, Notification | |
|
27 | 26 | from rhodecode.model.meta import Session |
|
28 | 27 | from rhodecode.lib import helpers as h |
|
29 | 28 | |
|
30 | 29 | |
|
31 | 30 | def route_path(name, params=None, **kwargs): |
|
32 | 31 | import urllib |
|
33 | 32 | |
|
34 | 33 | base_url = { |
|
35 | 34 | 'repo_commit': '/{repo_name}/changeset/{commit_id}', |
|
36 | 35 | 'repo_commit_comment_create': '/{repo_name}/changeset/{commit_id}/comment/create', |
|
37 | 36 | 'repo_commit_comment_preview': '/{repo_name}/changeset/{commit_id}/comment/preview', |
|
38 | 37 | 'repo_commit_comment_delete': '/{repo_name}/changeset/{commit_id}/comment/{comment_id}/delete', |
|
39 | 38 | }[name].format(**kwargs) |
|
40 | 39 | |
|
41 | 40 | if params: |
|
42 | 41 | base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) |
|
43 | 42 | return base_url |
|
44 | 43 | |
|
45 | 44 | |
|
46 | 45 | @pytest.mark.backends("git", "hg", "svn") |
|
47 | 46 | class TestRepoCommitCommentsView(TestController): |
|
48 | 47 | |
|
49 | 48 | @pytest.fixture(autouse=True) |
|
50 | 49 | def prepare(self, request, baseapp): |
|
51 | 50 | for x in ChangesetComment.query().all(): |
|
52 | 51 | Session().delete(x) |
|
53 | 52 | Session().commit() |
|
54 | 53 | |
|
55 | 54 | for x in Notification.query().all(): |
|
56 | 55 | Session().delete(x) |
|
57 | 56 | Session().commit() |
|
58 | 57 | |
|
59 | 58 | request.addfinalizer(self.cleanup) |
|
60 | 59 | |
|
61 | 60 | def cleanup(self): |
|
62 | 61 | for x in ChangesetComment.query().all(): |
|
63 | 62 | Session().delete(x) |
|
64 | 63 | Session().commit() |
|
65 | 64 | |
|
66 | 65 | for x in Notification.query().all(): |
|
67 | 66 | Session().delete(x) |
|
68 | 67 | Session().commit() |
|
69 | 68 | |
|
70 | 69 | @pytest.mark.parametrize('comment_type', ChangesetComment.COMMENT_TYPES) |
|
71 | 70 | def test_create(self, comment_type, backend): |
|
72 | 71 | self.log_user() |
|
73 | 72 | commit = backend.repo.get_commit('300') |
|
74 | 73 | commit_id = commit.raw_id |
|
75 | 74 | text = u'CommentOnCommit' |
|
76 | 75 | |
|
77 | 76 | params = {'text': text, 'csrf_token': self.csrf_token, |
|
78 | 77 | 'comment_type': comment_type} |
|
79 | 78 | self.app.post( |
|
80 | 79 | route_path('repo_commit_comment_create', |
|
81 | 80 | repo_name=backend.repo_name, commit_id=commit_id), |
|
82 | 81 | params=params) |
|
83 | 82 | |
|
84 | 83 | response = self.app.get( |
|
85 | 84 | route_path('repo_commit', |
|
86 | 85 | repo_name=backend.repo_name, commit_id=commit_id)) |
|
87 | 86 | |
|
88 | 87 | # test DB |
|
89 | 88 | assert ChangesetComment.query().count() == 1 |
|
90 | 89 | assert_comment_links(response, ChangesetComment.query().count(), 0) |
|
91 | 90 | |
|
92 | 91 | assert Notification.query().count() == 1 |
|
93 | 92 | assert ChangesetComment.query().count() == 1 |
|
94 | 93 | |
|
95 | 94 | notification = Notification.query().all()[0] |
|
96 | 95 | |
|
97 | 96 | comment_id = ChangesetComment.query().first().comment_id |
|
98 | 97 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT |
|
99 | 98 | |
|
100 | 99 | author = notification.created_by_user.username_and_name |
|
101 | 100 | sbj = '@{0} left a {1} on commit `{2}` in the `{3}` repository'.format( |
|
102 | 101 | author, comment_type, h.show_id(commit), backend.repo_name) |
|
103 | 102 | assert sbj == notification.subject |
|
104 | 103 | |
|
105 | 104 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( |
|
106 | 105 | backend.repo_name, commit_id, comment_id)) |
|
107 | 106 | assert lnk in notification.body |
|
108 | 107 | |
|
109 | 108 | @pytest.mark.parametrize('comment_type', ChangesetComment.COMMENT_TYPES) |
|
110 | 109 | def test_create_inline(self, comment_type, backend): |
|
111 | 110 | self.log_user() |
|
112 | 111 | commit = backend.repo.get_commit('300') |
|
113 | 112 | commit_id = commit.raw_id |
|
114 | 113 | text = u'CommentOnCommit' |
|
115 | 114 | f_path = 'vcs/web/simplevcs/views/repository.py' |
|
116 | 115 | line = 'n1' |
|
117 | 116 | |
|
118 | 117 | params = {'text': text, 'f_path': f_path, 'line': line, |
|
119 | 118 | 'comment_type': comment_type, |
|
120 | 119 | 'csrf_token': self.csrf_token} |
|
121 | 120 | |
|
122 | 121 | self.app.post( |
|
123 | 122 | route_path('repo_commit_comment_create', |
|
124 | 123 | repo_name=backend.repo_name, commit_id=commit_id), |
|
125 | 124 | params=params) |
|
126 | 125 | |
|
127 | 126 | response = self.app.get( |
|
128 | 127 | route_path('repo_commit', |
|
129 | 128 | repo_name=backend.repo_name, commit_id=commit_id)) |
|
130 | 129 | |
|
131 | 130 | # test DB |
|
132 | 131 | assert ChangesetComment.query().count() == 1 |
|
133 | 132 | assert_comment_links(response, 0, ChangesetComment.query().count()) |
|
134 | 133 | |
|
135 | 134 | if backend.alias == 'svn': |
|
136 | 135 | response.mustcontain( |
|
137 | 136 | '''data-f-path="vcs/commands/summary.py" ''' |
|
138 | 137 | '''data-anchor-id="c-300-ad05457a43f8"''' |
|
139 | 138 | ) |
|
140 | 139 | if backend.alias == 'git': |
|
141 | 140 | response.mustcontain( |
|
142 | 141 | '''data-f-path="vcs/backends/hg.py" ''' |
|
143 | 142 | '''data-anchor-id="c-883e775e89ea-9c390eb52cd6"''' |
|
144 | 143 | ) |
|
145 | 144 | |
|
146 | 145 | if backend.alias == 'hg': |
|
147 | 146 | response.mustcontain( |
|
148 | 147 | '''data-f-path="vcs/backends/hg.py" ''' |
|
149 | 148 | '''data-anchor-id="c-e58d85a3973b-9c390eb52cd6"''' |
|
150 | 149 | ) |
|
151 | 150 | |
|
152 | 151 | assert Notification.query().count() == 1 |
|
153 | 152 | assert ChangesetComment.query().count() == 1 |
|
154 | 153 | |
|
155 | 154 | notification = Notification.query().all()[0] |
|
156 | 155 | comment = ChangesetComment.query().first() |
|
157 | 156 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT |
|
158 | 157 | |
|
159 | 158 | assert comment.revision == commit_id |
|
160 | 159 | |
|
161 | 160 | author = notification.created_by_user.username_and_name |
|
162 | 161 | sbj = '@{0} left a {1} on file `{2}` in commit `{3}` in the `{4}` repository'.format( |
|
163 | 162 | author, comment_type, f_path, h.show_id(commit), backend.repo_name) |
|
164 | 163 | |
|
165 | 164 | assert sbj == notification.subject |
|
166 | 165 | |
|
167 | 166 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( |
|
168 | 167 | backend.repo_name, commit_id, comment.comment_id)) |
|
169 | 168 | assert lnk in notification.body |
|
170 | 169 | assert 'on line n1' in notification.body |
|
171 | 170 | |
|
172 | 171 | def test_create_with_mention(self, backend): |
|
173 | 172 | self.log_user() |
|
174 | 173 | |
|
175 | 174 | commit_id = backend.repo.get_commit('300').raw_id |
|
176 | 175 | text = u'@test_regular check CommentOnCommit' |
|
177 | 176 | |
|
178 | 177 | params = {'text': text, 'csrf_token': self.csrf_token} |
|
179 | 178 | self.app.post( |
|
180 | 179 | route_path('repo_commit_comment_create', |
|
181 | 180 | repo_name=backend.repo_name, commit_id=commit_id), |
|
182 | 181 | params=params) |
|
183 | 182 | |
|
184 | 183 | response = self.app.get( |
|
185 | 184 | route_path('repo_commit', |
|
186 | 185 | repo_name=backend.repo_name, commit_id=commit_id)) |
|
187 | 186 | # test DB |
|
188 | 187 | assert ChangesetComment.query().count() == 1 |
|
189 | 188 | assert_comment_links(response, ChangesetComment.query().count(), 0) |
|
190 | 189 | |
|
191 | 190 | notification = Notification.query().one() |
|
192 | 191 | |
|
193 | 192 | assert len(notification.recipients) == 2 |
|
194 | 193 | users = [x.username for x in notification.recipients] |
|
195 | 194 | |
|
196 | 195 | # test_regular gets notification by @mention |
|
197 | 196 | assert sorted(users) == [u'test_admin', u'test_regular'] |
|
198 | 197 | |
|
199 | 198 | def test_create_with_status_change(self, backend): |
|
200 | 199 | self.log_user() |
|
201 | 200 | commit = backend.repo.get_commit('300') |
|
202 | 201 | commit_id = commit.raw_id |
|
203 | 202 | text = u'CommentOnCommit' |
|
204 | 203 | f_path = 'vcs/web/simplevcs/views/repository.py' |
|
205 | 204 | line = 'n1' |
|
206 | 205 | |
|
207 | 206 | params = {'text': text, 'changeset_status': 'approved', |
|
208 | 207 | 'csrf_token': self.csrf_token} |
|
209 | 208 | |
|
210 | 209 | self.app.post( |
|
211 | 210 | route_path( |
|
212 | 211 | 'repo_commit_comment_create', |
|
213 | 212 | repo_name=backend.repo_name, commit_id=commit_id), |
|
214 | 213 | params=params) |
|
215 | 214 | |
|
216 | 215 | response = self.app.get( |
|
217 | 216 | route_path('repo_commit', |
|
218 | 217 | repo_name=backend.repo_name, commit_id=commit_id)) |
|
219 | 218 | |
|
220 | 219 | # test DB |
|
221 | 220 | assert ChangesetComment.query().count() == 1 |
|
222 | 221 | assert_comment_links(response, ChangesetComment.query().count(), 0) |
|
223 | 222 | |
|
224 | 223 | assert Notification.query().count() == 1 |
|
225 | 224 | assert ChangesetComment.query().count() == 1 |
|
226 | 225 | |
|
227 | 226 | notification = Notification.query().all()[0] |
|
228 | 227 | |
|
229 | 228 | comment_id = ChangesetComment.query().first().comment_id |
|
230 | 229 | assert notification.type_ == Notification.TYPE_CHANGESET_COMMENT |
|
231 | 230 | |
|
232 | 231 | author = notification.created_by_user.username_and_name |
|
233 | 232 | sbj = '[status: Approved] @{0} left a note on commit `{1}` in the `{2}` repository'.format( |
|
234 | 233 | author, h.show_id(commit), backend.repo_name) |
|
235 | 234 | assert sbj == notification.subject |
|
236 | 235 | |
|
237 | 236 | lnk = (u'/{0}/changeset/{1}#comment-{2}'.format( |
|
238 | 237 | backend.repo_name, commit_id, comment_id)) |
|
239 | 238 | assert lnk in notification.body |
|
240 | 239 | |
|
241 | 240 | def test_delete(self, backend): |
|
242 | 241 | self.log_user() |
|
243 | 242 | commit_id = backend.repo.get_commit('300').raw_id |
|
244 | 243 | text = u'CommentOnCommit' |
|
245 | 244 | |
|
246 | 245 | params = {'text': text, 'csrf_token': self.csrf_token} |
|
247 | 246 | self.app.post( |
|
248 | 247 | route_path( |
|
249 | 248 | 'repo_commit_comment_create', |
|
250 | 249 | repo_name=backend.repo_name, commit_id=commit_id), |
|
251 | 250 | params=params) |
|
252 | 251 | |
|
253 | 252 | comments = ChangesetComment.query().all() |
|
254 | 253 | assert len(comments) == 1 |
|
255 | 254 | comment_id = comments[0].comment_id |
|
256 | 255 | |
|
257 | 256 | self.app.post( |
|
258 | 257 | route_path('repo_commit_comment_delete', |
|
259 | 258 | repo_name=backend.repo_name, |
|
260 | 259 | commit_id=commit_id, |
|
261 | 260 | comment_id=comment_id), |
|
262 | 261 | params={'csrf_token': self.csrf_token}) |
|
263 | 262 | |
|
264 | 263 | comments = ChangesetComment.query().all() |
|
265 | 264 | assert len(comments) == 0 |
|
266 | 265 | |
|
267 | 266 | response = self.app.get( |
|
268 | 267 | route_path('repo_commit', |
|
269 | 268 | repo_name=backend.repo_name, commit_id=commit_id)) |
|
270 | 269 | assert_comment_links(response, 0, 0) |
|
271 | 270 | |
|
272 | @pytest.mark.parametrize('renderer, input, output', [ | |
|
271 | def test_delete_forbidden_for_immutable_comments(self, backend): | |
|
272 | self.log_user() | |
|
273 | commit_id = backend.repo.get_commit('300').raw_id | |
|
274 | text = u'CommentOnCommit' | |
|
275 | ||
|
276 | params = {'text': text, 'csrf_token': self.csrf_token} | |
|
277 | self.app.post( | |
|
278 | route_path( | |
|
279 | 'repo_commit_comment_create', | |
|
280 | repo_name=backend.repo_name, commit_id=commit_id), | |
|
281 | params=params) | |
|
282 | ||
|
283 | comments = ChangesetComment.query().all() | |
|
284 | assert len(comments) == 1 | |
|
285 | comment_id = comments[0].comment_id | |
|
286 | ||
|
287 | comment = ChangesetComment.get(comment_id) | |
|
288 | comment.immutable_state = ChangesetComment.OP_IMMUTABLE | |
|
289 | Session().add(comment) | |
|
290 | Session().commit() | |
|
291 | ||
|
292 | self.app.post( | |
|
293 | route_path('repo_commit_comment_delete', | |
|
294 | repo_name=backend.repo_name, | |
|
295 | commit_id=commit_id, | |
|
296 | comment_id=comment_id), | |
|
297 | params={'csrf_token': self.csrf_token}, | |
|
298 | status=403) | |
|
299 | ||
|
300 | @pytest.mark.parametrize('renderer, text_input, output', [ | |
|
273 | 301 | ('rst', 'plain text', '<p>plain text</p>'), |
|
274 | 302 | ('rst', 'header\n======', '<h1 class="title">header</h1>'), |
|
275 | 303 | ('rst', '*italics*', '<em>italics</em>'), |
|
276 | 304 | ('rst', '**bold**', '<strong>bold</strong>'), |
|
277 | 305 | ('markdown', 'plain text', '<p>plain text</p>'), |
|
278 | 306 | ('markdown', '# header', '<h1>header</h1>'), |
|
279 | 307 | ('markdown', '*italics*', '<em>italics</em>'), |
|
280 | 308 | ('markdown', '**bold**', '<strong>bold</strong>'), |
|
281 | 309 | ], ids=['rst-plain', 'rst-header', 'rst-italics', 'rst-bold', 'md-plain', |
|
282 | 310 | 'md-header', 'md-italics', 'md-bold', ]) |
|
283 | def test_preview(self, renderer, input, output, backend, xhr_header): | |
|
311 | def test_preview(self, renderer, text_input, output, backend, xhr_header): | |
|
284 | 312 | self.log_user() |
|
285 | 313 | params = { |
|
286 | 314 | 'renderer': renderer, |
|
287 | 'text': input, | |
|
315 | 'text': text_input, | |
|
288 | 316 | 'csrf_token': self.csrf_token |
|
289 | 317 | } |
|
290 | 318 | commit_id = '0' * 16 # fake this for tests |
|
291 | 319 | response = self.app.post( |
|
292 | 320 | route_path('repo_commit_comment_preview', |
|
293 | 321 | repo_name=backend.repo_name, commit_id=commit_id,), |
|
294 | 322 | params=params, |
|
295 | 323 | extra_environ=xhr_header) |
|
296 | 324 | |
|
297 | 325 | response.mustcontain(output) |
|
298 | 326 | |
|
299 | 327 | |
|
300 | 328 | def assert_comment_links(response, comments, inline_comments): |
|
301 | 329 | if comments == 1: |
|
302 | 330 | comments_text = "%d General" % comments |
|
303 | 331 | else: |
|
304 | 332 | comments_text = "%d General" % comments |
|
305 | 333 | |
|
306 | 334 | if inline_comments == 1: |
|
307 | 335 | inline_comments_text = "%d Inline" % inline_comments |
|
308 | 336 | else: |
|
309 | 337 | inline_comments_text = "%d Inline" % inline_comments |
|
310 | 338 | |
|
311 | 339 | if comments: |
|
312 | 340 | response.mustcontain('<a href="#comments">%s</a>,' % comments_text) |
|
313 | 341 | else: |
|
314 | 342 | response.mustcontain(comments_text) |
|
315 | 343 | |
|
316 | 344 | if inline_comments: |
|
317 | 345 | response.mustcontain( |
|
318 | 346 | 'id="inline-comments-counter">%s' % inline_comments_text) |
|
319 | 347 | else: |
|
320 | 348 | response.mustcontain(inline_comments_text) |
@@ -1,606 +1,610 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | import logging |
|
23 | 23 | import collections |
|
24 | 24 | |
|
25 | from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest, HTTPFound | |
|
25 | from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest, HTTPFound, HTTPForbidden | |
|
26 | 26 | from pyramid.view import view_config |
|
27 | 27 | from pyramid.renderers import render |
|
28 | 28 | from pyramid.response import Response |
|
29 | 29 | |
|
30 | 30 | from rhodecode.apps._base import RepoAppView |
|
31 | 31 | from rhodecode.apps.file_store import utils as store_utils |
|
32 | 32 | from rhodecode.apps.file_store.exceptions import FileNotAllowedException, FileOverSizeException |
|
33 | 33 | |
|
34 | 34 | from rhodecode.lib import diffs, codeblocks |
|
35 | 35 | from rhodecode.lib.auth import ( |
|
36 | 36 | LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous, CSRFRequired) |
|
37 | 37 | |
|
38 | 38 | from rhodecode.lib.compat import OrderedDict |
|
39 | 39 | from rhodecode.lib.diffs import ( |
|
40 | 40 | cache_diff, load_cached_diff, diff_cache_exist, get_diff_context, |
|
41 | 41 | get_diff_whitespace_flag) |
|
42 | 42 | from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError |
|
43 | 43 | import rhodecode.lib.helpers as h |
|
44 | 44 | from rhodecode.lib.utils2 import safe_unicode, str2bool |
|
45 | 45 | from rhodecode.lib.vcs.backends.base import EmptyCommit |
|
46 | 46 | from rhodecode.lib.vcs.exceptions import ( |
|
47 | 47 | RepositoryError, CommitDoesNotExistError) |
|
48 | 48 | from rhodecode.model.db import ChangesetComment, ChangesetStatus, FileStore |
|
49 | 49 | from rhodecode.model.changeset_status import ChangesetStatusModel |
|
50 | 50 | from rhodecode.model.comment import CommentsModel |
|
51 | 51 | from rhodecode.model.meta import Session |
|
52 | 52 | from rhodecode.model.settings import VcsSettingsModel |
|
53 | 53 | |
|
54 | 54 | log = logging.getLogger(__name__) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | def _update_with_GET(params, request): |
|
58 | 58 | for k in ['diff1', 'diff2', 'diff']: |
|
59 | 59 | params[k] += request.GET.getall(k) |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | class RepoCommitsView(RepoAppView): |
|
63 | 63 | def load_default_context(self): |
|
64 | 64 | c = self._get_local_tmpl_context(include_app_defaults=True) |
|
65 | 65 | c.rhodecode_repo = self.rhodecode_vcs_repo |
|
66 | 66 | |
|
67 | 67 | return c |
|
68 | 68 | |
|
69 | 69 | def _is_diff_cache_enabled(self, target_repo): |
|
70 | 70 | caching_enabled = self._get_general_setting( |
|
71 | 71 | target_repo, 'rhodecode_diff_cache') |
|
72 | 72 | log.debug('Diff caching enabled: %s', caching_enabled) |
|
73 | 73 | return caching_enabled |
|
74 | 74 | |
|
75 | 75 | def _commit(self, commit_id_range, method): |
|
76 | 76 | _ = self.request.translate |
|
77 | 77 | c = self.load_default_context() |
|
78 | 78 | c.fulldiff = self.request.GET.get('fulldiff') |
|
79 | 79 | |
|
80 | 80 | # fetch global flags of ignore ws or context lines |
|
81 | 81 | diff_context = get_diff_context(self.request) |
|
82 | 82 | hide_whitespace_changes = get_diff_whitespace_flag(self.request) |
|
83 | 83 | |
|
84 | 84 | # diff_limit will cut off the whole diff if the limit is applied |
|
85 | 85 | # otherwise it will just hide the big files from the front-end |
|
86 | 86 | diff_limit = c.visual.cut_off_limit_diff |
|
87 | 87 | file_limit = c.visual.cut_off_limit_file |
|
88 | 88 | |
|
89 | 89 | # get ranges of commit ids if preset |
|
90 | 90 | commit_range = commit_id_range.split('...')[:2] |
|
91 | 91 | |
|
92 | 92 | try: |
|
93 | 93 | pre_load = ['affected_files', 'author', 'branch', 'date', |
|
94 | 94 | 'message', 'parents'] |
|
95 | 95 | if self.rhodecode_vcs_repo.alias == 'hg': |
|
96 | 96 | pre_load += ['hidden', 'obsolete', 'phase'] |
|
97 | 97 | |
|
98 | 98 | if len(commit_range) == 2: |
|
99 | 99 | commits = self.rhodecode_vcs_repo.get_commits( |
|
100 | 100 | start_id=commit_range[0], end_id=commit_range[1], |
|
101 | 101 | pre_load=pre_load, translate_tags=False) |
|
102 | 102 | commits = list(commits) |
|
103 | 103 | else: |
|
104 | 104 | commits = [self.rhodecode_vcs_repo.get_commit( |
|
105 | 105 | commit_id=commit_id_range, pre_load=pre_load)] |
|
106 | 106 | |
|
107 | 107 | c.commit_ranges = commits |
|
108 | 108 | if not c.commit_ranges: |
|
109 | 109 | raise RepositoryError('The commit range returned an empty result') |
|
110 | 110 | except CommitDoesNotExistError as e: |
|
111 | 111 | msg = _('No such commit exists. Org exception: `{}`').format(e) |
|
112 | 112 | h.flash(msg, category='error') |
|
113 | 113 | raise HTTPNotFound() |
|
114 | 114 | except Exception: |
|
115 | 115 | log.exception("General failure") |
|
116 | 116 | raise HTTPNotFound() |
|
117 | 117 | |
|
118 | 118 | c.changes = OrderedDict() |
|
119 | 119 | c.lines_added = 0 |
|
120 | 120 | c.lines_deleted = 0 |
|
121 | 121 | |
|
122 | 122 | # auto collapse if we have more than limit |
|
123 | 123 | collapse_limit = diffs.DiffProcessor._collapse_commits_over |
|
124 | 124 | c.collapse_all_commits = len(c.commit_ranges) > collapse_limit |
|
125 | 125 | |
|
126 | 126 | c.commit_statuses = ChangesetStatus.STATUSES |
|
127 | 127 | c.inline_comments = [] |
|
128 | 128 | c.files = [] |
|
129 | 129 | |
|
130 | 130 | c.statuses = [] |
|
131 | 131 | c.comments = [] |
|
132 | 132 | c.unresolved_comments = [] |
|
133 | 133 | c.resolved_comments = [] |
|
134 | 134 | if len(c.commit_ranges) == 1: |
|
135 | 135 | commit = c.commit_ranges[0] |
|
136 | 136 | c.comments = CommentsModel().get_comments( |
|
137 | 137 | self.db_repo.repo_id, |
|
138 | 138 | revision=commit.raw_id) |
|
139 | 139 | c.statuses.append(ChangesetStatusModel().get_status( |
|
140 | 140 | self.db_repo.repo_id, commit.raw_id)) |
|
141 | 141 | # comments from PR |
|
142 | 142 | statuses = ChangesetStatusModel().get_statuses( |
|
143 | 143 | self.db_repo.repo_id, commit.raw_id, |
|
144 | 144 | with_revisions=True) |
|
145 | 145 | prs = set(st.pull_request for st in statuses |
|
146 | 146 | if st.pull_request is not None) |
|
147 | 147 | # from associated statuses, check the pull requests, and |
|
148 | 148 | # show comments from them |
|
149 | 149 | for pr in prs: |
|
150 | 150 | c.comments.extend(pr.comments) |
|
151 | 151 | |
|
152 | 152 | c.unresolved_comments = CommentsModel()\ |
|
153 | 153 | .get_commit_unresolved_todos(commit.raw_id) |
|
154 | 154 | c.resolved_comments = CommentsModel()\ |
|
155 | 155 | .get_commit_resolved_todos(commit.raw_id) |
|
156 | 156 | |
|
157 | 157 | diff = None |
|
158 | 158 | # Iterate over ranges (default commit view is always one commit) |
|
159 | 159 | for commit in c.commit_ranges: |
|
160 | 160 | c.changes[commit.raw_id] = [] |
|
161 | 161 | |
|
162 | 162 | commit2 = commit |
|
163 | 163 | commit1 = commit.first_parent |
|
164 | 164 | |
|
165 | 165 | if method == 'show': |
|
166 | 166 | inline_comments = CommentsModel().get_inline_comments( |
|
167 | 167 | self.db_repo.repo_id, revision=commit.raw_id) |
|
168 | 168 | c.inline_cnt = CommentsModel().get_inline_comments_count( |
|
169 | 169 | inline_comments) |
|
170 | 170 | c.inline_comments = inline_comments |
|
171 | 171 | |
|
172 | 172 | cache_path = self.rhodecode_vcs_repo.get_create_shadow_cache_pr_path( |
|
173 | 173 | self.db_repo) |
|
174 | 174 | cache_file_path = diff_cache_exist( |
|
175 | 175 | cache_path, 'diff', commit.raw_id, |
|
176 | 176 | hide_whitespace_changes, diff_context, c.fulldiff) |
|
177 | 177 | |
|
178 | 178 | caching_enabled = self._is_diff_cache_enabled(self.db_repo) |
|
179 | 179 | force_recache = str2bool(self.request.GET.get('force_recache')) |
|
180 | 180 | |
|
181 | 181 | cached_diff = None |
|
182 | 182 | if caching_enabled: |
|
183 | 183 | cached_diff = load_cached_diff(cache_file_path) |
|
184 | 184 | |
|
185 | 185 | has_proper_diff_cache = cached_diff and cached_diff.get('diff') |
|
186 | 186 | if not force_recache and has_proper_diff_cache: |
|
187 | 187 | diffset = cached_diff['diff'] |
|
188 | 188 | else: |
|
189 | 189 | vcs_diff = self.rhodecode_vcs_repo.get_diff( |
|
190 | 190 | commit1, commit2, |
|
191 | 191 | ignore_whitespace=hide_whitespace_changes, |
|
192 | 192 | context=diff_context) |
|
193 | 193 | |
|
194 | 194 | diff_processor = diffs.DiffProcessor( |
|
195 | 195 | vcs_diff, format='newdiff', diff_limit=diff_limit, |
|
196 | 196 | file_limit=file_limit, show_full_diff=c.fulldiff) |
|
197 | 197 | |
|
198 | 198 | _parsed = diff_processor.prepare() |
|
199 | 199 | |
|
200 | 200 | diffset = codeblocks.DiffSet( |
|
201 | 201 | repo_name=self.db_repo_name, |
|
202 | 202 | source_node_getter=codeblocks.diffset_node_getter(commit1), |
|
203 | 203 | target_node_getter=codeblocks.diffset_node_getter(commit2)) |
|
204 | 204 | |
|
205 | 205 | diffset = self.path_filter.render_patchset_filtered( |
|
206 | 206 | diffset, _parsed, commit1.raw_id, commit2.raw_id) |
|
207 | 207 | |
|
208 | 208 | # save cached diff |
|
209 | 209 | if caching_enabled: |
|
210 | 210 | cache_diff(cache_file_path, diffset, None) |
|
211 | 211 | |
|
212 | 212 | c.limited_diff = diffset.limited_diff |
|
213 | 213 | c.changes[commit.raw_id] = diffset |
|
214 | 214 | else: |
|
215 | 215 | # TODO(marcink): no cache usage here... |
|
216 | 216 | _diff = self.rhodecode_vcs_repo.get_diff( |
|
217 | 217 | commit1, commit2, |
|
218 | 218 | ignore_whitespace=hide_whitespace_changes, context=diff_context) |
|
219 | 219 | diff_processor = diffs.DiffProcessor( |
|
220 | 220 | _diff, format='newdiff', diff_limit=diff_limit, |
|
221 | 221 | file_limit=file_limit, show_full_diff=c.fulldiff) |
|
222 | 222 | # downloads/raw we only need RAW diff nothing else |
|
223 | 223 | diff = self.path_filter.get_raw_patch(diff_processor) |
|
224 | 224 | c.changes[commit.raw_id] = [None, None, None, None, diff, None, None] |
|
225 | 225 | |
|
226 | 226 | # sort comments by how they were generated |
|
227 | 227 | c.comments = sorted(c.comments, key=lambda x: x.comment_id) |
|
228 | 228 | |
|
229 | 229 | if len(c.commit_ranges) == 1: |
|
230 | 230 | c.commit = c.commit_ranges[0] |
|
231 | 231 | c.parent_tmpl = ''.join( |
|
232 | 232 | '# Parent %s\n' % x.raw_id for x in c.commit.parents) |
|
233 | 233 | |
|
234 | 234 | if method == 'download': |
|
235 | 235 | response = Response(diff) |
|
236 | 236 | response.content_type = 'text/plain' |
|
237 | 237 | response.content_disposition = ( |
|
238 | 238 | 'attachment; filename=%s.diff' % commit_id_range[:12]) |
|
239 | 239 | return response |
|
240 | 240 | elif method == 'patch': |
|
241 | 241 | c.diff = safe_unicode(diff) |
|
242 | 242 | patch = render( |
|
243 | 243 | 'rhodecode:templates/changeset/patch_changeset.mako', |
|
244 | 244 | self._get_template_context(c), self.request) |
|
245 | 245 | response = Response(patch) |
|
246 | 246 | response.content_type = 'text/plain' |
|
247 | 247 | return response |
|
248 | 248 | elif method == 'raw': |
|
249 | 249 | response = Response(diff) |
|
250 | 250 | response.content_type = 'text/plain' |
|
251 | 251 | return response |
|
252 | 252 | elif method == 'show': |
|
253 | 253 | if len(c.commit_ranges) == 1: |
|
254 | 254 | html = render( |
|
255 | 255 | 'rhodecode:templates/changeset/changeset.mako', |
|
256 | 256 | self._get_template_context(c), self.request) |
|
257 | 257 | return Response(html) |
|
258 | 258 | else: |
|
259 | 259 | c.ancestor = None |
|
260 | 260 | c.target_repo = self.db_repo |
|
261 | 261 | html = render( |
|
262 | 262 | 'rhodecode:templates/changeset/changeset_range.mako', |
|
263 | 263 | self._get_template_context(c), self.request) |
|
264 | 264 | return Response(html) |
|
265 | 265 | |
|
266 | 266 | raise HTTPBadRequest() |
|
267 | 267 | |
|
268 | 268 | @LoginRequired() |
|
269 | 269 | @HasRepoPermissionAnyDecorator( |
|
270 | 270 | 'repository.read', 'repository.write', 'repository.admin') |
|
271 | 271 | @view_config( |
|
272 | 272 | route_name='repo_commit', request_method='GET', |
|
273 | 273 | renderer=None) |
|
274 | 274 | def repo_commit_show(self): |
|
275 | 275 | commit_id = self.request.matchdict['commit_id'] |
|
276 | 276 | return self._commit(commit_id, method='show') |
|
277 | 277 | |
|
278 | 278 | @LoginRequired() |
|
279 | 279 | @HasRepoPermissionAnyDecorator( |
|
280 | 280 | 'repository.read', 'repository.write', 'repository.admin') |
|
281 | 281 | @view_config( |
|
282 | 282 | route_name='repo_commit_raw', request_method='GET', |
|
283 | 283 | renderer=None) |
|
284 | 284 | @view_config( |
|
285 | 285 | route_name='repo_commit_raw_deprecated', request_method='GET', |
|
286 | 286 | renderer=None) |
|
287 | 287 | def repo_commit_raw(self): |
|
288 | 288 | commit_id = self.request.matchdict['commit_id'] |
|
289 | 289 | return self._commit(commit_id, method='raw') |
|
290 | 290 | |
|
291 | 291 | @LoginRequired() |
|
292 | 292 | @HasRepoPermissionAnyDecorator( |
|
293 | 293 | 'repository.read', 'repository.write', 'repository.admin') |
|
294 | 294 | @view_config( |
|
295 | 295 | route_name='repo_commit_patch', request_method='GET', |
|
296 | 296 | renderer=None) |
|
297 | 297 | def repo_commit_patch(self): |
|
298 | 298 | commit_id = self.request.matchdict['commit_id'] |
|
299 | 299 | return self._commit(commit_id, method='patch') |
|
300 | 300 | |
|
301 | 301 | @LoginRequired() |
|
302 | 302 | @HasRepoPermissionAnyDecorator( |
|
303 | 303 | 'repository.read', 'repository.write', 'repository.admin') |
|
304 | 304 | @view_config( |
|
305 | 305 | route_name='repo_commit_download', request_method='GET', |
|
306 | 306 | renderer=None) |
|
307 | 307 | def repo_commit_download(self): |
|
308 | 308 | commit_id = self.request.matchdict['commit_id'] |
|
309 | 309 | return self._commit(commit_id, method='download') |
|
310 | 310 | |
|
311 | 311 | @LoginRequired() |
|
312 | 312 | @NotAnonymous() |
|
313 | 313 | @HasRepoPermissionAnyDecorator( |
|
314 | 314 | 'repository.read', 'repository.write', 'repository.admin') |
|
315 | 315 | @CSRFRequired() |
|
316 | 316 | @view_config( |
|
317 | 317 | route_name='repo_commit_comment_create', request_method='POST', |
|
318 | 318 | renderer='json_ext') |
|
319 | 319 | def repo_commit_comment_create(self): |
|
320 | 320 | _ = self.request.translate |
|
321 | 321 | commit_id = self.request.matchdict['commit_id'] |
|
322 | 322 | |
|
323 | 323 | c = self.load_default_context() |
|
324 | 324 | status = self.request.POST.get('changeset_status', None) |
|
325 | 325 | text = self.request.POST.get('text') |
|
326 | 326 | comment_type = self.request.POST.get('comment_type') |
|
327 | 327 | resolves_comment_id = self.request.POST.get('resolves_comment_id', None) |
|
328 | 328 | |
|
329 | 329 | if status: |
|
330 | 330 | text = text or (_('Status change %(transition_icon)s %(status)s') |
|
331 | 331 | % {'transition_icon': '>', |
|
332 | 332 | 'status': ChangesetStatus.get_status_lbl(status)}) |
|
333 | 333 | |
|
334 | 334 | multi_commit_ids = [] |
|
335 | 335 | for _commit_id in self.request.POST.get('commit_ids', '').split(','): |
|
336 | 336 | if _commit_id not in ['', None, EmptyCommit.raw_id]: |
|
337 | 337 | if _commit_id not in multi_commit_ids: |
|
338 | 338 | multi_commit_ids.append(_commit_id) |
|
339 | 339 | |
|
340 | 340 | commit_ids = multi_commit_ids or [commit_id] |
|
341 | 341 | |
|
342 | 342 | comment = None |
|
343 | 343 | for current_id in filter(None, commit_ids): |
|
344 | 344 | comment = CommentsModel().create( |
|
345 | 345 | text=text, |
|
346 | 346 | repo=self.db_repo.repo_id, |
|
347 | 347 | user=self._rhodecode_db_user.user_id, |
|
348 | 348 | commit_id=current_id, |
|
349 | 349 | f_path=self.request.POST.get('f_path'), |
|
350 | 350 | line_no=self.request.POST.get('line'), |
|
351 | 351 | status_change=(ChangesetStatus.get_status_lbl(status) |
|
352 | 352 | if status else None), |
|
353 | 353 | status_change_type=status, |
|
354 | 354 | comment_type=comment_type, |
|
355 | 355 | resolves_comment_id=resolves_comment_id, |
|
356 | 356 | auth_user=self._rhodecode_user |
|
357 | 357 | ) |
|
358 | 358 | |
|
359 | 359 | # get status if set ! |
|
360 | 360 | if status: |
|
361 | 361 | # if latest status was from pull request and it's closed |
|
362 | 362 | # disallow changing status ! |
|
363 | 363 | # dont_allow_on_closed_pull_request = True ! |
|
364 | 364 | |
|
365 | 365 | try: |
|
366 | 366 | ChangesetStatusModel().set_status( |
|
367 | 367 | self.db_repo.repo_id, |
|
368 | 368 | status, |
|
369 | 369 | self._rhodecode_db_user.user_id, |
|
370 | 370 | comment, |
|
371 | 371 | revision=current_id, |
|
372 | 372 | dont_allow_on_closed_pull_request=True |
|
373 | 373 | ) |
|
374 | 374 | except StatusChangeOnClosedPullRequestError: |
|
375 | 375 | msg = _('Changing the status of a commit associated with ' |
|
376 | 376 | 'a closed pull request is not allowed') |
|
377 | 377 | log.exception(msg) |
|
378 | 378 | h.flash(msg, category='warning') |
|
379 | 379 | raise HTTPFound(h.route_path( |
|
380 | 380 | 'repo_commit', repo_name=self.db_repo_name, |
|
381 | 381 | commit_id=current_id)) |
|
382 | 382 | |
|
383 | 383 | commit = self.db_repo.get_commit(current_id) |
|
384 | 384 | CommentsModel().trigger_commit_comment_hook( |
|
385 | 385 | self.db_repo, self._rhodecode_user, 'create', |
|
386 | 386 | data={'comment': comment, 'commit': commit}) |
|
387 | 387 | |
|
388 | 388 | # finalize, commit and redirect |
|
389 | 389 | Session().commit() |
|
390 | 390 | |
|
391 | 391 | data = { |
|
392 | 392 | 'target_id': h.safeid(h.safe_unicode( |
|
393 | 393 | self.request.POST.get('f_path'))), |
|
394 | 394 | } |
|
395 | 395 | if comment: |
|
396 | 396 | c.co = comment |
|
397 | 397 | rendered_comment = render( |
|
398 | 398 | 'rhodecode:templates/changeset/changeset_comment_block.mako', |
|
399 | 399 | self._get_template_context(c), self.request) |
|
400 | 400 | |
|
401 | 401 | data.update(comment.get_dict()) |
|
402 | 402 | data.update({'rendered_text': rendered_comment}) |
|
403 | 403 | |
|
404 | 404 | return data |
|
405 | 405 | |
|
406 | 406 | @LoginRequired() |
|
407 | 407 | @NotAnonymous() |
|
408 | 408 | @HasRepoPermissionAnyDecorator( |
|
409 | 409 | 'repository.read', 'repository.write', 'repository.admin') |
|
410 | 410 | @CSRFRequired() |
|
411 | 411 | @view_config( |
|
412 | 412 | route_name='repo_commit_comment_preview', request_method='POST', |
|
413 | 413 | renderer='string', xhr=True) |
|
414 | 414 | def repo_commit_comment_preview(self): |
|
415 | 415 | # Technically a CSRF token is not needed as no state changes with this |
|
416 | 416 | # call. However, as this is a POST is better to have it, so automated |
|
417 | 417 | # tools don't flag it as potential CSRF. |
|
418 | 418 | # Post is required because the payload could be bigger than the maximum |
|
419 | 419 | # allowed by GET. |
|
420 | 420 | |
|
421 | 421 | text = self.request.POST.get('text') |
|
422 | 422 | renderer = self.request.POST.get('renderer') or 'rst' |
|
423 | 423 | if text: |
|
424 | 424 | return h.render(text, renderer=renderer, mentions=True, |
|
425 | 425 | repo_name=self.db_repo_name) |
|
426 | 426 | return '' |
|
427 | 427 | |
|
428 | 428 | @LoginRequired() |
|
429 | 429 | @NotAnonymous() |
|
430 | 430 | @HasRepoPermissionAnyDecorator( |
|
431 | 431 | 'repository.read', 'repository.write', 'repository.admin') |
|
432 | 432 | @CSRFRequired() |
|
433 | 433 | @view_config( |
|
434 | 434 | route_name='repo_commit_comment_attachment_upload', request_method='POST', |
|
435 | 435 | renderer='json_ext', xhr=True) |
|
436 | 436 | def repo_commit_comment_attachment_upload(self): |
|
437 | 437 | c = self.load_default_context() |
|
438 | 438 | upload_key = 'attachment' |
|
439 | 439 | |
|
440 | 440 | file_obj = self.request.POST.get(upload_key) |
|
441 | 441 | |
|
442 | 442 | if file_obj is None: |
|
443 | 443 | self.request.response.status = 400 |
|
444 | 444 | return {'store_fid': None, |
|
445 | 445 | 'access_path': None, |
|
446 | 446 | 'error': '{} data field is missing'.format(upload_key)} |
|
447 | 447 | |
|
448 | 448 | if not hasattr(file_obj, 'filename'): |
|
449 | 449 | self.request.response.status = 400 |
|
450 | 450 | return {'store_fid': None, |
|
451 | 451 | 'access_path': None, |
|
452 | 452 | 'error': 'filename cannot be read from the data field'} |
|
453 | 453 | |
|
454 | 454 | filename = file_obj.filename |
|
455 | 455 | file_display_name = filename |
|
456 | 456 | |
|
457 | 457 | metadata = { |
|
458 | 458 | 'user_uploaded': {'username': self._rhodecode_user.username, |
|
459 | 459 | 'user_id': self._rhodecode_user.user_id, |
|
460 | 460 | 'ip': self._rhodecode_user.ip_addr}} |
|
461 | 461 | |
|
462 | 462 | # TODO(marcink): allow .ini configuration for allowed_extensions, and file-size |
|
463 | 463 | allowed_extensions = [ |
|
464 | 464 | 'gif', '.jpeg', '.jpg', '.png', '.docx', '.gz', '.log', '.pdf', |
|
465 | 465 | '.pptx', '.txt', '.xlsx', '.zip'] |
|
466 | 466 | max_file_size = 10 * 1024 * 1024 # 10MB, also validated via dropzone.js |
|
467 | 467 | |
|
468 | 468 | try: |
|
469 | 469 | storage = store_utils.get_file_storage(self.request.registry.settings) |
|
470 | 470 | store_uid, metadata = storage.save_file( |
|
471 | 471 | file_obj.file, filename, extra_metadata=metadata, |
|
472 | 472 | extensions=allowed_extensions, max_filesize=max_file_size) |
|
473 | 473 | except FileNotAllowedException: |
|
474 | 474 | self.request.response.status = 400 |
|
475 | 475 | permitted_extensions = ', '.join(allowed_extensions) |
|
476 | 476 | error_msg = 'File `{}` is not allowed. ' \ |
|
477 | 477 | 'Only following extensions are permitted: {}'.format( |
|
478 | 478 | filename, permitted_extensions) |
|
479 | 479 | return {'store_fid': None, |
|
480 | 480 | 'access_path': None, |
|
481 | 481 | 'error': error_msg} |
|
482 | 482 | except FileOverSizeException: |
|
483 | 483 | self.request.response.status = 400 |
|
484 | 484 | limit_mb = h.format_byte_size_binary(max_file_size) |
|
485 | 485 | return {'store_fid': None, |
|
486 | 486 | 'access_path': None, |
|
487 | 487 | 'error': 'File {} is exceeding allowed limit of {}.'.format( |
|
488 | 488 | filename, limit_mb)} |
|
489 | 489 | |
|
490 | 490 | try: |
|
491 | 491 | entry = FileStore.create( |
|
492 | 492 | file_uid=store_uid, filename=metadata["filename"], |
|
493 | 493 | file_hash=metadata["sha256"], file_size=metadata["size"], |
|
494 | 494 | file_display_name=file_display_name, |
|
495 | 495 | file_description=u'comment attachment `{}`'.format(safe_unicode(filename)), |
|
496 | 496 | hidden=True, check_acl=True, user_id=self._rhodecode_user.user_id, |
|
497 | 497 | scope_repo_id=self.db_repo.repo_id |
|
498 | 498 | ) |
|
499 | 499 | Session().add(entry) |
|
500 | 500 | Session().commit() |
|
501 | 501 | log.debug('Stored upload in DB as %s', entry) |
|
502 | 502 | except Exception: |
|
503 | 503 | log.exception('Failed to store file %s', filename) |
|
504 | 504 | self.request.response.status = 400 |
|
505 | 505 | return {'store_fid': None, |
|
506 | 506 | 'access_path': None, |
|
507 | 507 | 'error': 'File {} failed to store in DB.'.format(filename)} |
|
508 | 508 | |
|
509 | 509 | Session().commit() |
|
510 | 510 | |
|
511 | 511 | return { |
|
512 | 512 | 'store_fid': store_uid, |
|
513 | 513 | 'access_path': h.route_path( |
|
514 | 514 | 'download_file', fid=store_uid), |
|
515 | 515 | 'fqn_access_path': h.route_url( |
|
516 | 516 | 'download_file', fid=store_uid), |
|
517 | 517 | 'repo_access_path': h.route_path( |
|
518 | 518 | 'repo_artifacts_get', repo_name=self.db_repo_name, uid=store_uid), |
|
519 | 519 | 'repo_fqn_access_path': h.route_url( |
|
520 | 520 | 'repo_artifacts_get', repo_name=self.db_repo_name, uid=store_uid), |
|
521 | 521 | } |
|
522 | 522 | |
|
523 | 523 | @LoginRequired() |
|
524 | 524 | @NotAnonymous() |
|
525 | 525 | @HasRepoPermissionAnyDecorator( |
|
526 | 526 | 'repository.read', 'repository.write', 'repository.admin') |
|
527 | 527 | @CSRFRequired() |
|
528 | 528 | @view_config( |
|
529 | 529 | route_name='repo_commit_comment_delete', request_method='POST', |
|
530 | 530 | renderer='json_ext') |
|
531 | 531 | def repo_commit_comment_delete(self): |
|
532 | 532 | commit_id = self.request.matchdict['commit_id'] |
|
533 | 533 | comment_id = self.request.matchdict['comment_id'] |
|
534 | 534 | |
|
535 | 535 | comment = ChangesetComment.get_or_404(comment_id) |
|
536 | 536 | if not comment: |
|
537 | 537 | log.debug('Comment with id:%s not found, skipping', comment_id) |
|
538 | 538 | # comment already deleted in another call probably |
|
539 | 539 | return True |
|
540 | 540 | |
|
541 | if comment.immutable: | |
|
542 | # don't allow deleting comments that are immutable | |
|
543 | raise HTTPForbidden() | |
|
544 | ||
|
541 | 545 | is_repo_admin = h.HasRepoPermissionAny('repository.admin')(self.db_repo_name) |
|
542 | 546 | super_admin = h.HasPermissionAny('hg.admin')() |
|
543 | 547 | comment_owner = (comment.author.user_id == self._rhodecode_db_user.user_id) |
|
544 | 548 | is_repo_comment = comment.repo.repo_name == self.db_repo_name |
|
545 | 549 | comment_repo_admin = is_repo_admin and is_repo_comment |
|
546 | 550 | |
|
547 | 551 | if super_admin or comment_owner or comment_repo_admin: |
|
548 | 552 | CommentsModel().delete(comment=comment, auth_user=self._rhodecode_user) |
|
549 | 553 | Session().commit() |
|
550 | 554 | return True |
|
551 | 555 | else: |
|
552 | 556 | log.warning('No permissions for user %s to delete comment_id: %s', |
|
553 | 557 | self._rhodecode_db_user, comment_id) |
|
554 | 558 | raise HTTPNotFound() |
|
555 | 559 | |
|
556 | 560 | @LoginRequired() |
|
557 | 561 | @HasRepoPermissionAnyDecorator( |
|
558 | 562 | 'repository.read', 'repository.write', 'repository.admin') |
|
559 | 563 | @view_config( |
|
560 | 564 | route_name='repo_commit_data', request_method='GET', |
|
561 | 565 | renderer='json_ext', xhr=True) |
|
562 | 566 | def repo_commit_data(self): |
|
563 | 567 | commit_id = self.request.matchdict['commit_id'] |
|
564 | 568 | self.load_default_context() |
|
565 | 569 | |
|
566 | 570 | try: |
|
567 | 571 | return self.rhodecode_vcs_repo.get_commit(commit_id=commit_id) |
|
568 | 572 | except CommitDoesNotExistError as e: |
|
569 | 573 | return EmptyCommit(message=str(e)) |
|
570 | 574 | |
|
571 | 575 | @LoginRequired() |
|
572 | 576 | @HasRepoPermissionAnyDecorator( |
|
573 | 577 | 'repository.read', 'repository.write', 'repository.admin') |
|
574 | 578 | @view_config( |
|
575 | 579 | route_name='repo_commit_children', request_method='GET', |
|
576 | 580 | renderer='json_ext', xhr=True) |
|
577 | 581 | def repo_commit_children(self): |
|
578 | 582 | commit_id = self.request.matchdict['commit_id'] |
|
579 | 583 | self.load_default_context() |
|
580 | 584 | |
|
581 | 585 | try: |
|
582 | 586 | commit = self.rhodecode_vcs_repo.get_commit(commit_id=commit_id) |
|
583 | 587 | children = commit.children |
|
584 | 588 | except CommitDoesNotExistError: |
|
585 | 589 | children = [] |
|
586 | 590 | |
|
587 | 591 | result = {"results": children} |
|
588 | 592 | return result |
|
589 | 593 | |
|
590 | 594 | @LoginRequired() |
|
591 | 595 | @HasRepoPermissionAnyDecorator( |
|
592 | 596 | 'repository.read', 'repository.write', 'repository.admin') |
|
593 | 597 | @view_config( |
|
594 | 598 | route_name='repo_commit_parents', request_method='GET', |
|
595 | 599 | renderer='json_ext') |
|
596 | 600 | def repo_commit_parents(self): |
|
597 | 601 | commit_id = self.request.matchdict['commit_id'] |
|
598 | 602 | self.load_default_context() |
|
599 | 603 | |
|
600 | 604 | try: |
|
601 | 605 | commit = self.rhodecode_vcs_repo.get_commit(commit_id=commit_id) |
|
602 | 606 | parents = commit.parents |
|
603 | 607 | except CommitDoesNotExistError: |
|
604 | 608 | parents = [] |
|
605 | 609 | result = {"results": parents} |
|
606 | 610 | return result |
@@ -1,1508 +1,1512 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2020 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | import collections |
|
23 | 23 | |
|
24 | 24 | import formencode |
|
25 | 25 | import formencode.htmlfill |
|
26 | 26 | import peppercorn |
|
27 | 27 | from pyramid.httpexceptions import ( |
|
28 | 28 | HTTPFound, HTTPNotFound, HTTPForbidden, HTTPBadRequest) |
|
29 | 29 | from pyramid.view import view_config |
|
30 | 30 | from pyramid.renderers import render |
|
31 | 31 | |
|
32 | 32 | from rhodecode.apps._base import RepoAppView, DataGridAppView |
|
33 | 33 | |
|
34 | 34 | from rhodecode.lib import helpers as h, diffs, codeblocks, channelstream |
|
35 | 35 | from rhodecode.lib.base import vcs_operation_context |
|
36 | 36 | from rhodecode.lib.diffs import load_cached_diff, cache_diff, diff_cache_exist |
|
37 | 37 | from rhodecode.lib.ext_json import json |
|
38 | 38 | from rhodecode.lib.auth import ( |
|
39 | 39 | LoginRequired, HasRepoPermissionAny, HasRepoPermissionAnyDecorator, |
|
40 | 40 | NotAnonymous, CSRFRequired) |
|
41 | 41 | from rhodecode.lib.utils2 import str2bool, safe_str, safe_unicode |
|
42 | 42 | from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason |
|
43 | 43 | from rhodecode.lib.vcs.exceptions import (CommitDoesNotExistError, |
|
44 | 44 | RepositoryRequirementError, EmptyRepositoryError) |
|
45 | 45 | from rhodecode.model.changeset_status import ChangesetStatusModel |
|
46 | 46 | from rhodecode.model.comment import CommentsModel |
|
47 | 47 | from rhodecode.model.db import (func, or_, PullRequest, PullRequestVersion, |
|
48 | 48 | ChangesetComment, ChangesetStatus, Repository) |
|
49 | 49 | from rhodecode.model.forms import PullRequestForm |
|
50 | 50 | from rhodecode.model.meta import Session |
|
51 | 51 | from rhodecode.model.pull_request import PullRequestModel, MergeCheck |
|
52 | 52 | from rhodecode.model.scm import ScmModel |
|
53 | 53 | |
|
54 | 54 | log = logging.getLogger(__name__) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | class RepoPullRequestsView(RepoAppView, DataGridAppView): |
|
58 | 58 | |
|
59 | 59 | def load_default_context(self): |
|
60 | 60 | c = self._get_local_tmpl_context(include_app_defaults=True) |
|
61 | 61 | c.REVIEW_STATUS_APPROVED = ChangesetStatus.STATUS_APPROVED |
|
62 | 62 | c.REVIEW_STATUS_REJECTED = ChangesetStatus.STATUS_REJECTED |
|
63 | 63 | # backward compat., we use for OLD PRs a plain renderer |
|
64 | 64 | c.renderer = 'plain' |
|
65 | 65 | return c |
|
66 | 66 | |
|
67 | 67 | def _get_pull_requests_list( |
|
68 | 68 | self, repo_name, source, filter_type, opened_by, statuses): |
|
69 | 69 | |
|
70 | 70 | draw, start, limit = self._extract_chunk(self.request) |
|
71 | 71 | search_q, order_by, order_dir = self._extract_ordering(self.request) |
|
72 | 72 | _render = self.request.get_partial_renderer( |
|
73 | 73 | 'rhodecode:templates/data_table/_dt_elements.mako') |
|
74 | 74 | |
|
75 | 75 | # pagination |
|
76 | 76 | |
|
77 | 77 | if filter_type == 'awaiting_review': |
|
78 | 78 | pull_requests = PullRequestModel().get_awaiting_review( |
|
79 | 79 | repo_name, search_q=search_q, source=source, opened_by=opened_by, |
|
80 | 80 | statuses=statuses, offset=start, length=limit, |
|
81 | 81 | order_by=order_by, order_dir=order_dir) |
|
82 | 82 | pull_requests_total_count = PullRequestModel().count_awaiting_review( |
|
83 | 83 | repo_name, search_q=search_q, source=source, statuses=statuses, |
|
84 | 84 | opened_by=opened_by) |
|
85 | 85 | elif filter_type == 'awaiting_my_review': |
|
86 | 86 | pull_requests = PullRequestModel().get_awaiting_my_review( |
|
87 | 87 | repo_name, search_q=search_q, source=source, opened_by=opened_by, |
|
88 | 88 | user_id=self._rhodecode_user.user_id, statuses=statuses, |
|
89 | 89 | offset=start, length=limit, order_by=order_by, |
|
90 | 90 | order_dir=order_dir) |
|
91 | 91 | pull_requests_total_count = PullRequestModel().count_awaiting_my_review( |
|
92 | 92 | repo_name, search_q=search_q, source=source, user_id=self._rhodecode_user.user_id, |
|
93 | 93 | statuses=statuses, opened_by=opened_by) |
|
94 | 94 | else: |
|
95 | 95 | pull_requests = PullRequestModel().get_all( |
|
96 | 96 | repo_name, search_q=search_q, source=source, opened_by=opened_by, |
|
97 | 97 | statuses=statuses, offset=start, length=limit, |
|
98 | 98 | order_by=order_by, order_dir=order_dir) |
|
99 | 99 | pull_requests_total_count = PullRequestModel().count_all( |
|
100 | 100 | repo_name, search_q=search_q, source=source, statuses=statuses, |
|
101 | 101 | opened_by=opened_by) |
|
102 | 102 | |
|
103 | 103 | data = [] |
|
104 | 104 | comments_model = CommentsModel() |
|
105 | 105 | for pr in pull_requests: |
|
106 | 106 | comments = comments_model.get_all_comments( |
|
107 | 107 | self.db_repo.repo_id, pull_request=pr) |
|
108 | 108 | |
|
109 | 109 | data.append({ |
|
110 | 110 | 'name': _render('pullrequest_name', |
|
111 | 111 | pr.pull_request_id, pr.pull_request_state, |
|
112 | 112 | pr.work_in_progress, pr.target_repo.repo_name), |
|
113 | 113 | 'name_raw': pr.pull_request_id, |
|
114 | 114 | 'status': _render('pullrequest_status', |
|
115 | 115 | pr.calculated_review_status()), |
|
116 | 116 | 'title': _render('pullrequest_title', pr.title, pr.description), |
|
117 | 117 | 'description': h.escape(pr.description), |
|
118 | 118 | 'updated_on': _render('pullrequest_updated_on', |
|
119 | 119 | h.datetime_to_time(pr.updated_on)), |
|
120 | 120 | 'updated_on_raw': h.datetime_to_time(pr.updated_on), |
|
121 | 121 | 'created_on': _render('pullrequest_updated_on', |
|
122 | 122 | h.datetime_to_time(pr.created_on)), |
|
123 | 123 | 'created_on_raw': h.datetime_to_time(pr.created_on), |
|
124 | 124 | 'state': pr.pull_request_state, |
|
125 | 125 | 'author': _render('pullrequest_author', |
|
126 | 126 | pr.author.full_contact, ), |
|
127 | 127 | 'author_raw': pr.author.full_name, |
|
128 | 128 | 'comments': _render('pullrequest_comments', len(comments)), |
|
129 | 129 | 'comments_raw': len(comments), |
|
130 | 130 | 'closed': pr.is_closed(), |
|
131 | 131 | }) |
|
132 | 132 | |
|
133 | 133 | data = ({ |
|
134 | 134 | 'draw': draw, |
|
135 | 135 | 'data': data, |
|
136 | 136 | 'recordsTotal': pull_requests_total_count, |
|
137 | 137 | 'recordsFiltered': pull_requests_total_count, |
|
138 | 138 | }) |
|
139 | 139 | return data |
|
140 | 140 | |
|
141 | 141 | @LoginRequired() |
|
142 | 142 | @HasRepoPermissionAnyDecorator( |
|
143 | 143 | 'repository.read', 'repository.write', 'repository.admin') |
|
144 | 144 | @view_config( |
|
145 | 145 | route_name='pullrequest_show_all', request_method='GET', |
|
146 | 146 | renderer='rhodecode:templates/pullrequests/pullrequests.mako') |
|
147 | 147 | def pull_request_list(self): |
|
148 | 148 | c = self.load_default_context() |
|
149 | 149 | |
|
150 | 150 | req_get = self.request.GET |
|
151 | 151 | c.source = str2bool(req_get.get('source')) |
|
152 | 152 | c.closed = str2bool(req_get.get('closed')) |
|
153 | 153 | c.my = str2bool(req_get.get('my')) |
|
154 | 154 | c.awaiting_review = str2bool(req_get.get('awaiting_review')) |
|
155 | 155 | c.awaiting_my_review = str2bool(req_get.get('awaiting_my_review')) |
|
156 | 156 | |
|
157 | 157 | c.active = 'open' |
|
158 | 158 | if c.my: |
|
159 | 159 | c.active = 'my' |
|
160 | 160 | if c.closed: |
|
161 | 161 | c.active = 'closed' |
|
162 | 162 | if c.awaiting_review and not c.source: |
|
163 | 163 | c.active = 'awaiting' |
|
164 | 164 | if c.source and not c.awaiting_review: |
|
165 | 165 | c.active = 'source' |
|
166 | 166 | if c.awaiting_my_review: |
|
167 | 167 | c.active = 'awaiting_my' |
|
168 | 168 | |
|
169 | 169 | return self._get_template_context(c) |
|
170 | 170 | |
|
171 | 171 | @LoginRequired() |
|
172 | 172 | @HasRepoPermissionAnyDecorator( |
|
173 | 173 | 'repository.read', 'repository.write', 'repository.admin') |
|
174 | 174 | @view_config( |
|
175 | 175 | route_name='pullrequest_show_all_data', request_method='GET', |
|
176 | 176 | renderer='json_ext', xhr=True) |
|
177 | 177 | def pull_request_list_data(self): |
|
178 | 178 | self.load_default_context() |
|
179 | 179 | |
|
180 | 180 | # additional filters |
|
181 | 181 | req_get = self.request.GET |
|
182 | 182 | source = str2bool(req_get.get('source')) |
|
183 | 183 | closed = str2bool(req_get.get('closed')) |
|
184 | 184 | my = str2bool(req_get.get('my')) |
|
185 | 185 | awaiting_review = str2bool(req_get.get('awaiting_review')) |
|
186 | 186 | awaiting_my_review = str2bool(req_get.get('awaiting_my_review')) |
|
187 | 187 | |
|
188 | 188 | filter_type = 'awaiting_review' if awaiting_review \ |
|
189 | 189 | else 'awaiting_my_review' if awaiting_my_review \ |
|
190 | 190 | else None |
|
191 | 191 | |
|
192 | 192 | opened_by = None |
|
193 | 193 | if my: |
|
194 | 194 | opened_by = [self._rhodecode_user.user_id] |
|
195 | 195 | |
|
196 | 196 | statuses = [PullRequest.STATUS_NEW, PullRequest.STATUS_OPEN] |
|
197 | 197 | if closed: |
|
198 | 198 | statuses = [PullRequest.STATUS_CLOSED] |
|
199 | 199 | |
|
200 | 200 | data = self._get_pull_requests_list( |
|
201 | 201 | repo_name=self.db_repo_name, source=source, |
|
202 | 202 | filter_type=filter_type, opened_by=opened_by, statuses=statuses) |
|
203 | 203 | |
|
204 | 204 | return data |
|
205 | 205 | |
|
206 | 206 | def _is_diff_cache_enabled(self, target_repo): |
|
207 | 207 | caching_enabled = self._get_general_setting( |
|
208 | 208 | target_repo, 'rhodecode_diff_cache') |
|
209 | 209 | log.debug('Diff caching enabled: %s', caching_enabled) |
|
210 | 210 | return caching_enabled |
|
211 | 211 | |
|
212 | 212 | def _get_diffset(self, source_repo_name, source_repo, |
|
213 | 213 | source_ref_id, target_ref_id, |
|
214 | 214 | target_commit, source_commit, diff_limit, file_limit, |
|
215 | 215 | fulldiff, hide_whitespace_changes, diff_context): |
|
216 | 216 | |
|
217 | 217 | vcs_diff = PullRequestModel().get_diff( |
|
218 | 218 | source_repo, source_ref_id, target_ref_id, |
|
219 | 219 | hide_whitespace_changes, diff_context) |
|
220 | 220 | |
|
221 | 221 | diff_processor = diffs.DiffProcessor( |
|
222 | 222 | vcs_diff, format='newdiff', diff_limit=diff_limit, |
|
223 | 223 | file_limit=file_limit, show_full_diff=fulldiff) |
|
224 | 224 | |
|
225 | 225 | _parsed = diff_processor.prepare() |
|
226 | 226 | |
|
227 | 227 | diffset = codeblocks.DiffSet( |
|
228 | 228 | repo_name=self.db_repo_name, |
|
229 | 229 | source_repo_name=source_repo_name, |
|
230 | 230 | source_node_getter=codeblocks.diffset_node_getter(target_commit), |
|
231 | 231 | target_node_getter=codeblocks.diffset_node_getter(source_commit), |
|
232 | 232 | ) |
|
233 | 233 | diffset = self.path_filter.render_patchset_filtered( |
|
234 | 234 | diffset, _parsed, target_commit.raw_id, source_commit.raw_id) |
|
235 | 235 | |
|
236 | 236 | return diffset |
|
237 | 237 | |
|
238 | 238 | def _get_range_diffset(self, source_scm, source_repo, |
|
239 | 239 | commit1, commit2, diff_limit, file_limit, |
|
240 | 240 | fulldiff, hide_whitespace_changes, diff_context): |
|
241 | 241 | vcs_diff = source_scm.get_diff( |
|
242 | 242 | commit1, commit2, |
|
243 | 243 | ignore_whitespace=hide_whitespace_changes, |
|
244 | 244 | context=diff_context) |
|
245 | 245 | |
|
246 | 246 | diff_processor = diffs.DiffProcessor( |
|
247 | 247 | vcs_diff, format='newdiff', diff_limit=diff_limit, |
|
248 | 248 | file_limit=file_limit, show_full_diff=fulldiff) |
|
249 | 249 | |
|
250 | 250 | _parsed = diff_processor.prepare() |
|
251 | 251 | |
|
252 | 252 | diffset = codeblocks.DiffSet( |
|
253 | 253 | repo_name=source_repo.repo_name, |
|
254 | 254 | source_node_getter=codeblocks.diffset_node_getter(commit1), |
|
255 | 255 | target_node_getter=codeblocks.diffset_node_getter(commit2)) |
|
256 | 256 | |
|
257 | 257 | diffset = self.path_filter.render_patchset_filtered( |
|
258 | 258 | diffset, _parsed, commit1.raw_id, commit2.raw_id) |
|
259 | 259 | |
|
260 | 260 | return diffset |
|
261 | 261 | |
|
262 | 262 | @LoginRequired() |
|
263 | 263 | @HasRepoPermissionAnyDecorator( |
|
264 | 264 | 'repository.read', 'repository.write', 'repository.admin') |
|
265 | 265 | @view_config( |
|
266 | 266 | route_name='pullrequest_show', request_method='GET', |
|
267 | 267 | renderer='rhodecode:templates/pullrequests/pullrequest_show.mako') |
|
268 | 268 | def pull_request_show(self): |
|
269 | 269 | _ = self.request.translate |
|
270 | 270 | c = self.load_default_context() |
|
271 | 271 | |
|
272 | 272 | pull_request = PullRequest.get_or_404( |
|
273 | 273 | self.request.matchdict['pull_request_id']) |
|
274 | 274 | pull_request_id = pull_request.pull_request_id |
|
275 | 275 | |
|
276 | 276 | c.state_progressing = pull_request.is_state_changing() |
|
277 | 277 | |
|
278 | 278 | _new_state = { |
|
279 | 279 | 'created': PullRequest.STATE_CREATED, |
|
280 | 280 | }.get(self.request.GET.get('force_state')) |
|
281 | 281 | if c.is_super_admin and _new_state: |
|
282 | 282 | with pull_request.set_state(PullRequest.STATE_UPDATING, final_state=_new_state): |
|
283 | 283 | h.flash( |
|
284 | 284 | _('Pull Request state was force changed to `{}`').format(_new_state), |
|
285 | 285 | category='success') |
|
286 | 286 | Session().commit() |
|
287 | 287 | |
|
288 | 288 | raise HTTPFound(h.route_path( |
|
289 | 289 | 'pullrequest_show', repo_name=self.db_repo_name, |
|
290 | 290 | pull_request_id=pull_request_id)) |
|
291 | 291 | |
|
292 | 292 | version = self.request.GET.get('version') |
|
293 | 293 | from_version = self.request.GET.get('from_version') or version |
|
294 | 294 | merge_checks = self.request.GET.get('merge_checks') |
|
295 | 295 | c.fulldiff = str2bool(self.request.GET.get('fulldiff')) |
|
296 | 296 | |
|
297 | 297 | # fetch global flags of ignore ws or context lines |
|
298 | 298 | diff_context = diffs.get_diff_context(self.request) |
|
299 | 299 | hide_whitespace_changes = diffs.get_diff_whitespace_flag(self.request) |
|
300 | 300 | |
|
301 | 301 | force_refresh = str2bool(self.request.GET.get('force_refresh')) |
|
302 | 302 | |
|
303 | 303 | (pull_request_latest, |
|
304 | 304 | pull_request_at_ver, |
|
305 | 305 | pull_request_display_obj, |
|
306 | 306 | at_version) = PullRequestModel().get_pr_version( |
|
307 | 307 | pull_request_id, version=version) |
|
308 | 308 | pr_closed = pull_request_latest.is_closed() |
|
309 | 309 | |
|
310 | 310 | if pr_closed and (version or from_version): |
|
311 | 311 | # not allow to browse versions |
|
312 | 312 | raise HTTPFound(h.route_path( |
|
313 | 313 | 'pullrequest_show', repo_name=self.db_repo_name, |
|
314 | 314 | pull_request_id=pull_request_id)) |
|
315 | 315 | |
|
316 | 316 | versions = pull_request_display_obj.versions() |
|
317 | 317 | # used to store per-commit range diffs |
|
318 | 318 | c.changes = collections.OrderedDict() |
|
319 | 319 | c.range_diff_on = self.request.GET.get('range-diff') == "1" |
|
320 | 320 | |
|
321 | 321 | c.at_version = at_version |
|
322 | 322 | c.at_version_num = (at_version |
|
323 | 323 | if at_version and at_version != 'latest' |
|
324 | 324 | else None) |
|
325 | 325 | c.at_version_pos = ChangesetComment.get_index_from_version( |
|
326 | 326 | c.at_version_num, versions) |
|
327 | 327 | |
|
328 | 328 | (prev_pull_request_latest, |
|
329 | 329 | prev_pull_request_at_ver, |
|
330 | 330 | prev_pull_request_display_obj, |
|
331 | 331 | prev_at_version) = PullRequestModel().get_pr_version( |
|
332 | 332 | pull_request_id, version=from_version) |
|
333 | 333 | |
|
334 | 334 | c.from_version = prev_at_version |
|
335 | 335 | c.from_version_num = (prev_at_version |
|
336 | 336 | if prev_at_version and prev_at_version != 'latest' |
|
337 | 337 | else None) |
|
338 | 338 | c.from_version_pos = ChangesetComment.get_index_from_version( |
|
339 | 339 | c.from_version_num, versions) |
|
340 | 340 | |
|
341 | 341 | # define if we're in COMPARE mode or VIEW at version mode |
|
342 | 342 | compare = at_version != prev_at_version |
|
343 | 343 | |
|
344 | 344 | # pull_requests repo_name we opened it against |
|
345 | 345 | # ie. target_repo must match |
|
346 | 346 | if self.db_repo_name != pull_request_at_ver.target_repo.repo_name: |
|
347 | 347 | raise HTTPNotFound() |
|
348 | 348 | |
|
349 | 349 | c.shadow_clone_url = PullRequestModel().get_shadow_clone_url( |
|
350 | 350 | pull_request_at_ver) |
|
351 | 351 | |
|
352 | 352 | c.pull_request = pull_request_display_obj |
|
353 | 353 | c.renderer = pull_request_at_ver.description_renderer or c.renderer |
|
354 | 354 | c.pull_request_latest = pull_request_latest |
|
355 | 355 | |
|
356 | 356 | if compare or (at_version and not at_version == 'latest'): |
|
357 | 357 | c.allowed_to_change_status = False |
|
358 | 358 | c.allowed_to_update = False |
|
359 | 359 | c.allowed_to_merge = False |
|
360 | 360 | c.allowed_to_delete = False |
|
361 | 361 | c.allowed_to_comment = False |
|
362 | 362 | c.allowed_to_close = False |
|
363 | 363 | else: |
|
364 | 364 | can_change_status = PullRequestModel().check_user_change_status( |
|
365 | 365 | pull_request_at_ver, self._rhodecode_user) |
|
366 | 366 | c.allowed_to_change_status = can_change_status and not pr_closed |
|
367 | 367 | |
|
368 | 368 | c.allowed_to_update = PullRequestModel().check_user_update( |
|
369 | 369 | pull_request_latest, self._rhodecode_user) and not pr_closed |
|
370 | 370 | c.allowed_to_merge = PullRequestModel().check_user_merge( |
|
371 | 371 | pull_request_latest, self._rhodecode_user) and not pr_closed |
|
372 | 372 | c.allowed_to_delete = PullRequestModel().check_user_delete( |
|
373 | 373 | pull_request_latest, self._rhodecode_user) and not pr_closed |
|
374 | 374 | c.allowed_to_comment = not pr_closed |
|
375 | 375 | c.allowed_to_close = c.allowed_to_merge and not pr_closed |
|
376 | 376 | |
|
377 | 377 | c.forbid_adding_reviewers = False |
|
378 | 378 | c.forbid_author_to_review = False |
|
379 | 379 | c.forbid_commit_author_to_review = False |
|
380 | 380 | |
|
381 | 381 | if pull_request_latest.reviewer_data and \ |
|
382 | 382 | 'rules' in pull_request_latest.reviewer_data: |
|
383 | 383 | rules = pull_request_latest.reviewer_data['rules'] or {} |
|
384 | 384 | try: |
|
385 | 385 | c.forbid_adding_reviewers = rules.get( |
|
386 | 386 | 'forbid_adding_reviewers') |
|
387 | 387 | c.forbid_author_to_review = rules.get( |
|
388 | 388 | 'forbid_author_to_review') |
|
389 | 389 | c.forbid_commit_author_to_review = rules.get( |
|
390 | 390 | 'forbid_commit_author_to_review') |
|
391 | 391 | except Exception: |
|
392 | 392 | pass |
|
393 | 393 | |
|
394 | 394 | # check merge capabilities |
|
395 | 395 | _merge_check = MergeCheck.validate( |
|
396 | 396 | pull_request_latest, auth_user=self._rhodecode_user, |
|
397 | 397 | translator=self.request.translate, |
|
398 | 398 | force_shadow_repo_refresh=force_refresh) |
|
399 | 399 | |
|
400 | 400 | c.pr_merge_errors = _merge_check.error_details |
|
401 | 401 | c.pr_merge_possible = not _merge_check.failed |
|
402 | 402 | c.pr_merge_message = _merge_check.merge_msg |
|
403 | 403 | c.pr_merge_source_commit = _merge_check.source_commit |
|
404 | 404 | c.pr_merge_target_commit = _merge_check.target_commit |
|
405 | 405 | |
|
406 | 406 | c.pr_merge_info = MergeCheck.get_merge_conditions( |
|
407 | 407 | pull_request_latest, translator=self.request.translate) |
|
408 | 408 | |
|
409 | 409 | c.pull_request_review_status = _merge_check.review_status |
|
410 | 410 | if merge_checks: |
|
411 | 411 | self.request.override_renderer = \ |
|
412 | 412 | 'rhodecode:templates/pullrequests/pullrequest_merge_checks.mako' |
|
413 | 413 | return self._get_template_context(c) |
|
414 | 414 | |
|
415 | 415 | comments_model = CommentsModel() |
|
416 | 416 | |
|
417 | 417 | # reviewers and statuses |
|
418 | 418 | c.pull_request_reviewers = pull_request_at_ver.reviewers_statuses() |
|
419 | 419 | allowed_reviewers = [x[0].user_id for x in c.pull_request_reviewers] |
|
420 | 420 | |
|
421 | 421 | # GENERAL COMMENTS with versions # |
|
422 | 422 | q = comments_model._all_general_comments_of_pull_request(pull_request_latest) |
|
423 | 423 | q = q.order_by(ChangesetComment.comment_id.asc()) |
|
424 | 424 | general_comments = q |
|
425 | 425 | |
|
426 | 426 | # pick comments we want to render at current version |
|
427 | 427 | c.comment_versions = comments_model.aggregate_comments( |
|
428 | 428 | general_comments, versions, c.at_version_num) |
|
429 | 429 | c.comments = c.comment_versions[c.at_version_num]['until'] |
|
430 | 430 | |
|
431 | 431 | # INLINE COMMENTS with versions # |
|
432 | 432 | q = comments_model._all_inline_comments_of_pull_request(pull_request_latest) |
|
433 | 433 | q = q.order_by(ChangesetComment.comment_id.asc()) |
|
434 | 434 | inline_comments = q |
|
435 | 435 | |
|
436 | 436 | c.inline_versions = comments_model.aggregate_comments( |
|
437 | 437 | inline_comments, versions, c.at_version_num, inline=True) |
|
438 | 438 | |
|
439 | 439 | # TODOs |
|
440 | 440 | c.unresolved_comments = CommentsModel() \ |
|
441 | 441 | .get_pull_request_unresolved_todos(pull_request) |
|
442 | 442 | c.resolved_comments = CommentsModel() \ |
|
443 | 443 | .get_pull_request_resolved_todos(pull_request) |
|
444 | 444 | |
|
445 | 445 | # inject latest version |
|
446 | 446 | latest_ver = PullRequest.get_pr_display_object( |
|
447 | 447 | pull_request_latest, pull_request_latest) |
|
448 | 448 | |
|
449 | 449 | c.versions = versions + [latest_ver] |
|
450 | 450 | |
|
451 | 451 | # if we use version, then do not show later comments |
|
452 | 452 | # than current version |
|
453 | 453 | display_inline_comments = collections.defaultdict( |
|
454 | 454 | lambda: collections.defaultdict(list)) |
|
455 | 455 | for co in inline_comments: |
|
456 | 456 | if c.at_version_num: |
|
457 | 457 | # pick comments that are at least UPTO given version, so we |
|
458 | 458 | # don't render comments for higher version |
|
459 | 459 | should_render = co.pull_request_version_id and \ |
|
460 | 460 | co.pull_request_version_id <= c.at_version_num |
|
461 | 461 | else: |
|
462 | 462 | # showing all, for 'latest' |
|
463 | 463 | should_render = True |
|
464 | 464 | |
|
465 | 465 | if should_render: |
|
466 | 466 | display_inline_comments[co.f_path][co.line_no].append(co) |
|
467 | 467 | |
|
468 | 468 | # load diff data into template context, if we use compare mode then |
|
469 | 469 | # diff is calculated based on changes between versions of PR |
|
470 | 470 | |
|
471 | 471 | source_repo = pull_request_at_ver.source_repo |
|
472 | 472 | source_ref_id = pull_request_at_ver.source_ref_parts.commit_id |
|
473 | 473 | |
|
474 | 474 | target_repo = pull_request_at_ver.target_repo |
|
475 | 475 | target_ref_id = pull_request_at_ver.target_ref_parts.commit_id |
|
476 | 476 | |
|
477 | 477 | if compare: |
|
478 | 478 | # in compare switch the diff base to latest commit from prev version |
|
479 | 479 | target_ref_id = prev_pull_request_display_obj.revisions[0] |
|
480 | 480 | |
|
481 | 481 | # despite opening commits for bookmarks/branches/tags, we always |
|
482 | 482 | # convert this to rev to prevent changes after bookmark or branch change |
|
483 | 483 | c.source_ref_type = 'rev' |
|
484 | 484 | c.source_ref = source_ref_id |
|
485 | 485 | |
|
486 | 486 | c.target_ref_type = 'rev' |
|
487 | 487 | c.target_ref = target_ref_id |
|
488 | 488 | |
|
489 | 489 | c.source_repo = source_repo |
|
490 | 490 | c.target_repo = target_repo |
|
491 | 491 | |
|
492 | 492 | c.commit_ranges = [] |
|
493 | 493 | source_commit = EmptyCommit() |
|
494 | 494 | target_commit = EmptyCommit() |
|
495 | 495 | c.missing_requirements = False |
|
496 | 496 | |
|
497 | 497 | source_scm = source_repo.scm_instance() |
|
498 | 498 | target_scm = target_repo.scm_instance() |
|
499 | 499 | |
|
500 | 500 | shadow_scm = None |
|
501 | 501 | try: |
|
502 | 502 | shadow_scm = pull_request_latest.get_shadow_repo() |
|
503 | 503 | except Exception: |
|
504 | 504 | log.debug('Failed to get shadow repo', exc_info=True) |
|
505 | 505 | # try first the existing source_repo, and then shadow |
|
506 | 506 | # repo if we can obtain one |
|
507 | 507 | commits_source_repo = source_scm |
|
508 | 508 | if shadow_scm: |
|
509 | 509 | commits_source_repo = shadow_scm |
|
510 | 510 | |
|
511 | 511 | c.commits_source_repo = commits_source_repo |
|
512 | 512 | c.ancestor = None # set it to None, to hide it from PR view |
|
513 | 513 | |
|
514 | 514 | # empty version means latest, so we keep this to prevent |
|
515 | 515 | # double caching |
|
516 | 516 | version_normalized = version or 'latest' |
|
517 | 517 | from_version_normalized = from_version or 'latest' |
|
518 | 518 | |
|
519 | 519 | cache_path = self.rhodecode_vcs_repo.get_create_shadow_cache_pr_path(target_repo) |
|
520 | 520 | cache_file_path = diff_cache_exist( |
|
521 | 521 | cache_path, 'pull_request', pull_request_id, version_normalized, |
|
522 | 522 | from_version_normalized, source_ref_id, target_ref_id, |
|
523 | 523 | hide_whitespace_changes, diff_context, c.fulldiff) |
|
524 | 524 | |
|
525 | 525 | caching_enabled = self._is_diff_cache_enabled(c.target_repo) |
|
526 | 526 | force_recache = self.get_recache_flag() |
|
527 | 527 | |
|
528 | 528 | cached_diff = None |
|
529 | 529 | if caching_enabled: |
|
530 | 530 | cached_diff = load_cached_diff(cache_file_path) |
|
531 | 531 | |
|
532 | 532 | has_proper_commit_cache = ( |
|
533 | 533 | cached_diff and cached_diff.get('commits') |
|
534 | 534 | and len(cached_diff.get('commits', [])) == 5 |
|
535 | 535 | and cached_diff.get('commits')[0] |
|
536 | 536 | and cached_diff.get('commits')[3]) |
|
537 | 537 | |
|
538 | 538 | if not force_recache and not c.range_diff_on and has_proper_commit_cache: |
|
539 | 539 | diff_commit_cache = \ |
|
540 | 540 | (ancestor_commit, commit_cache, missing_requirements, |
|
541 | 541 | source_commit, target_commit) = cached_diff['commits'] |
|
542 | 542 | else: |
|
543 | 543 | # NOTE(marcink): we reach potentially unreachable errors when a PR has |
|
544 | 544 | # merge errors resulting in potentially hidden commits in the shadow repo. |
|
545 | 545 | maybe_unreachable = _merge_check.MERGE_CHECK in _merge_check.error_details \ |
|
546 | 546 | and _merge_check.merge_response |
|
547 | 547 | maybe_unreachable = maybe_unreachable \ |
|
548 | 548 | and _merge_check.merge_response.metadata.get('unresolved_files') |
|
549 | 549 | log.debug("Using unreachable commits due to MERGE_CHECK in merge simulation") |
|
550 | 550 | diff_commit_cache = \ |
|
551 | 551 | (ancestor_commit, commit_cache, missing_requirements, |
|
552 | 552 | source_commit, target_commit) = self.get_commits( |
|
553 | 553 | commits_source_repo, |
|
554 | 554 | pull_request_at_ver, |
|
555 | 555 | source_commit, |
|
556 | 556 | source_ref_id, |
|
557 | 557 | source_scm, |
|
558 | 558 | target_commit, |
|
559 | 559 | target_ref_id, |
|
560 | 560 | target_scm, maybe_unreachable=maybe_unreachable) |
|
561 | 561 | |
|
562 | 562 | # register our commit range |
|
563 | 563 | for comm in commit_cache.values(): |
|
564 | 564 | c.commit_ranges.append(comm) |
|
565 | 565 | |
|
566 | 566 | c.missing_requirements = missing_requirements |
|
567 | 567 | c.ancestor_commit = ancestor_commit |
|
568 | 568 | c.statuses = source_repo.statuses( |
|
569 | 569 | [x.raw_id for x in c.commit_ranges]) |
|
570 | 570 | |
|
571 | 571 | # auto collapse if we have more than limit |
|
572 | 572 | collapse_limit = diffs.DiffProcessor._collapse_commits_over |
|
573 | 573 | c.collapse_all_commits = len(c.commit_ranges) > collapse_limit |
|
574 | 574 | c.compare_mode = compare |
|
575 | 575 | |
|
576 | 576 | # diff_limit is the old behavior, will cut off the whole diff |
|
577 | 577 | # if the limit is applied otherwise will just hide the |
|
578 | 578 | # big files from the front-end |
|
579 | 579 | diff_limit = c.visual.cut_off_limit_diff |
|
580 | 580 | file_limit = c.visual.cut_off_limit_file |
|
581 | 581 | |
|
582 | 582 | c.missing_commits = False |
|
583 | 583 | if (c.missing_requirements |
|
584 | 584 | or isinstance(source_commit, EmptyCommit) |
|
585 | 585 | or source_commit == target_commit): |
|
586 | 586 | |
|
587 | 587 | c.missing_commits = True |
|
588 | 588 | else: |
|
589 | 589 | c.inline_comments = display_inline_comments |
|
590 | 590 | |
|
591 | 591 | has_proper_diff_cache = cached_diff and cached_diff.get('commits') |
|
592 | 592 | if not force_recache and has_proper_diff_cache: |
|
593 | 593 | c.diffset = cached_diff['diff'] |
|
594 | 594 | (ancestor_commit, commit_cache, missing_requirements, |
|
595 | 595 | source_commit, target_commit) = cached_diff['commits'] |
|
596 | 596 | else: |
|
597 | 597 | c.diffset = self._get_diffset( |
|
598 | 598 | c.source_repo.repo_name, commits_source_repo, |
|
599 | 599 | source_ref_id, target_ref_id, |
|
600 | 600 | target_commit, source_commit, |
|
601 | 601 | diff_limit, file_limit, c.fulldiff, |
|
602 | 602 | hide_whitespace_changes, diff_context) |
|
603 | 603 | |
|
604 | 604 | # save cached diff |
|
605 | 605 | if caching_enabled: |
|
606 | 606 | cache_diff(cache_file_path, c.diffset, diff_commit_cache) |
|
607 | 607 | |
|
608 | 608 | c.limited_diff = c.diffset.limited_diff |
|
609 | 609 | |
|
610 | 610 | # calculate removed files that are bound to comments |
|
611 | 611 | comment_deleted_files = [ |
|
612 | 612 | fname for fname in display_inline_comments |
|
613 | 613 | if fname not in c.diffset.file_stats] |
|
614 | 614 | |
|
615 | 615 | c.deleted_files_comments = collections.defaultdict(dict) |
|
616 | 616 | for fname, per_line_comments in display_inline_comments.items(): |
|
617 | 617 | if fname in comment_deleted_files: |
|
618 | 618 | c.deleted_files_comments[fname]['stats'] = 0 |
|
619 | 619 | c.deleted_files_comments[fname]['comments'] = list() |
|
620 | 620 | for lno, comments in per_line_comments.items(): |
|
621 | 621 | c.deleted_files_comments[fname]['comments'].extend(comments) |
|
622 | 622 | |
|
623 | 623 | # maybe calculate the range diff |
|
624 | 624 | if c.range_diff_on: |
|
625 | 625 | # TODO(marcink): set whitespace/context |
|
626 | 626 | context_lcl = 3 |
|
627 | 627 | ign_whitespace_lcl = False |
|
628 | 628 | |
|
629 | 629 | for commit in c.commit_ranges: |
|
630 | 630 | commit2 = commit |
|
631 | 631 | commit1 = commit.first_parent |
|
632 | 632 | |
|
633 | 633 | range_diff_cache_file_path = diff_cache_exist( |
|
634 | 634 | cache_path, 'diff', commit.raw_id, |
|
635 | 635 | ign_whitespace_lcl, context_lcl, c.fulldiff) |
|
636 | 636 | |
|
637 | 637 | cached_diff = None |
|
638 | 638 | if caching_enabled: |
|
639 | 639 | cached_diff = load_cached_diff(range_diff_cache_file_path) |
|
640 | 640 | |
|
641 | 641 | has_proper_diff_cache = cached_diff and cached_diff.get('diff') |
|
642 | 642 | if not force_recache and has_proper_diff_cache: |
|
643 | 643 | diffset = cached_diff['diff'] |
|
644 | 644 | else: |
|
645 | 645 | diffset = self._get_range_diffset( |
|
646 | 646 | commits_source_repo, source_repo, |
|
647 | 647 | commit1, commit2, diff_limit, file_limit, |
|
648 | 648 | c.fulldiff, ign_whitespace_lcl, context_lcl |
|
649 | 649 | ) |
|
650 | 650 | |
|
651 | 651 | # save cached diff |
|
652 | 652 | if caching_enabled: |
|
653 | 653 | cache_diff(range_diff_cache_file_path, diffset, None) |
|
654 | 654 | |
|
655 | 655 | c.changes[commit.raw_id] = diffset |
|
656 | 656 | |
|
657 | 657 | # this is a hack to properly display links, when creating PR, the |
|
658 | 658 | # compare view and others uses different notation, and |
|
659 | 659 | # compare_commits.mako renders links based on the target_repo. |
|
660 | 660 | # We need to swap that here to generate it properly on the html side |
|
661 | 661 | c.target_repo = c.source_repo |
|
662 | 662 | |
|
663 | 663 | c.commit_statuses = ChangesetStatus.STATUSES |
|
664 | 664 | |
|
665 | 665 | c.show_version_changes = not pr_closed |
|
666 | 666 | if c.show_version_changes: |
|
667 | 667 | cur_obj = pull_request_at_ver |
|
668 | 668 | prev_obj = prev_pull_request_at_ver |
|
669 | 669 | |
|
670 | 670 | old_commit_ids = prev_obj.revisions |
|
671 | 671 | new_commit_ids = cur_obj.revisions |
|
672 | 672 | commit_changes = PullRequestModel()._calculate_commit_id_changes( |
|
673 | 673 | old_commit_ids, new_commit_ids) |
|
674 | 674 | c.commit_changes_summary = commit_changes |
|
675 | 675 | |
|
676 | 676 | # calculate the diff for commits between versions |
|
677 | 677 | c.commit_changes = [] |
|
678 | 678 | mark = lambda cs, fw: list( |
|
679 | 679 | h.itertools.izip_longest([], cs, fillvalue=fw)) |
|
680 | 680 | for c_type, raw_id in mark(commit_changes.added, 'a') \ |
|
681 | 681 | + mark(commit_changes.removed, 'r') \ |
|
682 | 682 | + mark(commit_changes.common, 'c'): |
|
683 | 683 | |
|
684 | 684 | if raw_id in commit_cache: |
|
685 | 685 | commit = commit_cache[raw_id] |
|
686 | 686 | else: |
|
687 | 687 | try: |
|
688 | 688 | commit = commits_source_repo.get_commit(raw_id) |
|
689 | 689 | except CommitDoesNotExistError: |
|
690 | 690 | # in case we fail extracting still use "dummy" commit |
|
691 | 691 | # for display in commit diff |
|
692 | 692 | commit = h.AttributeDict( |
|
693 | 693 | {'raw_id': raw_id, |
|
694 | 694 | 'message': 'EMPTY or MISSING COMMIT'}) |
|
695 | 695 | c.commit_changes.append([c_type, commit]) |
|
696 | 696 | |
|
697 | 697 | # current user review statuses for each version |
|
698 | 698 | c.review_versions = {} |
|
699 | 699 | if self._rhodecode_user.user_id in allowed_reviewers: |
|
700 | 700 | for co in general_comments: |
|
701 | 701 | if co.author.user_id == self._rhodecode_user.user_id: |
|
702 | 702 | status = co.status_change |
|
703 | 703 | if status: |
|
704 | 704 | _ver_pr = status[0].comment.pull_request_version_id |
|
705 | 705 | c.review_versions[_ver_pr] = status[0] |
|
706 | 706 | |
|
707 | 707 | return self._get_template_context(c) |
|
708 | 708 | |
|
709 | 709 | def get_commits( |
|
710 | 710 | self, commits_source_repo, pull_request_at_ver, source_commit, |
|
711 | 711 | source_ref_id, source_scm, target_commit, target_ref_id, target_scm, |
|
712 | 712 | maybe_unreachable=False): |
|
713 | 713 | |
|
714 | 714 | commit_cache = collections.OrderedDict() |
|
715 | 715 | missing_requirements = False |
|
716 | 716 | |
|
717 | 717 | try: |
|
718 | 718 | pre_load = ["author", "date", "message", "branch", "parents"] |
|
719 | 719 | |
|
720 | 720 | pull_request_commits = pull_request_at_ver.revisions |
|
721 | 721 | log.debug('Loading %s commits from %s', |
|
722 | 722 | len(pull_request_commits), commits_source_repo) |
|
723 | 723 | |
|
724 | 724 | for rev in pull_request_commits: |
|
725 | 725 | comm = commits_source_repo.get_commit(commit_id=rev, pre_load=pre_load, |
|
726 | 726 | maybe_unreachable=maybe_unreachable) |
|
727 | 727 | commit_cache[comm.raw_id] = comm |
|
728 | 728 | |
|
729 | 729 | # Order here matters, we first need to get target, and then |
|
730 | 730 | # the source |
|
731 | 731 | target_commit = commits_source_repo.get_commit( |
|
732 | 732 | commit_id=safe_str(target_ref_id)) |
|
733 | 733 | |
|
734 | 734 | source_commit = commits_source_repo.get_commit( |
|
735 | 735 | commit_id=safe_str(source_ref_id), maybe_unreachable=True) |
|
736 | 736 | except CommitDoesNotExistError: |
|
737 | 737 | log.warning('Failed to get commit from `{}` repo'.format( |
|
738 | 738 | commits_source_repo), exc_info=True) |
|
739 | 739 | except RepositoryRequirementError: |
|
740 | 740 | log.warning('Failed to get all required data from repo', exc_info=True) |
|
741 | 741 | missing_requirements = True |
|
742 | 742 | ancestor_commit = None |
|
743 | 743 | try: |
|
744 | 744 | ancestor_id = source_scm.get_common_ancestor( |
|
745 | 745 | source_commit.raw_id, target_commit.raw_id, target_scm) |
|
746 | 746 | ancestor_commit = source_scm.get_commit(ancestor_id) |
|
747 | 747 | except Exception: |
|
748 | 748 | ancestor_commit = None |
|
749 | 749 | return ancestor_commit, commit_cache, missing_requirements, source_commit, target_commit |
|
750 | 750 | |
|
751 | 751 | def assure_not_empty_repo(self): |
|
752 | 752 | _ = self.request.translate |
|
753 | 753 | |
|
754 | 754 | try: |
|
755 | 755 | self.db_repo.scm_instance().get_commit() |
|
756 | 756 | except EmptyRepositoryError: |
|
757 | 757 | h.flash(h.literal(_('There are no commits yet')), |
|
758 | 758 | category='warning') |
|
759 | 759 | raise HTTPFound( |
|
760 | 760 | h.route_path('repo_summary', repo_name=self.db_repo.repo_name)) |
|
761 | 761 | |
|
762 | 762 | @LoginRequired() |
|
763 | 763 | @NotAnonymous() |
|
764 | 764 | @HasRepoPermissionAnyDecorator( |
|
765 | 765 | 'repository.read', 'repository.write', 'repository.admin') |
|
766 | 766 | @view_config( |
|
767 | 767 | route_name='pullrequest_new', request_method='GET', |
|
768 | 768 | renderer='rhodecode:templates/pullrequests/pullrequest.mako') |
|
769 | 769 | def pull_request_new(self): |
|
770 | 770 | _ = self.request.translate |
|
771 | 771 | c = self.load_default_context() |
|
772 | 772 | |
|
773 | 773 | self.assure_not_empty_repo() |
|
774 | 774 | source_repo = self.db_repo |
|
775 | 775 | |
|
776 | 776 | commit_id = self.request.GET.get('commit') |
|
777 | 777 | branch_ref = self.request.GET.get('branch') |
|
778 | 778 | bookmark_ref = self.request.GET.get('bookmark') |
|
779 | 779 | |
|
780 | 780 | try: |
|
781 | 781 | source_repo_data = PullRequestModel().generate_repo_data( |
|
782 | 782 | source_repo, commit_id=commit_id, |
|
783 | 783 | branch=branch_ref, bookmark=bookmark_ref, |
|
784 | 784 | translator=self.request.translate) |
|
785 | 785 | except CommitDoesNotExistError as e: |
|
786 | 786 | log.exception(e) |
|
787 | 787 | h.flash(_('Commit does not exist'), 'error') |
|
788 | 788 | raise HTTPFound( |
|
789 | 789 | h.route_path('pullrequest_new', repo_name=source_repo.repo_name)) |
|
790 | 790 | |
|
791 | 791 | default_target_repo = source_repo |
|
792 | 792 | |
|
793 | 793 | if source_repo.parent and c.has_origin_repo_read_perm: |
|
794 | 794 | parent_vcs_obj = source_repo.parent.scm_instance() |
|
795 | 795 | if parent_vcs_obj and not parent_vcs_obj.is_empty(): |
|
796 | 796 | # change default if we have a parent repo |
|
797 | 797 | default_target_repo = source_repo.parent |
|
798 | 798 | |
|
799 | 799 | target_repo_data = PullRequestModel().generate_repo_data( |
|
800 | 800 | default_target_repo, translator=self.request.translate) |
|
801 | 801 | |
|
802 | 802 | selected_source_ref = source_repo_data['refs']['selected_ref'] |
|
803 | 803 | title_source_ref = '' |
|
804 | 804 | if selected_source_ref: |
|
805 | 805 | title_source_ref = selected_source_ref.split(':', 2)[1] |
|
806 | 806 | c.default_title = PullRequestModel().generate_pullrequest_title( |
|
807 | 807 | source=source_repo.repo_name, |
|
808 | 808 | source_ref=title_source_ref, |
|
809 | 809 | target=default_target_repo.repo_name |
|
810 | 810 | ) |
|
811 | 811 | |
|
812 | 812 | c.default_repo_data = { |
|
813 | 813 | 'source_repo_name': source_repo.repo_name, |
|
814 | 814 | 'source_refs_json': json.dumps(source_repo_data), |
|
815 | 815 | 'target_repo_name': default_target_repo.repo_name, |
|
816 | 816 | 'target_refs_json': json.dumps(target_repo_data), |
|
817 | 817 | } |
|
818 | 818 | c.default_source_ref = selected_source_ref |
|
819 | 819 | |
|
820 | 820 | return self._get_template_context(c) |
|
821 | 821 | |
|
822 | 822 | @LoginRequired() |
|
823 | 823 | @NotAnonymous() |
|
824 | 824 | @HasRepoPermissionAnyDecorator( |
|
825 | 825 | 'repository.read', 'repository.write', 'repository.admin') |
|
826 | 826 | @view_config( |
|
827 | 827 | route_name='pullrequest_repo_refs', request_method='GET', |
|
828 | 828 | renderer='json_ext', xhr=True) |
|
829 | 829 | def pull_request_repo_refs(self): |
|
830 | 830 | self.load_default_context() |
|
831 | 831 | target_repo_name = self.request.matchdict['target_repo_name'] |
|
832 | 832 | repo = Repository.get_by_repo_name(target_repo_name) |
|
833 | 833 | if not repo: |
|
834 | 834 | raise HTTPNotFound() |
|
835 | 835 | |
|
836 | 836 | target_perm = HasRepoPermissionAny( |
|
837 | 837 | 'repository.read', 'repository.write', 'repository.admin')( |
|
838 | 838 | target_repo_name) |
|
839 | 839 | if not target_perm: |
|
840 | 840 | raise HTTPNotFound() |
|
841 | 841 | |
|
842 | 842 | return PullRequestModel().generate_repo_data( |
|
843 | 843 | repo, translator=self.request.translate) |
|
844 | 844 | |
|
845 | 845 | @LoginRequired() |
|
846 | 846 | @NotAnonymous() |
|
847 | 847 | @HasRepoPermissionAnyDecorator( |
|
848 | 848 | 'repository.read', 'repository.write', 'repository.admin') |
|
849 | 849 | @view_config( |
|
850 | 850 | route_name='pullrequest_repo_targets', request_method='GET', |
|
851 | 851 | renderer='json_ext', xhr=True) |
|
852 | 852 | def pullrequest_repo_targets(self): |
|
853 | 853 | _ = self.request.translate |
|
854 | 854 | filter_query = self.request.GET.get('query') |
|
855 | 855 | |
|
856 | 856 | # get the parents |
|
857 | 857 | parent_target_repos = [] |
|
858 | 858 | if self.db_repo.parent: |
|
859 | 859 | parents_query = Repository.query() \ |
|
860 | 860 | .order_by(func.length(Repository.repo_name)) \ |
|
861 | 861 | .filter(Repository.fork_id == self.db_repo.parent.repo_id) |
|
862 | 862 | |
|
863 | 863 | if filter_query: |
|
864 | 864 | ilike_expression = u'%{}%'.format(safe_unicode(filter_query)) |
|
865 | 865 | parents_query = parents_query.filter( |
|
866 | 866 | Repository.repo_name.ilike(ilike_expression)) |
|
867 | 867 | parents = parents_query.limit(20).all() |
|
868 | 868 | |
|
869 | 869 | for parent in parents: |
|
870 | 870 | parent_vcs_obj = parent.scm_instance() |
|
871 | 871 | if parent_vcs_obj and not parent_vcs_obj.is_empty(): |
|
872 | 872 | parent_target_repos.append(parent) |
|
873 | 873 | |
|
874 | 874 | # get other forks, and repo itself |
|
875 | 875 | query = Repository.query() \ |
|
876 | 876 | .order_by(func.length(Repository.repo_name)) \ |
|
877 | 877 | .filter( |
|
878 | 878 | or_(Repository.repo_id == self.db_repo.repo_id, # repo itself |
|
879 | 879 | Repository.fork_id == self.db_repo.repo_id) # forks of this repo |
|
880 | 880 | ) \ |
|
881 | 881 | .filter(~Repository.repo_id.in_([x.repo_id for x in parent_target_repos])) |
|
882 | 882 | |
|
883 | 883 | if filter_query: |
|
884 | 884 | ilike_expression = u'%{}%'.format(safe_unicode(filter_query)) |
|
885 | 885 | query = query.filter(Repository.repo_name.ilike(ilike_expression)) |
|
886 | 886 | |
|
887 | 887 | limit = max(20 - len(parent_target_repos), 5) # not less then 5 |
|
888 | 888 | target_repos = query.limit(limit).all() |
|
889 | 889 | |
|
890 | 890 | all_target_repos = target_repos + parent_target_repos |
|
891 | 891 | |
|
892 | 892 | repos = [] |
|
893 | 893 | # This checks permissions to the repositories |
|
894 | 894 | for obj in ScmModel().get_repos(all_target_repos): |
|
895 | 895 | repos.append({ |
|
896 | 896 | 'id': obj['name'], |
|
897 | 897 | 'text': obj['name'], |
|
898 | 898 | 'type': 'repo', |
|
899 | 899 | 'repo_id': obj['dbrepo']['repo_id'], |
|
900 | 900 | 'repo_type': obj['dbrepo']['repo_type'], |
|
901 | 901 | 'private': obj['dbrepo']['private'], |
|
902 | 902 | |
|
903 | 903 | }) |
|
904 | 904 | |
|
905 | 905 | data = { |
|
906 | 906 | 'more': False, |
|
907 | 907 | 'results': [{ |
|
908 | 908 | 'text': _('Repositories'), |
|
909 | 909 | 'children': repos |
|
910 | 910 | }] if repos else [] |
|
911 | 911 | } |
|
912 | 912 | return data |
|
913 | 913 | |
|
914 | 914 | @LoginRequired() |
|
915 | 915 | @NotAnonymous() |
|
916 | 916 | @HasRepoPermissionAnyDecorator( |
|
917 | 917 | 'repository.read', 'repository.write', 'repository.admin') |
|
918 | 918 | @CSRFRequired() |
|
919 | 919 | @view_config( |
|
920 | 920 | route_name='pullrequest_create', request_method='POST', |
|
921 | 921 | renderer=None) |
|
922 | 922 | def pull_request_create(self): |
|
923 | 923 | _ = self.request.translate |
|
924 | 924 | self.assure_not_empty_repo() |
|
925 | 925 | self.load_default_context() |
|
926 | 926 | |
|
927 | 927 | controls = peppercorn.parse(self.request.POST.items()) |
|
928 | 928 | |
|
929 | 929 | try: |
|
930 | 930 | form = PullRequestForm( |
|
931 | 931 | self.request.translate, self.db_repo.repo_id)() |
|
932 | 932 | _form = form.to_python(controls) |
|
933 | 933 | except formencode.Invalid as errors: |
|
934 | 934 | if errors.error_dict.get('revisions'): |
|
935 | 935 | msg = 'Revisions: %s' % errors.error_dict['revisions'] |
|
936 | 936 | elif errors.error_dict.get('pullrequest_title'): |
|
937 | 937 | msg = errors.error_dict.get('pullrequest_title') |
|
938 | 938 | else: |
|
939 | 939 | msg = _('Error creating pull request: {}').format(errors) |
|
940 | 940 | log.exception(msg) |
|
941 | 941 | h.flash(msg, 'error') |
|
942 | 942 | |
|
943 | 943 | # would rather just go back to form ... |
|
944 | 944 | raise HTTPFound( |
|
945 | 945 | h.route_path('pullrequest_new', repo_name=self.db_repo_name)) |
|
946 | 946 | |
|
947 | 947 | source_repo = _form['source_repo'] |
|
948 | 948 | source_ref = _form['source_ref'] |
|
949 | 949 | target_repo = _form['target_repo'] |
|
950 | 950 | target_ref = _form['target_ref'] |
|
951 | 951 | commit_ids = _form['revisions'][::-1] |
|
952 | 952 | |
|
953 | 953 | # find the ancestor for this pr |
|
954 | 954 | source_db_repo = Repository.get_by_repo_name(_form['source_repo']) |
|
955 | 955 | target_db_repo = Repository.get_by_repo_name(_form['target_repo']) |
|
956 | 956 | |
|
957 | 957 | if not (source_db_repo or target_db_repo): |
|
958 | 958 | h.flash(_('source_repo or target repo not found'), category='error') |
|
959 | 959 | raise HTTPFound( |
|
960 | 960 | h.route_path('pullrequest_new', repo_name=self.db_repo_name)) |
|
961 | 961 | |
|
962 | 962 | # re-check permissions again here |
|
963 | 963 | # source_repo we must have read permissions |
|
964 | 964 | |
|
965 | 965 | source_perm = HasRepoPermissionAny( |
|
966 | 966 | 'repository.read', 'repository.write', 'repository.admin')( |
|
967 | 967 | source_db_repo.repo_name) |
|
968 | 968 | if not source_perm: |
|
969 | 969 | msg = _('Not Enough permissions to source repo `{}`.'.format( |
|
970 | 970 | source_db_repo.repo_name)) |
|
971 | 971 | h.flash(msg, category='error') |
|
972 | 972 | # copy the args back to redirect |
|
973 | 973 | org_query = self.request.GET.mixed() |
|
974 | 974 | raise HTTPFound( |
|
975 | 975 | h.route_path('pullrequest_new', repo_name=self.db_repo_name, |
|
976 | 976 | _query=org_query)) |
|
977 | 977 | |
|
978 | 978 | # target repo we must have read permissions, and also later on |
|
979 | 979 | # we want to check branch permissions here |
|
980 | 980 | target_perm = HasRepoPermissionAny( |
|
981 | 981 | 'repository.read', 'repository.write', 'repository.admin')( |
|
982 | 982 | target_db_repo.repo_name) |
|
983 | 983 | if not target_perm: |
|
984 | 984 | msg = _('Not Enough permissions to target repo `{}`.'.format( |
|
985 | 985 | target_db_repo.repo_name)) |
|
986 | 986 | h.flash(msg, category='error') |
|
987 | 987 | # copy the args back to redirect |
|
988 | 988 | org_query = self.request.GET.mixed() |
|
989 | 989 | raise HTTPFound( |
|
990 | 990 | h.route_path('pullrequest_new', repo_name=self.db_repo_name, |
|
991 | 991 | _query=org_query)) |
|
992 | 992 | |
|
993 | 993 | source_scm = source_db_repo.scm_instance() |
|
994 | 994 | target_scm = target_db_repo.scm_instance() |
|
995 | 995 | |
|
996 | 996 | source_commit = source_scm.get_commit(source_ref.split(':')[-1]) |
|
997 | 997 | target_commit = target_scm.get_commit(target_ref.split(':')[-1]) |
|
998 | 998 | |
|
999 | 999 | ancestor = source_scm.get_common_ancestor( |
|
1000 | 1000 | source_commit.raw_id, target_commit.raw_id, target_scm) |
|
1001 | 1001 | |
|
1002 | 1002 | # recalculate target ref based on ancestor |
|
1003 | 1003 | target_ref_type, target_ref_name, __ = _form['target_ref'].split(':') |
|
1004 | 1004 | target_ref = ':'.join((target_ref_type, target_ref_name, ancestor)) |
|
1005 | 1005 | |
|
1006 | 1006 | get_default_reviewers_data, validate_default_reviewers = \ |
|
1007 | 1007 | PullRequestModel().get_reviewer_functions() |
|
1008 | 1008 | |
|
1009 | 1009 | # recalculate reviewers logic, to make sure we can validate this |
|
1010 | 1010 | reviewer_rules = get_default_reviewers_data( |
|
1011 | 1011 | self._rhodecode_db_user, source_db_repo, |
|
1012 | 1012 | source_commit, target_db_repo, target_commit) |
|
1013 | 1013 | |
|
1014 | 1014 | given_reviewers = _form['review_members'] |
|
1015 | 1015 | reviewers = validate_default_reviewers( |
|
1016 | 1016 | given_reviewers, reviewer_rules) |
|
1017 | 1017 | |
|
1018 | 1018 | pullrequest_title = _form['pullrequest_title'] |
|
1019 | 1019 | title_source_ref = source_ref.split(':', 2)[1] |
|
1020 | 1020 | if not pullrequest_title: |
|
1021 | 1021 | pullrequest_title = PullRequestModel().generate_pullrequest_title( |
|
1022 | 1022 | source=source_repo, |
|
1023 | 1023 | source_ref=title_source_ref, |
|
1024 | 1024 | target=target_repo |
|
1025 | 1025 | ) |
|
1026 | 1026 | |
|
1027 | 1027 | description = _form['pullrequest_desc'] |
|
1028 | 1028 | description_renderer = _form['description_renderer'] |
|
1029 | 1029 | |
|
1030 | 1030 | try: |
|
1031 | 1031 | pull_request = PullRequestModel().create( |
|
1032 | 1032 | created_by=self._rhodecode_user.user_id, |
|
1033 | 1033 | source_repo=source_repo, |
|
1034 | 1034 | source_ref=source_ref, |
|
1035 | 1035 | target_repo=target_repo, |
|
1036 | 1036 | target_ref=target_ref, |
|
1037 | 1037 | revisions=commit_ids, |
|
1038 | 1038 | reviewers=reviewers, |
|
1039 | 1039 | title=pullrequest_title, |
|
1040 | 1040 | description=description, |
|
1041 | 1041 | description_renderer=description_renderer, |
|
1042 | 1042 | reviewer_data=reviewer_rules, |
|
1043 | 1043 | auth_user=self._rhodecode_user |
|
1044 | 1044 | ) |
|
1045 | 1045 | Session().commit() |
|
1046 | 1046 | |
|
1047 | 1047 | h.flash(_('Successfully opened new pull request'), |
|
1048 | 1048 | category='success') |
|
1049 | 1049 | except Exception: |
|
1050 | 1050 | msg = _('Error occurred during creation of this pull request.') |
|
1051 | 1051 | log.exception(msg) |
|
1052 | 1052 | h.flash(msg, category='error') |
|
1053 | 1053 | |
|
1054 | 1054 | # copy the args back to redirect |
|
1055 | 1055 | org_query = self.request.GET.mixed() |
|
1056 | 1056 | raise HTTPFound( |
|
1057 | 1057 | h.route_path('pullrequest_new', repo_name=self.db_repo_name, |
|
1058 | 1058 | _query=org_query)) |
|
1059 | 1059 | |
|
1060 | 1060 | raise HTTPFound( |
|
1061 | 1061 | h.route_path('pullrequest_show', repo_name=target_repo, |
|
1062 | 1062 | pull_request_id=pull_request.pull_request_id)) |
|
1063 | 1063 | |
|
1064 | 1064 | @LoginRequired() |
|
1065 | 1065 | @NotAnonymous() |
|
1066 | 1066 | @HasRepoPermissionAnyDecorator( |
|
1067 | 1067 | 'repository.read', 'repository.write', 'repository.admin') |
|
1068 | 1068 | @CSRFRequired() |
|
1069 | 1069 | @view_config( |
|
1070 | 1070 | route_name='pullrequest_update', request_method='POST', |
|
1071 | 1071 | renderer='json_ext') |
|
1072 | 1072 | def pull_request_update(self): |
|
1073 | 1073 | pull_request = PullRequest.get_or_404( |
|
1074 | 1074 | self.request.matchdict['pull_request_id']) |
|
1075 | 1075 | _ = self.request.translate |
|
1076 | 1076 | |
|
1077 | 1077 | self.load_default_context() |
|
1078 | 1078 | redirect_url = None |
|
1079 | 1079 | |
|
1080 | 1080 | if pull_request.is_closed(): |
|
1081 | 1081 | log.debug('update: forbidden because pull request is closed') |
|
1082 | 1082 | msg = _(u'Cannot update closed pull requests.') |
|
1083 | 1083 | h.flash(msg, category='error') |
|
1084 | 1084 | return {'response': True, |
|
1085 | 1085 | 'redirect_url': redirect_url} |
|
1086 | 1086 | |
|
1087 | 1087 | is_state_changing = pull_request.is_state_changing() |
|
1088 | 1088 | |
|
1089 | 1089 | # only owner or admin can update it |
|
1090 | 1090 | allowed_to_update = PullRequestModel().check_user_update( |
|
1091 | 1091 | pull_request, self._rhodecode_user) |
|
1092 | 1092 | if allowed_to_update: |
|
1093 | 1093 | controls = peppercorn.parse(self.request.POST.items()) |
|
1094 | 1094 | force_refresh = str2bool(self.request.POST.get('force_refresh')) |
|
1095 | 1095 | |
|
1096 | 1096 | if 'review_members' in controls: |
|
1097 | 1097 | self._update_reviewers( |
|
1098 | 1098 | pull_request, controls['review_members'], |
|
1099 | 1099 | pull_request.reviewer_data) |
|
1100 | 1100 | elif str2bool(self.request.POST.get('update_commits', 'false')): |
|
1101 | 1101 | if is_state_changing: |
|
1102 | 1102 | log.debug('commits update: forbidden because pull request is in state %s', |
|
1103 | 1103 | pull_request.pull_request_state) |
|
1104 | 1104 | msg = _(u'Cannot update pull requests commits in state other than `{}`. ' |
|
1105 | 1105 | u'Current state is: `{}`').format( |
|
1106 | 1106 | PullRequest.STATE_CREATED, pull_request.pull_request_state) |
|
1107 | 1107 | h.flash(msg, category='error') |
|
1108 | 1108 | return {'response': True, |
|
1109 | 1109 | 'redirect_url': redirect_url} |
|
1110 | 1110 | |
|
1111 | 1111 | self._update_commits(pull_request) |
|
1112 | 1112 | if force_refresh: |
|
1113 | 1113 | redirect_url = h.route_path( |
|
1114 | 1114 | 'pullrequest_show', repo_name=self.db_repo_name, |
|
1115 | 1115 | pull_request_id=pull_request.pull_request_id, |
|
1116 | 1116 | _query={"force_refresh": 1}) |
|
1117 | 1117 | elif str2bool(self.request.POST.get('edit_pull_request', 'false')): |
|
1118 | 1118 | self._edit_pull_request(pull_request) |
|
1119 | 1119 | else: |
|
1120 | 1120 | raise HTTPBadRequest() |
|
1121 | 1121 | |
|
1122 | 1122 | return {'response': True, |
|
1123 | 1123 | 'redirect_url': redirect_url} |
|
1124 | 1124 | raise HTTPForbidden() |
|
1125 | 1125 | |
|
1126 | 1126 | def _edit_pull_request(self, pull_request): |
|
1127 | 1127 | _ = self.request.translate |
|
1128 | 1128 | |
|
1129 | 1129 | try: |
|
1130 | 1130 | PullRequestModel().edit( |
|
1131 | 1131 | pull_request, |
|
1132 | 1132 | self.request.POST.get('title'), |
|
1133 | 1133 | self.request.POST.get('description'), |
|
1134 | 1134 | self.request.POST.get('description_renderer'), |
|
1135 | 1135 | self._rhodecode_user) |
|
1136 | 1136 | except ValueError: |
|
1137 | 1137 | msg = _(u'Cannot update closed pull requests.') |
|
1138 | 1138 | h.flash(msg, category='error') |
|
1139 | 1139 | return |
|
1140 | 1140 | else: |
|
1141 | 1141 | Session().commit() |
|
1142 | 1142 | |
|
1143 | 1143 | msg = _(u'Pull request title & description updated.') |
|
1144 | 1144 | h.flash(msg, category='success') |
|
1145 | 1145 | return |
|
1146 | 1146 | |
|
1147 | 1147 | def _update_commits(self, pull_request): |
|
1148 | 1148 | _ = self.request.translate |
|
1149 | 1149 | |
|
1150 | 1150 | with pull_request.set_state(PullRequest.STATE_UPDATING): |
|
1151 | 1151 | resp = PullRequestModel().update_commits( |
|
1152 | 1152 | pull_request, self._rhodecode_db_user) |
|
1153 | 1153 | |
|
1154 | 1154 | if resp.executed: |
|
1155 | 1155 | |
|
1156 | 1156 | if resp.target_changed and resp.source_changed: |
|
1157 | 1157 | changed = 'target and source repositories' |
|
1158 | 1158 | elif resp.target_changed and not resp.source_changed: |
|
1159 | 1159 | changed = 'target repository' |
|
1160 | 1160 | elif not resp.target_changed and resp.source_changed: |
|
1161 | 1161 | changed = 'source repository' |
|
1162 | 1162 | else: |
|
1163 | 1163 | changed = 'nothing' |
|
1164 | 1164 | |
|
1165 | 1165 | msg = _(u'Pull request updated to "{source_commit_id}" with ' |
|
1166 | 1166 | u'{count_added} added, {count_removed} removed commits. ' |
|
1167 | 1167 | u'Source of changes: {change_source}') |
|
1168 | 1168 | msg = msg.format( |
|
1169 | 1169 | source_commit_id=pull_request.source_ref_parts.commit_id, |
|
1170 | 1170 | count_added=len(resp.changes.added), |
|
1171 | 1171 | count_removed=len(resp.changes.removed), |
|
1172 | 1172 | change_source=changed) |
|
1173 | 1173 | h.flash(msg, category='success') |
|
1174 | 1174 | |
|
1175 | 1175 | channel = '/repo${}$/pr/{}'.format( |
|
1176 | 1176 | pull_request.target_repo.repo_name, pull_request.pull_request_id) |
|
1177 | 1177 | message = msg + ( |
|
1178 | 1178 | ' - <a onclick="window.location.reload()">' |
|
1179 | 1179 | '<strong>{}</strong></a>'.format(_('Reload page'))) |
|
1180 | 1180 | channelstream.post_message( |
|
1181 | 1181 | channel, message, self._rhodecode_user.username, |
|
1182 | 1182 | registry=self.request.registry) |
|
1183 | 1183 | else: |
|
1184 | 1184 | msg = PullRequestModel.UPDATE_STATUS_MESSAGES[resp.reason] |
|
1185 | 1185 | warning_reasons = [ |
|
1186 | 1186 | UpdateFailureReason.NO_CHANGE, |
|
1187 | 1187 | UpdateFailureReason.WRONG_REF_TYPE, |
|
1188 | 1188 | ] |
|
1189 | 1189 | category = 'warning' if resp.reason in warning_reasons else 'error' |
|
1190 | 1190 | h.flash(msg, category=category) |
|
1191 | 1191 | |
|
1192 | 1192 | @LoginRequired() |
|
1193 | 1193 | @NotAnonymous() |
|
1194 | 1194 | @HasRepoPermissionAnyDecorator( |
|
1195 | 1195 | 'repository.read', 'repository.write', 'repository.admin') |
|
1196 | 1196 | @CSRFRequired() |
|
1197 | 1197 | @view_config( |
|
1198 | 1198 | route_name='pullrequest_merge', request_method='POST', |
|
1199 | 1199 | renderer='json_ext') |
|
1200 | 1200 | def pull_request_merge(self): |
|
1201 | 1201 | """ |
|
1202 | 1202 | Merge will perform a server-side merge of the specified |
|
1203 | 1203 | pull request, if the pull request is approved and mergeable. |
|
1204 | 1204 | After successful merging, the pull request is automatically |
|
1205 | 1205 | closed, with a relevant comment. |
|
1206 | 1206 | """ |
|
1207 | 1207 | pull_request = PullRequest.get_or_404( |
|
1208 | 1208 | self.request.matchdict['pull_request_id']) |
|
1209 | 1209 | _ = self.request.translate |
|
1210 | 1210 | |
|
1211 | 1211 | if pull_request.is_state_changing(): |
|
1212 | 1212 | log.debug('show: forbidden because pull request is in state %s', |
|
1213 | 1213 | pull_request.pull_request_state) |
|
1214 | 1214 | msg = _(u'Cannot merge pull requests in state other than `{}`. ' |
|
1215 | 1215 | u'Current state is: `{}`').format(PullRequest.STATE_CREATED, |
|
1216 | 1216 | pull_request.pull_request_state) |
|
1217 | 1217 | h.flash(msg, category='error') |
|
1218 | 1218 | raise HTTPFound( |
|
1219 | 1219 | h.route_path('pullrequest_show', |
|
1220 | 1220 | repo_name=pull_request.target_repo.repo_name, |
|
1221 | 1221 | pull_request_id=pull_request.pull_request_id)) |
|
1222 | 1222 | |
|
1223 | 1223 | self.load_default_context() |
|
1224 | 1224 | |
|
1225 | 1225 | with pull_request.set_state(PullRequest.STATE_UPDATING): |
|
1226 | 1226 | check = MergeCheck.validate( |
|
1227 | 1227 | pull_request, auth_user=self._rhodecode_user, |
|
1228 | 1228 | translator=self.request.translate) |
|
1229 | 1229 | merge_possible = not check.failed |
|
1230 | 1230 | |
|
1231 | 1231 | for err_type, error_msg in check.errors: |
|
1232 | 1232 | h.flash(error_msg, category=err_type) |
|
1233 | 1233 | |
|
1234 | 1234 | if merge_possible: |
|
1235 | 1235 | log.debug("Pre-conditions checked, trying to merge.") |
|
1236 | 1236 | extras = vcs_operation_context( |
|
1237 | 1237 | self.request.environ, repo_name=pull_request.target_repo.repo_name, |
|
1238 | 1238 | username=self._rhodecode_db_user.username, action='push', |
|
1239 | 1239 | scm=pull_request.target_repo.repo_type) |
|
1240 | 1240 | with pull_request.set_state(PullRequest.STATE_UPDATING): |
|
1241 | 1241 | self._merge_pull_request( |
|
1242 | 1242 | pull_request, self._rhodecode_db_user, extras) |
|
1243 | 1243 | else: |
|
1244 | 1244 | log.debug("Pre-conditions failed, NOT merging.") |
|
1245 | 1245 | |
|
1246 | 1246 | raise HTTPFound( |
|
1247 | 1247 | h.route_path('pullrequest_show', |
|
1248 | 1248 | repo_name=pull_request.target_repo.repo_name, |
|
1249 | 1249 | pull_request_id=pull_request.pull_request_id)) |
|
1250 | 1250 | |
|
1251 | 1251 | def _merge_pull_request(self, pull_request, user, extras): |
|
1252 | 1252 | _ = self.request.translate |
|
1253 | 1253 | merge_resp = PullRequestModel().merge_repo(pull_request, user, extras=extras) |
|
1254 | 1254 | |
|
1255 | 1255 | if merge_resp.executed: |
|
1256 | 1256 | log.debug("The merge was successful, closing the pull request.") |
|
1257 | 1257 | PullRequestModel().close_pull_request( |
|
1258 | 1258 | pull_request.pull_request_id, user) |
|
1259 | 1259 | Session().commit() |
|
1260 | 1260 | msg = _('Pull request was successfully merged and closed.') |
|
1261 | 1261 | h.flash(msg, category='success') |
|
1262 | 1262 | else: |
|
1263 | 1263 | log.debug( |
|
1264 | 1264 | "The merge was not successful. Merge response: %s", merge_resp) |
|
1265 | 1265 | msg = merge_resp.merge_status_message |
|
1266 | 1266 | h.flash(msg, category='error') |
|
1267 | 1267 | |
|
1268 | 1268 | def _update_reviewers(self, pull_request, review_members, reviewer_rules): |
|
1269 | 1269 | _ = self.request.translate |
|
1270 | 1270 | |
|
1271 | 1271 | get_default_reviewers_data, validate_default_reviewers = \ |
|
1272 | 1272 | PullRequestModel().get_reviewer_functions() |
|
1273 | 1273 | |
|
1274 | 1274 | try: |
|
1275 | 1275 | reviewers = validate_default_reviewers(review_members, reviewer_rules) |
|
1276 | 1276 | except ValueError as e: |
|
1277 | 1277 | log.error('Reviewers Validation: {}'.format(e)) |
|
1278 | 1278 | h.flash(e, category='error') |
|
1279 | 1279 | return |
|
1280 | 1280 | |
|
1281 | 1281 | old_calculated_status = pull_request.calculated_review_status() |
|
1282 | 1282 | PullRequestModel().update_reviewers( |
|
1283 | 1283 | pull_request, reviewers, self._rhodecode_user) |
|
1284 | 1284 | h.flash(_('Pull request reviewers updated.'), category='success') |
|
1285 | 1285 | Session().commit() |
|
1286 | 1286 | |
|
1287 | 1287 | # trigger status changed if change in reviewers changes the status |
|
1288 | 1288 | calculated_status = pull_request.calculated_review_status() |
|
1289 | 1289 | if old_calculated_status != calculated_status: |
|
1290 | 1290 | PullRequestModel().trigger_pull_request_hook( |
|
1291 | 1291 | pull_request, self._rhodecode_user, 'review_status_change', |
|
1292 | 1292 | data={'status': calculated_status}) |
|
1293 | 1293 | |
|
1294 | 1294 | @LoginRequired() |
|
1295 | 1295 | @NotAnonymous() |
|
1296 | 1296 | @HasRepoPermissionAnyDecorator( |
|
1297 | 1297 | 'repository.read', 'repository.write', 'repository.admin') |
|
1298 | 1298 | @CSRFRequired() |
|
1299 | 1299 | @view_config( |
|
1300 | 1300 | route_name='pullrequest_delete', request_method='POST', |
|
1301 | 1301 | renderer='json_ext') |
|
1302 | 1302 | def pull_request_delete(self): |
|
1303 | 1303 | _ = self.request.translate |
|
1304 | 1304 | |
|
1305 | 1305 | pull_request = PullRequest.get_or_404( |
|
1306 | 1306 | self.request.matchdict['pull_request_id']) |
|
1307 | 1307 | self.load_default_context() |
|
1308 | 1308 | |
|
1309 | 1309 | pr_closed = pull_request.is_closed() |
|
1310 | 1310 | allowed_to_delete = PullRequestModel().check_user_delete( |
|
1311 | 1311 | pull_request, self._rhodecode_user) and not pr_closed |
|
1312 | 1312 | |
|
1313 | 1313 | # only owner can delete it ! |
|
1314 | 1314 | if allowed_to_delete: |
|
1315 | 1315 | PullRequestModel().delete(pull_request, self._rhodecode_user) |
|
1316 | 1316 | Session().commit() |
|
1317 | 1317 | h.flash(_('Successfully deleted pull request'), |
|
1318 | 1318 | category='success') |
|
1319 | 1319 | raise HTTPFound(h.route_path('pullrequest_show_all', |
|
1320 | 1320 | repo_name=self.db_repo_name)) |
|
1321 | 1321 | |
|
1322 | 1322 | log.warning('user %s tried to delete pull request without access', |
|
1323 | 1323 | self._rhodecode_user) |
|
1324 | 1324 | raise HTTPNotFound() |
|
1325 | 1325 | |
|
1326 | 1326 | @LoginRequired() |
|
1327 | 1327 | @NotAnonymous() |
|
1328 | 1328 | @HasRepoPermissionAnyDecorator( |
|
1329 | 1329 | 'repository.read', 'repository.write', 'repository.admin') |
|
1330 | 1330 | @CSRFRequired() |
|
1331 | 1331 | @view_config( |
|
1332 | 1332 | route_name='pullrequest_comment_create', request_method='POST', |
|
1333 | 1333 | renderer='json_ext') |
|
1334 | 1334 | def pull_request_comment_create(self): |
|
1335 | 1335 | _ = self.request.translate |
|
1336 | 1336 | |
|
1337 | 1337 | pull_request = PullRequest.get_or_404( |
|
1338 | 1338 | self.request.matchdict['pull_request_id']) |
|
1339 | 1339 | pull_request_id = pull_request.pull_request_id |
|
1340 | 1340 | |
|
1341 | 1341 | if pull_request.is_closed(): |
|
1342 | 1342 | log.debug('comment: forbidden because pull request is closed') |
|
1343 | 1343 | raise HTTPForbidden() |
|
1344 | 1344 | |
|
1345 | 1345 | allowed_to_comment = PullRequestModel().check_user_comment( |
|
1346 | 1346 | pull_request, self._rhodecode_user) |
|
1347 | 1347 | if not allowed_to_comment: |
|
1348 | 1348 | log.debug( |
|
1349 | 1349 | 'comment: forbidden because pull request is from forbidden repo') |
|
1350 | 1350 | raise HTTPForbidden() |
|
1351 | 1351 | |
|
1352 | 1352 | c = self.load_default_context() |
|
1353 | 1353 | |
|
1354 | 1354 | status = self.request.POST.get('changeset_status', None) |
|
1355 | 1355 | text = self.request.POST.get('text') |
|
1356 | 1356 | comment_type = self.request.POST.get('comment_type') |
|
1357 | 1357 | resolves_comment_id = self.request.POST.get('resolves_comment_id', None) |
|
1358 | 1358 | close_pull_request = self.request.POST.get('close_pull_request') |
|
1359 | 1359 | |
|
1360 | 1360 | # the logic here should work like following, if we submit close |
|
1361 | 1361 | # pr comment, use `close_pull_request_with_comment` function |
|
1362 | 1362 | # else handle regular comment logic |
|
1363 | 1363 | |
|
1364 | 1364 | if close_pull_request: |
|
1365 | 1365 | # only owner or admin or person with write permissions |
|
1366 | 1366 | allowed_to_close = PullRequestModel().check_user_update( |
|
1367 | 1367 | pull_request, self._rhodecode_user) |
|
1368 | 1368 | if not allowed_to_close: |
|
1369 | 1369 | log.debug('comment: forbidden because not allowed to close ' |
|
1370 | 1370 | 'pull request %s', pull_request_id) |
|
1371 | 1371 | raise HTTPForbidden() |
|
1372 | 1372 | |
|
1373 | 1373 | # This also triggers `review_status_change` |
|
1374 | 1374 | comment, status = PullRequestModel().close_pull_request_with_comment( |
|
1375 | 1375 | pull_request, self._rhodecode_user, self.db_repo, message=text, |
|
1376 | 1376 | auth_user=self._rhodecode_user) |
|
1377 | 1377 | Session().flush() |
|
1378 | 1378 | |
|
1379 | 1379 | PullRequestModel().trigger_pull_request_hook( |
|
1380 | 1380 | pull_request, self._rhodecode_user, 'comment', |
|
1381 | 1381 | data={'comment': comment}) |
|
1382 | 1382 | |
|
1383 | 1383 | else: |
|
1384 | 1384 | # regular comment case, could be inline, or one with status. |
|
1385 | 1385 | # for that one we check also permissions |
|
1386 | 1386 | |
|
1387 | 1387 | allowed_to_change_status = PullRequestModel().check_user_change_status( |
|
1388 | 1388 | pull_request, self._rhodecode_user) |
|
1389 | 1389 | |
|
1390 | 1390 | if status and allowed_to_change_status: |
|
1391 | 1391 | message = (_('Status change %(transition_icon)s %(status)s') |
|
1392 | 1392 | % {'transition_icon': '>', |
|
1393 | 1393 | 'status': ChangesetStatus.get_status_lbl(status)}) |
|
1394 | 1394 | text = text or message |
|
1395 | 1395 | |
|
1396 | 1396 | comment = CommentsModel().create( |
|
1397 | 1397 | text=text, |
|
1398 | 1398 | repo=self.db_repo.repo_id, |
|
1399 | 1399 | user=self._rhodecode_user.user_id, |
|
1400 | 1400 | pull_request=pull_request, |
|
1401 | 1401 | f_path=self.request.POST.get('f_path'), |
|
1402 | 1402 | line_no=self.request.POST.get('line'), |
|
1403 | 1403 | status_change=(ChangesetStatus.get_status_lbl(status) |
|
1404 | 1404 | if status and allowed_to_change_status else None), |
|
1405 | 1405 | status_change_type=(status |
|
1406 | 1406 | if status and allowed_to_change_status else None), |
|
1407 | 1407 | comment_type=comment_type, |
|
1408 | 1408 | resolves_comment_id=resolves_comment_id, |
|
1409 | 1409 | auth_user=self._rhodecode_user |
|
1410 | 1410 | ) |
|
1411 | 1411 | |
|
1412 | 1412 | if allowed_to_change_status: |
|
1413 | 1413 | # calculate old status before we change it |
|
1414 | 1414 | old_calculated_status = pull_request.calculated_review_status() |
|
1415 | 1415 | |
|
1416 | 1416 | # get status if set ! |
|
1417 | 1417 | if status: |
|
1418 | 1418 | ChangesetStatusModel().set_status( |
|
1419 | 1419 | self.db_repo.repo_id, |
|
1420 | 1420 | status, |
|
1421 | 1421 | self._rhodecode_user.user_id, |
|
1422 | 1422 | comment, |
|
1423 | 1423 | pull_request=pull_request |
|
1424 | 1424 | ) |
|
1425 | 1425 | |
|
1426 | 1426 | Session().flush() |
|
1427 | 1427 | # this is somehow required to get access to some relationship |
|
1428 | 1428 | # loaded on comment |
|
1429 | 1429 | Session().refresh(comment) |
|
1430 | 1430 | |
|
1431 | 1431 | PullRequestModel().trigger_pull_request_hook( |
|
1432 | 1432 | pull_request, self._rhodecode_user, 'comment', |
|
1433 | 1433 | data={'comment': comment}) |
|
1434 | 1434 | |
|
1435 | 1435 | # we now calculate the status of pull request, and based on that |
|
1436 | 1436 | # calculation we set the commits status |
|
1437 | 1437 | calculated_status = pull_request.calculated_review_status() |
|
1438 | 1438 | if old_calculated_status != calculated_status: |
|
1439 | 1439 | PullRequestModel().trigger_pull_request_hook( |
|
1440 | 1440 | pull_request, self._rhodecode_user, 'review_status_change', |
|
1441 | 1441 | data={'status': calculated_status}) |
|
1442 | 1442 | |
|
1443 | 1443 | Session().commit() |
|
1444 | 1444 | |
|
1445 | 1445 | data = { |
|
1446 | 1446 | 'target_id': h.safeid(h.safe_unicode( |
|
1447 | 1447 | self.request.POST.get('f_path'))), |
|
1448 | 1448 | } |
|
1449 | 1449 | if comment: |
|
1450 | 1450 | c.co = comment |
|
1451 | 1451 | rendered_comment = render( |
|
1452 | 1452 | 'rhodecode:templates/changeset/changeset_comment_block.mako', |
|
1453 | 1453 | self._get_template_context(c), self.request) |
|
1454 | 1454 | |
|
1455 | 1455 | data.update(comment.get_dict()) |
|
1456 | 1456 | data.update({'rendered_text': rendered_comment}) |
|
1457 | 1457 | |
|
1458 | 1458 | return data |
|
1459 | 1459 | |
|
1460 | 1460 | @LoginRequired() |
|
1461 | 1461 | @NotAnonymous() |
|
1462 | 1462 | @HasRepoPermissionAnyDecorator( |
|
1463 | 1463 | 'repository.read', 'repository.write', 'repository.admin') |
|
1464 | 1464 | @CSRFRequired() |
|
1465 | 1465 | @view_config( |
|
1466 | 1466 | route_name='pullrequest_comment_delete', request_method='POST', |
|
1467 | 1467 | renderer='json_ext') |
|
1468 | 1468 | def pull_request_comment_delete(self): |
|
1469 | 1469 | pull_request = PullRequest.get_or_404( |
|
1470 | 1470 | self.request.matchdict['pull_request_id']) |
|
1471 | 1471 | |
|
1472 | 1472 | comment = ChangesetComment.get_or_404( |
|
1473 | 1473 | self.request.matchdict['comment_id']) |
|
1474 | 1474 | comment_id = comment.comment_id |
|
1475 | 1475 | |
|
1476 | if comment.immutable: | |
|
1477 | # don't allow deleting comments that are immutable | |
|
1478 | raise HTTPForbidden() | |
|
1479 | ||
|
1476 | 1480 | if pull_request.is_closed(): |
|
1477 | 1481 | log.debug('comment: forbidden because pull request is closed') |
|
1478 | 1482 | raise HTTPForbidden() |
|
1479 | 1483 | |
|
1480 | 1484 | if not comment: |
|
1481 | 1485 | log.debug('Comment with id:%s not found, skipping', comment_id) |
|
1482 | 1486 | # comment already deleted in another call probably |
|
1483 | 1487 | return True |
|
1484 | 1488 | |
|
1485 | 1489 | if comment.pull_request.is_closed(): |
|
1486 | 1490 | # don't allow deleting comments on closed pull request |
|
1487 | 1491 | raise HTTPForbidden() |
|
1488 | 1492 | |
|
1489 | 1493 | is_repo_admin = h.HasRepoPermissionAny('repository.admin')(self.db_repo_name) |
|
1490 | 1494 | super_admin = h.HasPermissionAny('hg.admin')() |
|
1491 | 1495 | comment_owner = comment.author.user_id == self._rhodecode_user.user_id |
|
1492 | 1496 | is_repo_comment = comment.repo.repo_name == self.db_repo_name |
|
1493 | 1497 | comment_repo_admin = is_repo_admin and is_repo_comment |
|
1494 | 1498 | |
|
1495 | 1499 | if super_admin or comment_owner or comment_repo_admin: |
|
1496 | 1500 | old_calculated_status = comment.pull_request.calculated_review_status() |
|
1497 | 1501 | CommentsModel().delete(comment=comment, auth_user=self._rhodecode_user) |
|
1498 | 1502 | Session().commit() |
|
1499 | 1503 | calculated_status = comment.pull_request.calculated_review_status() |
|
1500 | 1504 | if old_calculated_status != calculated_status: |
|
1501 | 1505 | PullRequestModel().trigger_pull_request_hook( |
|
1502 | 1506 | comment.pull_request, self._rhodecode_user, 'review_status_change', |
|
1503 | 1507 | data={'status': calculated_status}) |
|
1504 | 1508 | return True |
|
1505 | 1509 | else: |
|
1506 | 1510 | log.warning('No permissions for user %s to delete comment_id: %s', |
|
1507 | 1511 | self._rhodecode_db_user, comment_id) |
|
1508 | 1512 | raise HTTPNotFound() |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,426 +1,426 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | ## usage: |
|
3 | 3 | ## <%namespace name="comment" file="/changeset/changeset_file_comment.mako"/> |
|
4 | 4 | ## ${comment.comment_block(comment)} |
|
5 | 5 | ## |
|
6 | 6 | <%namespace name="base" file="/base/base.mako"/> |
|
7 | 7 | |
|
8 | 8 | <%def name="comment_block(comment, inline=False, active_pattern_entries=None)"> |
|
9 | 9 | <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %> |
|
10 | 10 | <% latest_ver = len(getattr(c, 'versions', [])) %> |
|
11 | 11 | % if inline: |
|
12 | 12 | <% outdated_at_ver = comment.outdated_at_version(getattr(c, 'at_version_num', None)) %> |
|
13 | 13 | % else: |
|
14 | 14 | <% outdated_at_ver = comment.older_than_version(getattr(c, 'at_version_num', None)) %> |
|
15 | 15 | % endif |
|
16 | 16 | |
|
17 | 17 | <div class="comment |
|
18 | 18 | ${'comment-inline' if inline else 'comment-general'} |
|
19 | 19 | ${'comment-outdated' if outdated_at_ver else 'comment-current'}" |
|
20 | 20 | id="comment-${comment.comment_id}" |
|
21 | 21 | line="${comment.line_no}" |
|
22 | 22 | data-comment-id="${comment.comment_id}" |
|
23 | 23 | data-comment-type="${comment.comment_type}" |
|
24 | 24 | data-comment-line-no="${comment.line_no}" |
|
25 | 25 | data-comment-inline=${h.json.dumps(inline)} |
|
26 | 26 | style="${'display: none;' if outdated_at_ver else ''}"> |
|
27 | 27 | |
|
28 | 28 | <div class="meta"> |
|
29 | 29 | <div class="comment-type-label"> |
|
30 | 30 | <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}" title="line: ${comment.line_no}"> |
|
31 | 31 | % if comment.comment_type == 'todo': |
|
32 | 32 | % if comment.resolved: |
|
33 | 33 | <div class="resolved tooltip" title="${_('Resolved by comment #{}').format(comment.resolved.comment_id)}"> |
|
34 | 34 | <a href="#comment-${comment.resolved.comment_id}">${comment.comment_type}</a> |
|
35 | 35 | </div> |
|
36 | 36 | % else: |
|
37 | 37 | <div class="resolved tooltip" style="display: none"> |
|
38 | 38 | <span>${comment.comment_type}</span> |
|
39 | 39 | </div> |
|
40 | 40 | <div class="resolve tooltip" onclick="return Rhodecode.comments.createResolutionComment(${comment.comment_id});" title="${_('Click to resolve this comment')}"> |
|
41 | 41 | ${comment.comment_type} |
|
42 | 42 | </div> |
|
43 | 43 | % endif |
|
44 | 44 | % else: |
|
45 | 45 | % if comment.resolved_comment: |
|
46 | 46 | fix |
|
47 | 47 | <a href="#comment-${comment.resolved_comment.comment_id}" onclick="Rhodecode.comments.scrollToComment($('#comment-${comment.resolved_comment.comment_id}'), 0, ${h.json.dumps(comment.resolved_comment.outdated)})"> |
|
48 | 48 | <span style="text-decoration: line-through">#${comment.resolved_comment.comment_id}</span> |
|
49 | 49 | </a> |
|
50 | 50 | % else: |
|
51 | 51 | ${comment.comment_type or 'note'} |
|
52 | 52 | % endif |
|
53 | 53 | % endif |
|
54 | 54 | </div> |
|
55 | 55 | </div> |
|
56 | 56 | |
|
57 | 57 | <div class="author ${'author-inline' if inline else 'author-general'}"> |
|
58 | 58 | ${base.gravatar_with_user(comment.author.email, 16, tooltip=True)} |
|
59 | 59 | </div> |
|
60 | 60 | <div class="date"> |
|
61 | 61 | ${h.age_component(comment.modified_at, time_is_local=True)} |
|
62 | 62 | </div> |
|
63 | 63 | % if inline: |
|
64 | 64 | <span></span> |
|
65 | 65 | % else: |
|
66 | 66 | <div class="status-change"> |
|
67 | 67 | % if comment.pull_request: |
|
68 | 68 | <a href="${h.route_path('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id)}"> |
|
69 | 69 | % if comment.status_change: |
|
70 | 70 | ${_('pull request !{}').format(comment.pull_request.pull_request_id)}: |
|
71 | 71 | % else: |
|
72 | 72 | ${_('pull request !{}').format(comment.pull_request.pull_request_id)} |
|
73 | 73 | % endif |
|
74 | 74 | </a> |
|
75 | 75 | % else: |
|
76 | 76 | % if comment.status_change: |
|
77 | 77 | ${_('Status change on commit')}: |
|
78 | 78 | % endif |
|
79 | 79 | % endif |
|
80 | 80 | </div> |
|
81 | 81 | % endif |
|
82 | 82 | |
|
83 | 83 | % if comment.status_change: |
|
84 | 84 | <i class="icon-circle review-status-${comment.status_change[0].status}"></i> |
|
85 | 85 | <div title="${_('Commit status')}" class="changeset-status-lbl"> |
|
86 | 86 | ${comment.status_change[0].status_lbl} |
|
87 | 87 | </div> |
|
88 | 88 | % endif |
|
89 | 89 | |
|
90 | 90 | <a class="permalink" href="#comment-${comment.comment_id}"> ¶</a> |
|
91 | 91 | |
|
92 | 92 | <div class="comment-links-block"> |
|
93 | 93 | % if comment.pull_request and comment.pull_request.author.user_id == comment.author.user_id: |
|
94 | 94 | <span class="tag authortag tooltip" title="${_('Pull request author')}"> |
|
95 | 95 | ${_('author')} |
|
96 | 96 | </span> |
|
97 | 97 | | |
|
98 | 98 | % endif |
|
99 | 99 | % if inline: |
|
100 | 100 | <div class="pr-version-inline"> |
|
101 | 101 | <a href="${request.current_route_path(_query=dict(version=comment.pull_request_version_id), _anchor='comment-{}'.format(comment.comment_id))}"> |
|
102 | 102 | % if outdated_at_ver: |
|
103 | 103 | <code class="pr-version-num" title="${_('Outdated comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
104 | 104 | outdated ${'v{}'.format(pr_index_ver)} | |
|
105 | 105 | </code> |
|
106 | 106 | % elif pr_index_ver: |
|
107 | 107 | <code class="pr-version-num" title="${_('Comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
108 | 108 | ${'v{}'.format(pr_index_ver)} | |
|
109 | 109 | </code> |
|
110 | 110 | % endif |
|
111 | 111 | </a> |
|
112 | 112 | </div> |
|
113 | 113 | % else: |
|
114 | 114 | % if comment.pull_request_version_id and pr_index_ver: |
|
115 | 115 | | |
|
116 | 116 | <div class="pr-version"> |
|
117 | 117 | % if comment.outdated: |
|
118 | 118 | <a href="?version=${comment.pull_request_version_id}#comment-${comment.comment_id}"> |
|
119 | 119 | ${_('Outdated comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)} |
|
120 | 120 | </a> |
|
121 | 121 | % else: |
|
122 | 122 | <div title="${_('Comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
123 | 123 | <a href="${h.route_path('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id, version=comment.pull_request_version_id)}"> |
|
124 | 124 | <code class="pr-version-num"> |
|
125 | 125 | ${'v{}'.format(pr_index_ver)} |
|
126 | 126 | </code> |
|
127 | 127 | </a> |
|
128 | 128 | </div> |
|
129 | 129 | % endif |
|
130 | 130 | </div> |
|
131 | 131 | % endif |
|
132 | 132 | % endif |
|
133 | 133 | |
|
134 | 134 | ## show delete comment if it's not a PR (regular comments) or it's PR that is not closed |
|
135 | 135 | ## only super-admin, repo admin OR comment owner can delete, also hide delete if currently viewed comment is outdated |
|
136 | 136 | %if not outdated_at_ver and (not comment.pull_request or (comment.pull_request and not comment.pull_request.is_closed())): |
|
137 | 137 | ## permissions to delete |
|
138 | %if c.is_super_admin or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or comment.author.user_id == c.rhodecode_user.user_id: | |
|
138 | %if comment.immutable is False and (c.is_super_admin or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or comment.author.user_id == c.rhodecode_user.user_id): | |
|
139 | 139 | ## TODO: dan: add edit comment here |
|
140 | 140 | <a onclick="return Rhodecode.comments.deleteComment(this);" class="delete-comment"> ${_('Delete')}</a> |
|
141 | 141 | %else: |
|
142 | 142 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
143 | 143 | %endif |
|
144 | 144 | %else: |
|
145 | 145 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
146 | 146 | %endif |
|
147 | 147 | |
|
148 | 148 | % if outdated_at_ver: |
|
149 | 149 | | <a onclick="return Rhodecode.comments.prevOutdatedComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
150 | 150 | | <a onclick="return Rhodecode.comments.nextOutdatedComment(this);" class="next-comment"> ${_('Next')}</a> |
|
151 | 151 | % else: |
|
152 | 152 | | <a onclick="return Rhodecode.comments.prevComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
153 | 153 | | <a onclick="return Rhodecode.comments.nextComment(this);" class="next-comment"> ${_('Next')}</a> |
|
154 | 154 | % endif |
|
155 | 155 | |
|
156 | 156 | </div> |
|
157 | 157 | </div> |
|
158 | 158 | <div class="text"> |
|
159 | 159 | ${h.render(comment.text, renderer=comment.renderer, mentions=True, repo_name=getattr(c, 'repo_name', None), active_pattern_entries=active_pattern_entries)} |
|
160 | 160 | </div> |
|
161 | 161 | |
|
162 | 162 | </div> |
|
163 | 163 | </%def> |
|
164 | 164 | |
|
165 | 165 | ## generate main comments |
|
166 | 166 | <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)"> |
|
167 | 167 | <% |
|
168 | 168 | active_pattern_entries = h.get_active_pattern_entries(getattr(c, 'repo_name', None)) |
|
169 | 169 | %> |
|
170 | 170 | |
|
171 | 171 | <div class="general-comments" id="comments"> |
|
172 | 172 | %for comment in comments: |
|
173 | 173 | <div id="comment-tr-${comment.comment_id}"> |
|
174 | 174 | ## only render comments that are not from pull request, or from |
|
175 | 175 | ## pull request and a status change |
|
176 | 176 | %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request: |
|
177 | 177 | ${comment_block(comment, active_pattern_entries=active_pattern_entries)} |
|
178 | 178 | %endif |
|
179 | 179 | </div> |
|
180 | 180 | %endfor |
|
181 | 181 | ## to anchor ajax comments |
|
182 | 182 | <div id="injected_page_comments"></div> |
|
183 | 183 | </div> |
|
184 | 184 | </%def> |
|
185 | 185 | |
|
186 | 186 | |
|
187 | 187 | <%def name="comments(post_url, cur_status, is_pull_request=False, is_compare=False, change_status=True, form_extras=None)"> |
|
188 | 188 | |
|
189 | 189 | <div class="comments"> |
|
190 | 190 | <% |
|
191 | 191 | if is_pull_request: |
|
192 | 192 | placeholder = _('Leave a comment on this Pull Request.') |
|
193 | 193 | elif is_compare: |
|
194 | 194 | placeholder = _('Leave a comment on {} commits in this range.').format(len(form_extras)) |
|
195 | 195 | else: |
|
196 | 196 | placeholder = _('Leave a comment on this Commit.') |
|
197 | 197 | %> |
|
198 | 198 | |
|
199 | 199 | % if c.rhodecode_user.username != h.DEFAULT_USER: |
|
200 | 200 | <div class="js-template" id="cb-comment-general-form-template"> |
|
201 | 201 | ## template generated for injection |
|
202 | 202 | ${comment_form(form_type='general', review_statuses=c.commit_statuses, form_extras=form_extras)} |
|
203 | 203 | </div> |
|
204 | 204 | |
|
205 | 205 | <div id="cb-comment-general-form-placeholder" class="comment-form ac"> |
|
206 | 206 | ## inject form here |
|
207 | 207 | </div> |
|
208 | 208 | <script type="text/javascript"> |
|
209 | 209 | var lineNo = 'general'; |
|
210 | 210 | var resolvesCommentId = null; |
|
211 | 211 | var generalCommentForm = Rhodecode.comments.createGeneralComment( |
|
212 | 212 | lineNo, "${placeholder}", resolvesCommentId); |
|
213 | 213 | |
|
214 | 214 | // set custom success callback on rangeCommit |
|
215 | 215 | % if is_compare: |
|
216 | 216 | generalCommentForm.setHandleFormSubmit(function(o) { |
|
217 | 217 | var self = generalCommentForm; |
|
218 | 218 | |
|
219 | 219 | var text = self.cm.getValue(); |
|
220 | 220 | var status = self.getCommentStatus(); |
|
221 | 221 | var commentType = self.getCommentType(); |
|
222 | 222 | |
|
223 | 223 | if (text === "" && !status) { |
|
224 | 224 | return; |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | // we can pick which commits we want to make the comment by |
|
228 | 228 | // selecting them via click on preview pane, this will alter the hidden inputs |
|
229 | 229 | var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0; |
|
230 | 230 | |
|
231 | 231 | var commitIds = []; |
|
232 | 232 | $('#changeset_compare_view_content .compare_select').each(function(el) { |
|
233 | 233 | var commitId = this.id.replace('row-', ''); |
|
234 | 234 | if ($(this).hasClass('hl') || !cherryPicked) { |
|
235 | 235 | $("input[data-commit-id='{0}']".format(commitId)).val(commitId); |
|
236 | 236 | commitIds.push(commitId); |
|
237 | 237 | } else { |
|
238 | 238 | $("input[data-commit-id='{0}']".format(commitId)).val('') |
|
239 | 239 | } |
|
240 | 240 | }); |
|
241 | 241 | |
|
242 | 242 | self.setActionButtonsDisabled(true); |
|
243 | 243 | self.cm.setOption("readOnly", true); |
|
244 | 244 | var postData = { |
|
245 | 245 | 'text': text, |
|
246 | 246 | 'changeset_status': status, |
|
247 | 247 | 'comment_type': commentType, |
|
248 | 248 | 'commit_ids': commitIds, |
|
249 | 249 | 'csrf_token': CSRF_TOKEN |
|
250 | 250 | }; |
|
251 | 251 | |
|
252 | 252 | var submitSuccessCallback = function(o) { |
|
253 | 253 | location.reload(true); |
|
254 | 254 | }; |
|
255 | 255 | var submitFailCallback = function(){ |
|
256 | 256 | self.resetCommentFormState(text) |
|
257 | 257 | }; |
|
258 | 258 | self.submitAjaxPOST( |
|
259 | 259 | self.submitUrl, postData, submitSuccessCallback, submitFailCallback); |
|
260 | 260 | }); |
|
261 | 261 | % endif |
|
262 | 262 | |
|
263 | 263 | </script> |
|
264 | 264 | % else: |
|
265 | 265 | ## form state when not logged in |
|
266 | 266 | <div class="comment-form ac"> |
|
267 | 267 | |
|
268 | 268 | <div class="comment-area"> |
|
269 | 269 | <div class="comment-area-header"> |
|
270 | 270 | <ul class="nav-links clearfix"> |
|
271 | 271 | <li class="active"> |
|
272 | 272 | <a class="disabled" href="#edit-btn" disabled="disabled" onclick="return false">${_('Write')}</a> |
|
273 | 273 | </li> |
|
274 | 274 | <li class=""> |
|
275 | 275 | <a class="disabled" href="#preview-btn" disabled="disabled" onclick="return false">${_('Preview')}</a> |
|
276 | 276 | </li> |
|
277 | 277 | </ul> |
|
278 | 278 | </div> |
|
279 | 279 | |
|
280 | 280 | <div class="comment-area-write" style="display: block;"> |
|
281 | 281 | <div id="edit-container"> |
|
282 | 282 | <div style="padding: 40px 0"> |
|
283 | 283 | ${_('You need to be logged in to leave comments.')} |
|
284 | 284 | <a href="${h.route_path('login', _query={'came_from': h.current_route_path(request)})}">${_('Login now')}</a> |
|
285 | 285 | </div> |
|
286 | 286 | </div> |
|
287 | 287 | <div id="preview-container" class="clearfix" style="display: none;"> |
|
288 | 288 | <div id="preview-box" class="preview-box"></div> |
|
289 | 289 | </div> |
|
290 | 290 | </div> |
|
291 | 291 | |
|
292 | 292 | <div class="comment-area-footer"> |
|
293 | 293 | <div class="toolbar"> |
|
294 | 294 | <div class="toolbar-text"> |
|
295 | 295 | </div> |
|
296 | 296 | </div> |
|
297 | 297 | </div> |
|
298 | 298 | </div> |
|
299 | 299 | |
|
300 | 300 | <div class="comment-footer"> |
|
301 | 301 | </div> |
|
302 | 302 | |
|
303 | 303 | </div> |
|
304 | 304 | % endif |
|
305 | 305 | |
|
306 | 306 | <script type="text/javascript"> |
|
307 | 307 | bindToggleButtons(); |
|
308 | 308 | </script> |
|
309 | 309 | </div> |
|
310 | 310 | </%def> |
|
311 | 311 | |
|
312 | 312 | |
|
313 | 313 | <%def name="comment_form(form_type, form_id='', lineno_id='{1}', review_statuses=None, form_extras=None)"> |
|
314 | 314 | |
|
315 | 315 | ## comment injected based on assumption that user is logged in |
|
316 | 316 | <form ${('id="{}"'.format(form_id) if form_id else '') |n} action="#" method="GET"> |
|
317 | 317 | |
|
318 | 318 | <div class="comment-area"> |
|
319 | 319 | <div class="comment-area-header"> |
|
320 | 320 | <div class="pull-left"> |
|
321 | 321 | <ul class="nav-links clearfix"> |
|
322 | 322 | <li class="active"> |
|
323 | 323 | <a href="#edit-btn" tabindex="-1" id="edit-btn_${lineno_id}">${_('Write')}</a> |
|
324 | 324 | </li> |
|
325 | 325 | <li class=""> |
|
326 | 326 | <a href="#preview-btn" tabindex="-1" id="preview-btn_${lineno_id}">${_('Preview')}</a> |
|
327 | 327 | </li> |
|
328 | 328 | </ul> |
|
329 | 329 | </div> |
|
330 | 330 | <div class="pull-right"> |
|
331 | 331 | <span class="comment-area-text">${_('Mark as')}:</span> |
|
332 | 332 | <select class="comment-type" id="comment_type_${lineno_id}" name="comment_type"> |
|
333 | 333 | % for val in c.visual.comment_types: |
|
334 | 334 | <option value="${val}">${val.upper()}</option> |
|
335 | 335 | % endfor |
|
336 | 336 | </select> |
|
337 | 337 | </div> |
|
338 | 338 | </div> |
|
339 | 339 | |
|
340 | 340 | <div class="comment-area-write" style="display: block;"> |
|
341 | 341 | <div id="edit-container_${lineno_id}"> |
|
342 | 342 | <textarea id="text_${lineno_id}" name="text" class="comment-block-ta ac-input"></textarea> |
|
343 | 343 | </div> |
|
344 | 344 | <div id="preview-container_${lineno_id}" class="clearfix" style="display: none;"> |
|
345 | 345 | <div id="preview-box_${lineno_id}" class="preview-box"></div> |
|
346 | 346 | </div> |
|
347 | 347 | </div> |
|
348 | 348 | |
|
349 | 349 | <div class="comment-area-footer comment-attachment-uploader"> |
|
350 | 350 | <div class="toolbar"> |
|
351 | 351 | |
|
352 | 352 | <div class="comment-attachment-text"> |
|
353 | 353 | <div class="dropzone-text"> |
|
354 | 354 | ${_("Drag'n Drop files here or")} <span class="link pick-attachment">${_('Choose your files')}</span>.<br> |
|
355 | 355 | </div> |
|
356 | 356 | <div class="dropzone-upload" style="display:none"> |
|
357 | 357 | <i class="icon-spin animate-spin"></i> ${_('uploading...')} |
|
358 | 358 | </div> |
|
359 | 359 | </div> |
|
360 | 360 | |
|
361 | 361 | ## comments dropzone template, empty on purpose |
|
362 | 362 | <div style="display: none" class="comment-attachment-uploader-template"> |
|
363 | 363 | <div class="dz-file-preview" style="margin: 0"> |
|
364 | 364 | <div class="dz-error-message"></div> |
|
365 | 365 | </div> |
|
366 | 366 | </div> |
|
367 | 367 | |
|
368 | 368 | </div> |
|
369 | 369 | </div> |
|
370 | 370 | </div> |
|
371 | 371 | |
|
372 | 372 | <div class="comment-footer"> |
|
373 | 373 | |
|
374 | 374 | ## inject extra inputs into the form |
|
375 | 375 | % if form_extras and isinstance(form_extras, (list, tuple)): |
|
376 | 376 | <div id="comment_form_extras"> |
|
377 | 377 | % for form_ex_el in form_extras: |
|
378 | 378 | ${form_ex_el|n} |
|
379 | 379 | % endfor |
|
380 | 380 | </div> |
|
381 | 381 | % endif |
|
382 | 382 | |
|
383 | 383 | <div class="action-buttons"> |
|
384 | 384 | % if form_type != 'inline': |
|
385 | 385 | <div class="action-buttons-extra"></div> |
|
386 | 386 | % endif |
|
387 | 387 | |
|
388 | 388 | <input class="btn btn-success comment-button-input" id="save_${lineno_id}" name="save" type="submit" value="${_('Comment')}"> |
|
389 | 389 | |
|
390 | 390 | ## inline for has a file, and line-number together with cancel hide button. |
|
391 | 391 | % if form_type == 'inline': |
|
392 | 392 | <input type="hidden" name="f_path" value="{0}"> |
|
393 | 393 | <input type="hidden" name="line" value="${lineno_id}"> |
|
394 | 394 | <button type="button" class="cb-comment-cancel" onclick="return Rhodecode.comments.cancelComment(this);"> |
|
395 | 395 | ${_('Cancel')} |
|
396 | 396 | </button> |
|
397 | 397 | % endif |
|
398 | 398 | </div> |
|
399 | 399 | |
|
400 | 400 | % if review_statuses: |
|
401 | 401 | <div class="status_box"> |
|
402 | 402 | <select id="change_status_${lineno_id}" name="changeset_status"> |
|
403 | 403 | <option></option> ## Placeholder |
|
404 | 404 | % for status, lbl in review_statuses: |
|
405 | 405 | <option value="${status}" data-status="${status}">${lbl}</option> |
|
406 | 406 | %if is_pull_request and change_status and status in ('approved', 'rejected'): |
|
407 | 407 | <option value="${status}_closed" data-status="${status}">${lbl} & ${_('Closed')}</option> |
|
408 | 408 | %endif |
|
409 | 409 | % endfor |
|
410 | 410 | </select> |
|
411 | 411 | </div> |
|
412 | 412 | % endif |
|
413 | 413 | |
|
414 | 414 | <div class="toolbar-text"> |
|
415 | 415 | <% renderer_url = '<a href="%s">%s</a>' % (h.route_url('%s_help' % c.visual.default_renderer), c.visual.default_renderer.upper()) %> |
|
416 | 416 | ${_('Comments parsed using {} syntax.').format(renderer_url)|n} <br/> |
|
417 | 417 | <span class="tooltip" title="${_('Use @username inside this text to send notification to this RhodeCode user')}">@mention</span> |
|
418 | 418 | ${_('and')} |
|
419 | 419 | <span class="tooltip" title="${_('Start typing with / for certain actions to be triggered via text box.')}">`/` autocomplete</span> |
|
420 | 420 | ${_('actions supported.')} |
|
421 | 421 | </div> |
|
422 | 422 | </div> |
|
423 | 423 | |
|
424 | 424 | </form> |
|
425 | 425 | |
|
426 | 426 | </%def> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now