@@ -1,587 +1,592 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
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 General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class IssuesController < ApplicationController |
|
19 | 19 | default_search_scope :issues |
|
20 | 20 | |
|
21 | 21 | before_action :find_issue, :only => [:show, :edit, :update] |
|
22 | 22 | before_action :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] |
|
23 | 23 | before_action :authorize, :except => [:index, :new, :create] |
|
24 | 24 | before_action :find_optional_project, :only => [:index, :new, :create] |
|
25 | 25 | before_action :build_new_issue_from_params, :only => [:new, :create] |
|
26 | 26 | accept_rss_auth :index, :show |
|
27 | 27 | accept_api_auth :index, :show, :create, :update, :destroy |
|
28 | 28 | |
|
29 | 29 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
30 | 30 | |
|
31 | 31 | helper :journals |
|
32 | 32 | helper :projects |
|
33 | 33 | helper :custom_fields |
|
34 | 34 | helper :issue_relations |
|
35 | 35 | helper :watchers |
|
36 | 36 | helper :attachments |
|
37 | 37 | helper :queries |
|
38 | 38 | include QueriesHelper |
|
39 | 39 | helper :repositories |
|
40 | 40 | helper :sort |
|
41 | 41 | include SortHelper |
|
42 | 42 | helper :timelog |
|
43 | 43 | |
|
44 | 44 | def index |
|
45 | 45 | retrieve_query |
|
46 | 46 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
47 | 47 | sort_update(@query.sortable_columns) |
|
48 | 48 | @query.sort_criteria = sort_criteria.to_a |
|
49 | 49 | |
|
50 | 50 | if @query.valid? |
|
51 | 51 | case params[:format] |
|
52 | 52 | when 'csv', 'pdf' |
|
53 | 53 | @limit = Setting.issues_export_limit.to_i |
|
54 | 54 | if params[:columns] == 'all' |
|
55 | 55 | @query.column_names = @query.available_inline_columns.map(&:name) |
|
56 | 56 | end |
|
57 | 57 | when 'atom' |
|
58 | 58 | @limit = Setting.feeds_limit.to_i |
|
59 | 59 | when 'xml', 'json' |
|
60 | 60 | @offset, @limit = api_offset_and_limit |
|
61 | 61 | @query.column_names = %w(author) |
|
62 | 62 | else |
|
63 | 63 | @limit = per_page_option |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | @issue_count = @query.issue_count |
|
67 | 67 | @issue_pages = Paginator.new @issue_count, @limit, params['page'] |
|
68 | 68 | @offset ||= @issue_pages.offset |
|
69 | 69 | @issues = @query.issues(:order => sort_clause, |
|
70 | 70 | :offset => @offset, |
|
71 | 71 | :limit => @limit) |
|
72 | 72 | @issue_count_by_group = @query.issue_count_by_group |
|
73 | 73 | |
|
74 | 74 | respond_to do |format| |
|
75 | 75 | format.html { render :template => 'issues/index', :layout => !request.xhr? } |
|
76 | 76 | format.api { |
|
77 | 77 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') |
|
78 | 78 | } |
|
79 | 79 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
80 | 80 | format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') } |
|
81 | 81 | format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' } |
|
82 | 82 | end |
|
83 | 83 | else |
|
84 | 84 | respond_to do |format| |
|
85 | 85 | format.html { render(:template => 'issues/index', :layout => !request.xhr?) } |
|
86 | 86 | format.any(:atom, :csv, :pdf) { head 422 } |
|
87 | 87 | format.api { render_validation_errors(@query) } |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | rescue ActiveRecord::RecordNotFound |
|
91 | 91 | render_404 |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def show |
|
95 | 95 | @journals = @issue.visible_journals_with_index |
|
96 | 96 | @changesets = @issue.changesets.visible.preload(:repository, :user).to_a |
|
97 | 97 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
98 | 98 | |
|
99 | 99 | if User.current.wants_comments_in_reverse_order? |
|
100 | 100 | @journals.reverse! |
|
101 | 101 | @changesets.reverse! |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | if User.current.allowed_to?(:view_time_entries, @project) | |
|
105 | Issue.load_visible_spent_hours([@issue]) | |
|
106 | Issue.load_visible_total_spent_hours([@issue]) | |
|
107 | end | |
|
108 | ||
|
104 | 109 | respond_to do |format| |
|
105 | 110 | format.html { |
|
106 | 111 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
107 | 112 | @priorities = IssuePriority.active |
|
108 | 113 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
109 | 114 | @relation = IssueRelation.new |
|
110 | 115 | retrieve_previous_and_next_issue_ids |
|
111 | 116 | render :template => 'issues/show' |
|
112 | 117 | } |
|
113 | 118 | format.api |
|
114 | 119 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } |
|
115 | 120 | format.pdf { |
|
116 | 121 | send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf" |
|
117 | 122 | } |
|
118 | 123 | end |
|
119 | 124 | end |
|
120 | 125 | |
|
121 | 126 | def new |
|
122 | 127 | respond_to do |format| |
|
123 | 128 | format.html { render :action => 'new', :layout => !request.xhr? } |
|
124 | 129 | format.js |
|
125 | 130 | end |
|
126 | 131 | end |
|
127 | 132 | |
|
128 | 133 | def create |
|
129 | 134 | unless User.current.allowed_to?(:add_issues, @issue.project, :global => true) |
|
130 | 135 | raise ::Unauthorized |
|
131 | 136 | end |
|
132 | 137 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
133 | 138 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
134 | 139 | if @issue.save |
|
135 | 140 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
136 | 141 | respond_to do |format| |
|
137 | 142 | format.html { |
|
138 | 143 | render_attachment_warning_if_needed(@issue) |
|
139 | 144 | flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) |
|
140 | 145 | redirect_after_create |
|
141 | 146 | } |
|
142 | 147 | format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } |
|
143 | 148 | end |
|
144 | 149 | return |
|
145 | 150 | else |
|
146 | 151 | respond_to do |format| |
|
147 | 152 | format.html { |
|
148 | 153 | if @issue.project.nil? |
|
149 | 154 | render_error :status => 422 |
|
150 | 155 | else |
|
151 | 156 | render :action => 'new' |
|
152 | 157 | end |
|
153 | 158 | } |
|
154 | 159 | format.api { render_validation_errors(@issue) } |
|
155 | 160 | end |
|
156 | 161 | end |
|
157 | 162 | end |
|
158 | 163 | |
|
159 | 164 | def edit |
|
160 | 165 | return unless update_issue_from_params |
|
161 | 166 | |
|
162 | 167 | respond_to do |format| |
|
163 | 168 | format.html { } |
|
164 | 169 | format.js |
|
165 | 170 | end |
|
166 | 171 | end |
|
167 | 172 | |
|
168 | 173 | def update |
|
169 | 174 | return unless update_issue_from_params |
|
170 | 175 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
171 | 176 | saved = false |
|
172 | 177 | begin |
|
173 | 178 | saved = save_issue_with_child_records |
|
174 | 179 | rescue ActiveRecord::StaleObjectError |
|
175 | 180 | @conflict = true |
|
176 | 181 | if params[:last_journal_id] |
|
177 | 182 | @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a |
|
178 | 183 | @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) |
|
179 | 184 | end |
|
180 | 185 | end |
|
181 | 186 | |
|
182 | 187 | if saved |
|
183 | 188 | render_attachment_warning_if_needed(@issue) |
|
184 | 189 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
185 | 190 | |
|
186 | 191 | respond_to do |format| |
|
187 | 192 | format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) } |
|
188 | 193 | format.api { render_api_ok } |
|
189 | 194 | end |
|
190 | 195 | else |
|
191 | 196 | respond_to do |format| |
|
192 | 197 | format.html { render :action => 'edit' } |
|
193 | 198 | format.api { render_validation_errors(@issue) } |
|
194 | 199 | end |
|
195 | 200 | end |
|
196 | 201 | end |
|
197 | 202 | |
|
198 | 203 | # Bulk edit/copy a set of issues |
|
199 | 204 | def bulk_edit |
|
200 | 205 | @issues.sort! |
|
201 | 206 | @copy = params[:copy].present? |
|
202 | 207 | @notes = params[:notes] |
|
203 | 208 | |
|
204 | 209 | if @copy |
|
205 | 210 | unless User.current.allowed_to?(:copy_issues, @projects) |
|
206 | 211 | raise ::Unauthorized |
|
207 | 212 | end |
|
208 | 213 | else |
|
209 | 214 | unless @issues.all?(&:attributes_editable?) |
|
210 | 215 | raise ::Unauthorized |
|
211 | 216 | end |
|
212 | 217 | end |
|
213 | 218 | |
|
214 | 219 | edited_issues = Issue.where(:id => @issues.map(&:id)).to_a |
|
215 | 220 | |
|
216 | 221 | @values_by_custom_field = {} |
|
217 | 222 | edited_issues.each do |issue| |
|
218 | 223 | issue.custom_field_values.each do |c| |
|
219 | 224 | if c.value_present? |
|
220 | 225 | @values_by_custom_field[c.custom_field] ||= [] |
|
221 | 226 | @values_by_custom_field[c.custom_field] << issue.id |
|
222 | 227 | end |
|
223 | 228 | end |
|
224 | 229 | end |
|
225 | 230 | |
|
226 | 231 | @allowed_projects = Issue.allowed_target_projects |
|
227 | 232 | if params[:issue] |
|
228 | 233 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} |
|
229 | 234 | if @target_project |
|
230 | 235 | target_projects = [@target_project] |
|
231 | 236 | edited_issues.each {|issue| issue.project = @target_project} |
|
232 | 237 | end |
|
233 | 238 | end |
|
234 | 239 | target_projects ||= @projects |
|
235 | 240 | |
|
236 | 241 | @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) |
|
237 | 242 | if params[:issue] |
|
238 | 243 | @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s} |
|
239 | 244 | if @target_tracker |
|
240 | 245 | edited_issues.each {|issue| issue.tracker = @target_tracker} |
|
241 | 246 | end |
|
242 | 247 | end |
|
243 | 248 | |
|
244 | 249 | if @copy |
|
245 | 250 | # Copied issues will get their default statuses |
|
246 | 251 | @available_statuses = [] |
|
247 | 252 | else |
|
248 | 253 | @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&) |
|
249 | 254 | end |
|
250 | 255 | if params[:issue] |
|
251 | 256 | @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s} |
|
252 | 257 | if @target_status |
|
253 | 258 | edited_issues.each {|issue| issue.status = @target_status} |
|
254 | 259 | end |
|
255 | 260 | end |
|
256 | 261 | |
|
257 | 262 | edited_issues.each do |issue| |
|
258 | 263 | issue.custom_field_values.each do |c| |
|
259 | 264 | if c.value_present? && @values_by_custom_field[c.custom_field] |
|
260 | 265 | @values_by_custom_field[c.custom_field].delete(issue.id) |
|
261 | 266 | end |
|
262 | 267 | end |
|
263 | 268 | end |
|
264 | 269 | @values_by_custom_field.delete_if {|k,v| v.blank?} |
|
265 | 270 | |
|
266 | 271 | @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&).select {|field| field.format.bulk_edit_supported} |
|
267 | 272 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
268 | 273 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
269 | 274 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) |
|
270 | 275 | if @copy |
|
271 | 276 | @attachments_present = @issues.detect {|i| i.attachments.any?}.present? |
|
272 | 277 | @subtasks_present = @issues.detect {|i| !i.leaf?}.present? |
|
273 | 278 | end |
|
274 | 279 | |
|
275 | 280 | @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&) |
|
276 | 281 | |
|
277 | 282 | @issue_params = params[:issue] || {} |
|
278 | 283 | @issue_params[:custom_field_values] ||= {} |
|
279 | 284 | end |
|
280 | 285 | |
|
281 | 286 | def bulk_update |
|
282 | 287 | @issues.sort! |
|
283 | 288 | @copy = params[:copy].present? |
|
284 | 289 | |
|
285 | 290 | attributes = parse_params_for_bulk_update(params[:issue]) |
|
286 | 291 | copy_subtasks = (params[:copy_subtasks] == '1') |
|
287 | 292 | copy_attachments = (params[:copy_attachments] == '1') |
|
288 | 293 | |
|
289 | 294 | if @copy |
|
290 | 295 | unless User.current.allowed_to?(:copy_issues, @projects) |
|
291 | 296 | raise ::Unauthorized |
|
292 | 297 | end |
|
293 | 298 | target_projects = @projects |
|
294 | 299 | if attributes['project_id'].present? |
|
295 | 300 | target_projects = Project.where(:id => attributes['project_id']).to_a |
|
296 | 301 | end |
|
297 | 302 | unless User.current.allowed_to?(:add_issues, target_projects) |
|
298 | 303 | raise ::Unauthorized |
|
299 | 304 | end |
|
300 | 305 | else |
|
301 | 306 | unless @issues.all?(&:attributes_editable?) |
|
302 | 307 | raise ::Unauthorized |
|
303 | 308 | end |
|
304 | 309 | end |
|
305 | 310 | |
|
306 | 311 | unsaved_issues = [] |
|
307 | 312 | saved_issues = [] |
|
308 | 313 | |
|
309 | 314 | if @copy && copy_subtasks |
|
310 | 315 | # Descendant issues will be copied with the parent task |
|
311 | 316 | # Don't copy them twice |
|
312 | 317 | @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} |
|
313 | 318 | end |
|
314 | 319 | |
|
315 | 320 | @issues.each do |orig_issue| |
|
316 | 321 | orig_issue.reload |
|
317 | 322 | if @copy |
|
318 | 323 | issue = orig_issue.copy({}, |
|
319 | 324 | :attachments => copy_attachments, |
|
320 | 325 | :subtasks => copy_subtasks, |
|
321 | 326 | :link => link_copy?(params[:link_copy]) |
|
322 | 327 | ) |
|
323 | 328 | else |
|
324 | 329 | issue = orig_issue |
|
325 | 330 | end |
|
326 | 331 | journal = issue.init_journal(User.current, params[:notes]) |
|
327 | 332 | issue.safe_attributes = attributes |
|
328 | 333 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
329 | 334 | if issue.save |
|
330 | 335 | saved_issues << issue |
|
331 | 336 | else |
|
332 | 337 | unsaved_issues << orig_issue |
|
333 | 338 | end |
|
334 | 339 | end |
|
335 | 340 | |
|
336 | 341 | if unsaved_issues.empty? |
|
337 | 342 | flash[:notice] = l(:notice_successful_update) unless saved_issues.empty? |
|
338 | 343 | if params[:follow] |
|
339 | 344 | if @issues.size == 1 && saved_issues.size == 1 |
|
340 | 345 | redirect_to issue_path(saved_issues.first) |
|
341 | 346 | elsif saved_issues.map(&:project).uniq.size == 1 |
|
342 | 347 | redirect_to project_issues_path(saved_issues.map(&:project).first) |
|
343 | 348 | end |
|
344 | 349 | else |
|
345 | 350 | redirect_back_or_default _project_issues_path(@project) |
|
346 | 351 | end |
|
347 | 352 | else |
|
348 | 353 | @saved_issues = @issues |
|
349 | 354 | @unsaved_issues = unsaved_issues |
|
350 | 355 | @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a |
|
351 | 356 | bulk_edit |
|
352 | 357 | render :action => 'bulk_edit' |
|
353 | 358 | end |
|
354 | 359 | end |
|
355 | 360 | |
|
356 | 361 | def destroy |
|
357 | 362 | raise Unauthorized unless @issues.all?(&:deletable?) |
|
358 | 363 | |
|
359 | 364 | # all issues and their descendants are about to be deleted |
|
360 | 365 | issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id) |
|
361 | 366 | time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids) |
|
362 | 367 | @hours = time_entries.sum(:hours).to_f |
|
363 | 368 | |
|
364 | 369 | if @hours > 0 |
|
365 | 370 | case params[:todo] |
|
366 | 371 | when 'destroy' |
|
367 | 372 | # nothing to do |
|
368 | 373 | when 'nullify' |
|
369 | 374 | time_entries.update_all(:issue_id => nil) |
|
370 | 375 | when 'reassign' |
|
371 | 376 | reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id]) |
|
372 | 377 | if reassign_to.nil? |
|
373 | 378 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
374 | 379 | return |
|
375 | 380 | elsif issues_and_descendants_ids.include?(reassign_to.id) |
|
376 | 381 | flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted) |
|
377 | 382 | return |
|
378 | 383 | else |
|
379 | 384 | time_entries.update_all(:issue_id => reassign_to.id, :project_id => reassign_to.project_id) |
|
380 | 385 | end |
|
381 | 386 | else |
|
382 | 387 | # display the destroy form if it's a user request |
|
383 | 388 | return unless api_request? |
|
384 | 389 | end |
|
385 | 390 | end |
|
386 | 391 | @issues.each do |issue| |
|
387 | 392 | begin |
|
388 | 393 | issue.reload.destroy |
|
389 | 394 | rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists |
|
390 | 395 | # nothing to do, issue was already deleted (eg. by a parent) |
|
391 | 396 | end |
|
392 | 397 | end |
|
393 | 398 | respond_to do |format| |
|
394 | 399 | format.html { redirect_back_or_default _project_issues_path(@project) } |
|
395 | 400 | format.api { render_api_ok } |
|
396 | 401 | end |
|
397 | 402 | end |
|
398 | 403 | |
|
399 | 404 | # Overrides Redmine::MenuManager::MenuController::ClassMethods for |
|
400 | 405 | # when the "New issue" tab is enabled |
|
401 | 406 | def current_menu_item |
|
402 | 407 | if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym) |
|
403 | 408 | :new_issue |
|
404 | 409 | else |
|
405 | 410 | super |
|
406 | 411 | end |
|
407 | 412 | end |
|
408 | 413 | |
|
409 | 414 | private |
|
410 | 415 | |
|
411 | 416 | def retrieve_previous_and_next_issue_ids |
|
412 | 417 | if params[:prev_issue_id].present? || params[:next_issue_id].present? |
|
413 | 418 | @prev_issue_id = params[:prev_issue_id].presence.try(:to_i) |
|
414 | 419 | @next_issue_id = params[:next_issue_id].presence.try(:to_i) |
|
415 | 420 | @issue_position = params[:issue_position].presence.try(:to_i) |
|
416 | 421 | @issue_count = params[:issue_count].presence.try(:to_i) |
|
417 | 422 | else |
|
418 | 423 | retrieve_query_from_session |
|
419 | 424 | if @query |
|
420 | 425 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
421 | 426 | sort_update(@query.sortable_columns, 'issues_index_sort') |
|
422 | 427 | limit = 500 |
|
423 | 428 | issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1)) |
|
424 | 429 | if (idx = issue_ids.index(@issue.id)) && idx < limit |
|
425 | 430 | if issue_ids.size < 500 |
|
426 | 431 | @issue_position = idx + 1 |
|
427 | 432 | @issue_count = issue_ids.size |
|
428 | 433 | end |
|
429 | 434 | @prev_issue_id = issue_ids[idx - 1] if idx > 0 |
|
430 | 435 | @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) |
|
431 | 436 | end |
|
432 | 437 | end |
|
433 | 438 | end |
|
434 | 439 | end |
|
435 | 440 | |
|
436 | 441 | def previous_and_next_issue_ids_params |
|
437 | 442 | { |
|
438 | 443 | :prev_issue_id => params[:prev_issue_id], |
|
439 | 444 | :next_issue_id => params[:next_issue_id], |
|
440 | 445 | :issue_position => params[:issue_position], |
|
441 | 446 | :issue_count => params[:issue_count] |
|
442 | 447 | }.reject {|k,v| k.blank?} |
|
443 | 448 | end |
|
444 | 449 | |
|
445 | 450 | # Used by #edit and #update to set some common instance variables |
|
446 | 451 | # from the params |
|
447 | 452 | def update_issue_from_params |
|
448 | 453 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
449 | 454 | if params[:time_entry] |
|
450 | 455 | @time_entry.safe_attributes = params[:time_entry] |
|
451 | 456 | end |
|
452 | 457 | |
|
453 | 458 | @issue.init_journal(User.current) |
|
454 | 459 | |
|
455 | 460 | issue_attributes = params[:issue] |
|
456 | 461 | if issue_attributes && params[:conflict_resolution] |
|
457 | 462 | case params[:conflict_resolution] |
|
458 | 463 | when 'overwrite' |
|
459 | 464 | issue_attributes = issue_attributes.dup |
|
460 | 465 | issue_attributes.delete(:lock_version) |
|
461 | 466 | when 'add_notes' |
|
462 | 467 | issue_attributes = issue_attributes.slice(:notes, :private_notes) |
|
463 | 468 | when 'cancel' |
|
464 | 469 | redirect_to issue_path(@issue) |
|
465 | 470 | return false |
|
466 | 471 | end |
|
467 | 472 | end |
|
468 | 473 | @issue.safe_attributes = issue_attributes |
|
469 | 474 | @priorities = IssuePriority.active |
|
470 | 475 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
471 | 476 | true |
|
472 | 477 | end |
|
473 | 478 | |
|
474 | 479 | # Used by #new and #create to build a new issue from the params |
|
475 | 480 | # The new issue will be copied from an existing one if copy_from parameter is given |
|
476 | 481 | def build_new_issue_from_params |
|
477 | 482 | @issue = Issue.new |
|
478 | 483 | if params[:copy_from] |
|
479 | 484 | begin |
|
480 | 485 | @issue.init_journal(User.current) |
|
481 | 486 | @copy_from = Issue.visible.find(params[:copy_from]) |
|
482 | 487 | unless User.current.allowed_to?(:copy_issues, @copy_from.project) |
|
483 | 488 | raise ::Unauthorized |
|
484 | 489 | end |
|
485 | 490 | @link_copy = link_copy?(params[:link_copy]) || request.get? |
|
486 | 491 | @copy_attachments = params[:copy_attachments].present? || request.get? |
|
487 | 492 | @copy_subtasks = params[:copy_subtasks].present? || request.get? |
|
488 | 493 | @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy) |
|
489 | 494 | @issue.parent_issue_id = @copy_from.parent_id |
|
490 | 495 | rescue ActiveRecord::RecordNotFound |
|
491 | 496 | render_404 |
|
492 | 497 | return |
|
493 | 498 | end |
|
494 | 499 | end |
|
495 | 500 | @issue.project = @project |
|
496 | 501 | if request.get? |
|
497 | 502 | @issue.project ||= @issue.allowed_target_projects.first |
|
498 | 503 | end |
|
499 | 504 | @issue.author ||= User.current |
|
500 | 505 | @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date? |
|
501 | 506 | |
|
502 | 507 | attrs = (params[:issue] || {}).deep_dup |
|
503 | 508 | if action_name == 'new' && params[:was_default_status] == attrs[:status_id] |
|
504 | 509 | attrs.delete(:status_id) |
|
505 | 510 | end |
|
506 | 511 | if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id' |
|
507 | 512 | # Discard submitted version when changing the project on the issue form |
|
508 | 513 | # so we can use the default version for the new project |
|
509 | 514 | attrs.delete(:fixed_version_id) |
|
510 | 515 | end |
|
511 | 516 | @issue.safe_attributes = attrs |
|
512 | 517 | |
|
513 | 518 | if @issue.project |
|
514 | 519 | @issue.tracker ||= @issue.allowed_target_trackers.first |
|
515 | 520 | if @issue.tracker.nil? |
|
516 | 521 | if @issue.project.trackers.any? |
|
517 | 522 | # None of the project trackers is allowed to the user |
|
518 | 523 | render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403 |
|
519 | 524 | else |
|
520 | 525 | # Project has no trackers |
|
521 | 526 | render_error l(:error_no_tracker_in_project) |
|
522 | 527 | end |
|
523 | 528 | return false |
|
524 | 529 | end |
|
525 | 530 | if @issue.status.nil? |
|
526 | 531 | render_error l(:error_no_default_issue_status) |
|
527 | 532 | return false |
|
528 | 533 | end |
|
529 | 534 | elsif request.get? |
|
530 | 535 | render_error :message => l(:error_no_projects_with_tracker_allowed_for_new_issue), :status => 403 |
|
531 | 536 | return false |
|
532 | 537 | end |
|
533 | 538 | |
|
534 | 539 | @priorities = IssuePriority.active |
|
535 | 540 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
536 | 541 | end |
|
537 | 542 | |
|
538 | 543 | # Saves @issue and a time_entry from the parameters |
|
539 | 544 | def save_issue_with_child_records |
|
540 | 545 | Issue.transaction do |
|
541 | 546 | if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project) |
|
542 | 547 | time_entry = @time_entry || TimeEntry.new |
|
543 | 548 | time_entry.project = @issue.project |
|
544 | 549 | time_entry.issue = @issue |
|
545 | 550 | time_entry.user = User.current |
|
546 | 551 | time_entry.spent_on = User.current.today |
|
547 | 552 | time_entry.attributes = params[:time_entry] |
|
548 | 553 | @issue.time_entries << time_entry |
|
549 | 554 | end |
|
550 | 555 | |
|
551 | 556 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal}) |
|
552 | 557 | if @issue.save |
|
553 | 558 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal}) |
|
554 | 559 | else |
|
555 | 560 | raise ActiveRecord::Rollback |
|
556 | 561 | end |
|
557 | 562 | end |
|
558 | 563 | end |
|
559 | 564 | |
|
560 | 565 | # Returns true if the issue copy should be linked |
|
561 | 566 | # to the original issue |
|
562 | 567 | def link_copy?(param) |
|
563 | 568 | case Setting.link_copied_issue |
|
564 | 569 | when 'yes' |
|
565 | 570 | true |
|
566 | 571 | when 'no' |
|
567 | 572 | false |
|
568 | 573 | when 'ask' |
|
569 | 574 | param == '1' |
|
570 | 575 | end |
|
571 | 576 | end |
|
572 | 577 | |
|
573 | 578 | # Redirects user after a successful issue creation |
|
574 | 579 | def redirect_after_create |
|
575 | 580 | if params[:continue] |
|
576 | 581 | attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} |
|
577 | 582 | if params[:project_id] |
|
578 | 583 | redirect_to new_project_issue_path(@issue.project, :issue => attrs) |
|
579 | 584 | else |
|
580 | 585 | attrs.merge! :project_id => @issue.project_id |
|
581 | 586 | redirect_to new_issue_path(:issue => attrs) |
|
582 | 587 | end |
|
583 | 588 | else |
|
584 | 589 | redirect_to issue_path(@issue) |
|
585 | 590 | end |
|
586 | 591 | end |
|
587 | 592 | end |
@@ -1,164 +1,164 | |||
|
1 | 1 | <%= render :partial => 'action_menu' %> |
|
2 | 2 | |
|
3 | 3 | <h2><%= issue_heading(@issue) %></h2> |
|
4 | 4 | |
|
5 | 5 | <div class="<%= @issue.css_classes %> details"> |
|
6 | 6 | <% if @prev_issue_id || @next_issue_id %> |
|
7 | 7 | <div class="next-prev-links contextual"> |
|
8 | 8 | <%= link_to_if @prev_issue_id, |
|
9 | 9 | "\xc2\xab #{l(:label_previous)}", |
|
10 | 10 | (@prev_issue_id ? issue_path(@prev_issue_id) : nil), |
|
11 | 11 | :title => "##{@prev_issue_id}", |
|
12 | 12 | :accesskey => accesskey(:previous) %> | |
|
13 | 13 | <% if @issue_position && @issue_count %> |
|
14 | 14 | <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> | |
|
15 | 15 | <% end %> |
|
16 | 16 | <%= link_to_if @next_issue_id, |
|
17 | 17 | "#{l(:label_next)} \xc2\xbb", |
|
18 | 18 | (@next_issue_id ? issue_path(@next_issue_id) : nil), |
|
19 | 19 | :title => "##{@next_issue_id}", |
|
20 | 20 | :accesskey => accesskey(:next) %> |
|
21 | 21 | </div> |
|
22 | 22 | <% end %> |
|
23 | 23 | |
|
24 | 24 | <%= avatar(@issue.author, :size => "50") %> |
|
25 | 25 | |
|
26 | 26 | <div class="subject"> |
|
27 | 27 | <%= render_issue_subject_with_tree(@issue) %> |
|
28 | 28 | </div> |
|
29 | 29 | <p class="author"> |
|
30 | 30 | <%= authoring @issue.created_on, @issue.author %>. |
|
31 | 31 | <% if @issue.created_on != @issue.updated_on %> |
|
32 | 32 | <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>. |
|
33 | 33 | <% end %> |
|
34 | 34 | </p> |
|
35 | 35 | |
|
36 | 36 | <div class="attributes"> |
|
37 | 37 | <%= issue_fields_rows do |rows| |
|
38 | 38 | rows.left l(:field_status), @issue.status.name, :class => 'status' |
|
39 | 39 | rows.left l(:field_priority), @issue.priority.name, :class => 'priority' |
|
40 | 40 | |
|
41 | 41 | unless @issue.disabled_core_fields.include?('assigned_to_id') |
|
42 | 42 | rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to' |
|
43 | 43 | end |
|
44 | 44 | unless @issue.disabled_core_fields.include?('category_id') || (@issue.category.nil? && @issue.project.issue_categories.none?) |
|
45 | 45 | rows.left l(:field_category), (@issue.category ? @issue.category.name : "-"), :class => 'category' |
|
46 | 46 | end |
|
47 | 47 | unless @issue.disabled_core_fields.include?('fixed_version_id') || (@issue.fixed_version.nil? && @issue.assignable_versions.none?) |
|
48 | 48 | rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version' |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | unless @issue.disabled_core_fields.include?('start_date') |
|
52 | 52 | rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date' |
|
53 | 53 | end |
|
54 | 54 | unless @issue.disabled_core_fields.include?('due_date') |
|
55 | 55 | rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date' |
|
56 | 56 | end |
|
57 | 57 | unless @issue.disabled_core_fields.include?('done_ratio') |
|
58 | 58 | rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :legend => "#{@issue.done_ratio}%"), :class => 'progress' |
|
59 | 59 | end |
|
60 | 60 | unless @issue.disabled_core_fields.include?('estimated_hours') |
|
61 | 61 | rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), :class => 'estimated-hours' |
|
62 | 62 | end |
|
63 |
if User.current.allowed_to |
|
|
63 | if User.current.allowed_to?(:view_time_entries, @project) | |
|
64 | 64 | if @issue.total_spent_hours > 0 |
|
65 | 65 | rows.right l(:label_spent_time), issue_spent_hours_details(@issue), :class => 'spent-time' |
|
66 | 66 | end |
|
67 | 67 | end |
|
68 | 68 | end %> |
|
69 | 69 | <%= render_half_width_custom_fields_rows(@issue) %> |
|
70 | 70 | <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> |
|
71 | 71 | </div> |
|
72 | 72 | |
|
73 | 73 | <% if @issue.description? || @issue.attachments.any? -%> |
|
74 | 74 | <hr /> |
|
75 | 75 | <% if @issue.description? %> |
|
76 | 76 | <div class="description"> |
|
77 | 77 | <div class="contextual"> |
|
78 | 78 | <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if @issue.notes_addable? %> |
|
79 | 79 | </div> |
|
80 | 80 | |
|
81 | 81 | <p><strong><%=l(:field_description)%></strong></p> |
|
82 | 82 | <div class="wiki"> |
|
83 | 83 | <%= textilizable @issue, :description, :attachments => @issue.attachments %> |
|
84 | 84 | </div> |
|
85 | 85 | </div> |
|
86 | 86 | <% end %> |
|
87 | 87 | <%= link_to_attachments @issue, :thumbnails => true %> |
|
88 | 88 | <% end -%> |
|
89 | 89 | |
|
90 | 90 | <%= render_full_width_custom_fields_rows(@issue) %> |
|
91 | 91 | |
|
92 | 92 | <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> |
|
93 | 93 | |
|
94 | 94 | <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %> |
|
95 | 95 | <hr /> |
|
96 | 96 | <div id="issue_tree"> |
|
97 | 97 | <div class="contextual"> |
|
98 | 98 | <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %> |
|
99 | 99 | </div> |
|
100 | 100 | <p><strong><%=l(:label_subtask_plural)%></strong></p> |
|
101 | 101 | <%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %> |
|
102 | 102 | <%= render_descendants_tree(@issue) unless @issue.leaf? %> |
|
103 | 103 | <% end %> |
|
104 | 104 | </div> |
|
105 | 105 | <% end %> |
|
106 | 106 | |
|
107 | 107 | <% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %> |
|
108 | 108 | <hr /> |
|
109 | 109 | <div id="relations"> |
|
110 | 110 | <%= render :partial => 'relations' %> |
|
111 | 111 | </div> |
|
112 | 112 | <% end %> |
|
113 | 113 | |
|
114 | 114 | </div> |
|
115 | 115 | |
|
116 | 116 | <% if @changesets.present? %> |
|
117 | 117 | <div id="issue-changesets"> |
|
118 | 118 | <h3><%=l(:label_associated_revisions)%></h3> |
|
119 | 119 | <%= render :partial => 'changesets', :locals => { :changesets => @changesets} %> |
|
120 | 120 | </div> |
|
121 | 121 | <% end %> |
|
122 | 122 | |
|
123 | 123 | <% if @journals.present? %> |
|
124 | 124 | <div id="history"> |
|
125 | 125 | <h3><%=l(:label_history)%></h3> |
|
126 | 126 | <%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %> |
|
127 | 127 | </div> |
|
128 | 128 | <% end %> |
|
129 | 129 | |
|
130 | 130 | |
|
131 | 131 | <div style="clear: both;"></div> |
|
132 | 132 | <%= render :partial => 'action_menu' %> |
|
133 | 133 | |
|
134 | 134 | <div style="clear: both;"></div> |
|
135 | 135 | <% if @issue.editable? %> |
|
136 | 136 | <div id="update" style="display:none;"> |
|
137 | 137 | <h3><%= l(:button_edit) %></h3> |
|
138 | 138 | <%= render :partial => 'edit' %> |
|
139 | 139 | </div> |
|
140 | 140 | <% end %> |
|
141 | 141 | |
|
142 | 142 | <% other_formats_links do |f| %> |
|
143 | 143 | <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> |
|
144 | 144 | <%= f.link_to 'PDF' %> |
|
145 | 145 | <% end %> |
|
146 | 146 | |
|
147 | 147 | <% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %> |
|
148 | 148 | |
|
149 | 149 | <% content_for :sidebar do %> |
|
150 | 150 | <%= render :partial => 'issues/sidebar' %> |
|
151 | 151 | |
|
152 | 152 | <% if User.current.allowed_to?(:add_issue_watchers, @project) || |
|
153 | 153 | (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %> |
|
154 | 154 | <div id="watchers"> |
|
155 | 155 | <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %> |
|
156 | 156 | </div> |
|
157 | 157 | <% end %> |
|
158 | 158 | <% end %> |
|
159 | 159 | |
|
160 | 160 | <% content_for :header_tags do %> |
|
161 | 161 | <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %> |
|
162 | 162 | <% end %> |
|
163 | 163 | |
|
164 | 164 | <%= context_menu %> |
General Comments 0
You need to be logged in to leave comments.
Login now