The requested changes are too big and content was truncated. Show full diff
@@ -1,551 +1,568 | |||
|
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(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
|
70 | 70 | :order => sort_clause, |
|
71 | 71 | :offset => @offset, |
|
72 | 72 | :limit => @limit) |
|
73 | 73 | @issue_count_by_group = @query.issue_count_by_group |
|
74 | 74 | |
|
75 | 75 | respond_to do |format| |
|
76 | 76 | format.html { render :template => 'issues/index', :layout => !request.xhr? } |
|
77 | 77 | format.api { |
|
78 | 78 | Issue.load_visible_relations(@issues) if include_in_api_response?('relations') |
|
79 | 79 | } |
|
80 | 80 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
81 | 81 | format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') } |
|
82 | 82 | format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' } |
|
83 | 83 | end |
|
84 | 84 | else |
|
85 | 85 | respond_to do |format| |
|
86 | 86 | format.html { render(:template => 'issues/index', :layout => !request.xhr?) } |
|
87 | 87 | format.any(:atom, :csv, :pdf) { head 422 } |
|
88 | 88 | format.api { render_validation_errors(@query) } |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | rescue ActiveRecord::RecordNotFound |
|
92 | 92 | render_404 |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def show |
|
96 | 96 | @journals = @issue.journals. |
|
97 | 97 | preload(:details). |
|
98 | 98 | preload(:user => :email_address). |
|
99 | 99 | reorder(:created_on, :id).to_a |
|
100 | 100 | @journals.each_with_index {|j,i| j.indice = i+1} |
|
101 | 101 | @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) |
|
102 | 102 | Journal.preload_journals_details_custom_fields(@journals) |
|
103 | 103 | @journals.select! {|journal| journal.notes? || journal.visible_details.any?} |
|
104 | 104 | @journals.reverse! if User.current.wants_comments_in_reverse_order? |
|
105 | 105 | |
|
106 | 106 | @changesets = @issue.changesets.visible.preload(:repository, :user).to_a |
|
107 | 107 | @changesets.reverse! if User.current.wants_comments_in_reverse_order? |
|
108 | 108 | |
|
109 | 109 | @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? } |
|
110 | 110 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
111 | 111 | @priorities = IssuePriority.active |
|
112 | 112 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
113 | 113 | @relation = IssueRelation.new |
|
114 | 114 | |
|
115 | 115 | respond_to do |format| |
|
116 | 116 | format.html { |
|
117 | 117 | retrieve_previous_and_next_issue_ids |
|
118 | 118 | render :template => 'issues/show' |
|
119 | 119 | } |
|
120 | 120 | format.api |
|
121 | 121 | format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } |
|
122 | 122 | format.pdf { |
|
123 | 123 | send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf" |
|
124 | 124 | } |
|
125 | 125 | end |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def new |
|
129 | 129 | respond_to do |format| |
|
130 | 130 | format.html { render :action => 'new', :layout => !request.xhr? } |
|
131 | 131 | format.js |
|
132 | 132 | end |
|
133 | 133 | end |
|
134 | 134 | |
|
135 | 135 | def create |
|
136 | 136 | unless User.current.allowed_to?(:add_issues, @issue.project, :global => true) |
|
137 | 137 | raise ::Unauthorized |
|
138 | 138 | end |
|
139 | 139 | call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) |
|
140 | 140 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
141 | 141 | if @issue.save |
|
142 | 142 | call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) |
|
143 | 143 | respond_to do |format| |
|
144 | 144 | format.html { |
|
145 | 145 | render_attachment_warning_if_needed(@issue) |
|
146 | 146 | flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) |
|
147 | 147 | redirect_after_create |
|
148 | 148 | } |
|
149 | 149 | format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } |
|
150 | 150 | end |
|
151 | 151 | return |
|
152 | 152 | else |
|
153 | 153 | respond_to do |format| |
|
154 | 154 | format.html { |
|
155 | 155 | if @issue.project.nil? |
|
156 | 156 | render_error :status => 422 |
|
157 | 157 | else |
|
158 | 158 | render :action => 'new' |
|
159 | 159 | end |
|
160 | 160 | } |
|
161 | 161 | format.api { render_validation_errors(@issue) } |
|
162 | 162 | end |
|
163 | 163 | end |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def edit |
|
167 | 167 | return unless update_issue_from_params |
|
168 | 168 | |
|
169 | 169 | respond_to do |format| |
|
170 | 170 | format.html { } |
|
171 | 171 | format.js |
|
172 | 172 | end |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | def update |
|
176 | 176 | return unless update_issue_from_params |
|
177 | 177 | @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) |
|
178 | 178 | saved = false |
|
179 | 179 | begin |
|
180 | 180 | saved = save_issue_with_child_records |
|
181 | 181 | rescue ActiveRecord::StaleObjectError |
|
182 | 182 | @conflict = true |
|
183 | 183 | if params[:last_journal_id] |
|
184 | 184 | @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a |
|
185 | 185 | @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) |
|
186 | 186 | end |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | if saved |
|
190 | 190 | render_attachment_warning_if_needed(@issue) |
|
191 | 191 | flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? |
|
192 | 192 | |
|
193 | 193 | respond_to do |format| |
|
194 | 194 | format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) } |
|
195 | 195 | format.api { render_api_ok } |
|
196 | 196 | end |
|
197 | 197 | else |
|
198 | 198 | respond_to do |format| |
|
199 | 199 | format.html { render :action => 'edit' } |
|
200 | 200 | format.api { render_validation_errors(@issue) } |
|
201 | 201 | end |
|
202 | 202 | end |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | # Bulk edit/copy a set of issues |
|
206 | 206 | def bulk_edit |
|
207 | 207 | @issues.sort! |
|
208 | 208 | @copy = params[:copy].present? |
|
209 | 209 | @notes = params[:notes] |
|
210 | 210 | |
|
211 | 211 | if @copy |
|
212 | 212 | unless User.current.allowed_to?(:copy_issues, @projects) |
|
213 | 213 | raise ::Unauthorized |
|
214 | 214 | end |
|
215 | 215 | else |
|
216 | 216 | unless @issues.all?(&:attributes_editable?) |
|
217 | 217 | raise ::Unauthorized |
|
218 | 218 | end |
|
219 | 219 | end |
|
220 | 220 | |
|
221 | edited_issues = Issue.where(:id => @issues.map(&:id)).to_a | |
|
222 | ||
|
221 | 223 | @allowed_projects = Issue.allowed_target_projects |
|
222 | 224 | if params[:issue] |
|
223 | 225 | @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} |
|
224 | 226 | if @target_project |
|
225 | 227 | target_projects = [@target_project] |
|
228 | edited_issues.each {|issue| issue.project = @target_project} | |
|
226 | 229 | end |
|
227 | 230 | end |
|
228 | 231 | target_projects ||= @projects |
|
229 | 232 | |
|
233 | @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) | |
|
234 | if params[:issue] | |
|
235 | @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s} | |
|
236 | if @target_tracker | |
|
237 | edited_issues.each {|issue| issue.tracker = @target_tracker} | |
|
238 | end | |
|
239 | end | |
|
240 | ||
|
230 | 241 | if @copy |
|
231 | 242 | # Copied issues will get their default statuses |
|
232 | 243 | @available_statuses = [] |
|
233 | 244 | else |
|
234 |
@available_statuses = |
|
|
245 | @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&) | |
|
235 | 246 | end |
|
236 | @custom_fields = @issues.map{|i|i.editable_custom_fields}.reduce(:&) | |
|
247 | if params[:issue] | |
|
248 | @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s} | |
|
249 | if @target_status | |
|
250 | edited_issues.each {|issue| issue.status = @target_status} | |
|
251 | end | |
|
252 | end | |
|
253 | ||
|
254 | @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&) | |
|
237 | 255 | @assignables = target_projects.map(&:assignable_users).reduce(:&) |
|
238 | @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) | |
|
239 | 256 | @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) |
|
240 | 257 | @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) |
|
241 | 258 | if @copy |
|
242 | 259 | @attachments_present = @issues.detect {|i| i.attachments.any?}.present? |
|
243 | 260 | @subtasks_present = @issues.detect {|i| !i.leaf?}.present? |
|
244 | 261 | end |
|
245 | 262 | |
|
246 |
@safe_attributes = |
|
|
263 | @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&) | |
|
247 | 264 | |
|
248 | 265 | @issue_params = params[:issue] || {} |
|
249 | 266 | @issue_params[:custom_field_values] ||= {} |
|
250 | 267 | end |
|
251 | 268 | |
|
252 | 269 | def bulk_update |
|
253 | 270 | @issues.sort! |
|
254 | 271 | @copy = params[:copy].present? |
|
255 | 272 | |
|
256 | 273 | attributes = parse_params_for_bulk_update(params[:issue]) |
|
257 | 274 | copy_subtasks = (params[:copy_subtasks] == '1') |
|
258 | 275 | copy_attachments = (params[:copy_attachments] == '1') |
|
259 | 276 | |
|
260 | 277 | if @copy |
|
261 | 278 | unless User.current.allowed_to?(:copy_issues, @projects) |
|
262 | 279 | raise ::Unauthorized |
|
263 | 280 | end |
|
264 | 281 | target_projects = @projects |
|
265 | 282 | if attributes['project_id'].present? |
|
266 | 283 | target_projects = Project.where(:id => attributes['project_id']).to_a |
|
267 | 284 | end |
|
268 | 285 | unless User.current.allowed_to?(:add_issues, target_projects) |
|
269 | 286 | raise ::Unauthorized |
|
270 | 287 | end |
|
271 | 288 | else |
|
272 | 289 | unless @issues.all?(&:attributes_editable?) |
|
273 | 290 | raise ::Unauthorized |
|
274 | 291 | end |
|
275 | 292 | end |
|
276 | 293 | |
|
277 | 294 | unsaved_issues = [] |
|
278 | 295 | saved_issues = [] |
|
279 | 296 | |
|
280 | 297 | if @copy && copy_subtasks |
|
281 | 298 | # Descendant issues will be copied with the parent task |
|
282 | 299 | # Don't copy them twice |
|
283 | 300 | @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} |
|
284 | 301 | end |
|
285 | 302 | |
|
286 | 303 | @issues.each do |orig_issue| |
|
287 | 304 | orig_issue.reload |
|
288 | 305 | if @copy |
|
289 | 306 | issue = orig_issue.copy({}, |
|
290 | 307 | :attachments => copy_attachments, |
|
291 | 308 | :subtasks => copy_subtasks, |
|
292 | 309 | :link => link_copy?(params[:link_copy]) |
|
293 | 310 | ) |
|
294 | 311 | else |
|
295 | 312 | issue = orig_issue |
|
296 | 313 | end |
|
297 | 314 | journal = issue.init_journal(User.current, params[:notes]) |
|
298 | 315 | issue.safe_attributes = attributes |
|
299 | 316 | call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) |
|
300 | 317 | if issue.save |
|
301 | 318 | saved_issues << issue |
|
302 | 319 | else |
|
303 | 320 | unsaved_issues << orig_issue |
|
304 | 321 | end |
|
305 | 322 | end |
|
306 | 323 | |
|
307 | 324 | if unsaved_issues.empty? |
|
308 | 325 | flash[:notice] = l(:notice_successful_update) unless saved_issues.empty? |
|
309 | 326 | if params[:follow] |
|
310 | 327 | if @issues.size == 1 && saved_issues.size == 1 |
|
311 | 328 | redirect_to issue_path(saved_issues.first) |
|
312 | 329 | elsif saved_issues.map(&:project).uniq.size == 1 |
|
313 | 330 | redirect_to project_issues_path(saved_issues.map(&:project).first) |
|
314 | 331 | end |
|
315 | 332 | else |
|
316 | 333 | redirect_back_or_default _project_issues_path(@project) |
|
317 | 334 | end |
|
318 | 335 | else |
|
319 | 336 | @saved_issues = @issues |
|
320 | 337 | @unsaved_issues = unsaved_issues |
|
321 | 338 | @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a |
|
322 | 339 | bulk_edit |
|
323 | 340 | render :action => 'bulk_edit' |
|
324 | 341 | end |
|
325 | 342 | end |
|
326 | 343 | |
|
327 | 344 | def destroy |
|
328 | 345 | raise Unauthorized unless @issues.all?(&:deletable?) |
|
329 | 346 | @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f |
|
330 | 347 | if @hours > 0 |
|
331 | 348 | case params[:todo] |
|
332 | 349 | when 'destroy' |
|
333 | 350 | # nothing to do |
|
334 | 351 | when 'nullify' |
|
335 | 352 | TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL') |
|
336 | 353 | when 'reassign' |
|
337 | 354 | reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) |
|
338 | 355 | if reassign_to.nil? |
|
339 | 356 | flash.now[:error] = l(:error_issue_not_found_in_project) |
|
340 | 357 | return |
|
341 | 358 | else |
|
342 | 359 | TimeEntry.where(['issue_id IN (?)', @issues]). |
|
343 | 360 | update_all("issue_id = #{reassign_to.id}") |
|
344 | 361 | end |
|
345 | 362 | else |
|
346 | 363 | # display the destroy form if it's a user request |
|
347 | 364 | return unless api_request? |
|
348 | 365 | end |
|
349 | 366 | end |
|
350 | 367 | @issues.each do |issue| |
|
351 | 368 | begin |
|
352 | 369 | issue.reload.destroy |
|
353 | 370 | rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists |
|
354 | 371 | # nothing to do, issue was already deleted (eg. by a parent) |
|
355 | 372 | end |
|
356 | 373 | end |
|
357 | 374 | respond_to do |format| |
|
358 | 375 | format.html { redirect_back_or_default _project_issues_path(@project) } |
|
359 | 376 | format.api { render_api_ok } |
|
360 | 377 | end |
|
361 | 378 | end |
|
362 | 379 | |
|
363 | 380 | # Overrides Redmine::MenuManager::MenuController::ClassMethods for |
|
364 | 381 | # when the "New issue" tab is enabled |
|
365 | 382 | def current_menu_item |
|
366 | 383 | if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym) |
|
367 | 384 | :new_issue |
|
368 | 385 | else |
|
369 | 386 | super |
|
370 | 387 | end |
|
371 | 388 | end |
|
372 | 389 | |
|
373 | 390 | private |
|
374 | 391 | |
|
375 | 392 | def retrieve_previous_and_next_issue_ids |
|
376 | 393 | if params[:prev_issue_id].present? || params[:next_issue_id].present? |
|
377 | 394 | @prev_issue_id = params[:prev_issue_id].presence.try(:to_i) |
|
378 | 395 | @next_issue_id = params[:next_issue_id].presence.try(:to_i) |
|
379 | 396 | @issue_position = params[:issue_position].presence.try(:to_i) |
|
380 | 397 | @issue_count = params[:issue_count].presence.try(:to_i) |
|
381 | 398 | else |
|
382 | 399 | retrieve_query_from_session |
|
383 | 400 | if @query |
|
384 | 401 | sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) |
|
385 | 402 | sort_update(@query.sortable_columns, 'issues_index_sort') |
|
386 | 403 | limit = 500 |
|
387 | 404 | issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) |
|
388 | 405 | if (idx = issue_ids.index(@issue.id)) && idx < limit |
|
389 | 406 | if issue_ids.size < 500 |
|
390 | 407 | @issue_position = idx + 1 |
|
391 | 408 | @issue_count = issue_ids.size |
|
392 | 409 | end |
|
393 | 410 | @prev_issue_id = issue_ids[idx - 1] if idx > 0 |
|
394 | 411 | @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) |
|
395 | 412 | end |
|
396 | 413 | end |
|
397 | 414 | end |
|
398 | 415 | end |
|
399 | 416 | |
|
400 | 417 | def previous_and_next_issue_ids_params |
|
401 | 418 | { |
|
402 | 419 | :prev_issue_id => params[:prev_issue_id], |
|
403 | 420 | :next_issue_id => params[:next_issue_id], |
|
404 | 421 | :issue_position => params[:issue_position], |
|
405 | 422 | :issue_count => params[:issue_count] |
|
406 | 423 | }.reject {|k,v| k.blank?} |
|
407 | 424 | end |
|
408 | 425 | |
|
409 | 426 | # Used by #edit and #update to set some common instance variables |
|
410 | 427 | # from the params |
|
411 | 428 | def update_issue_from_params |
|
412 | 429 | @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) |
|
413 | 430 | if params[:time_entry] |
|
414 | 431 | @time_entry.safe_attributes = params[:time_entry] |
|
415 | 432 | end |
|
416 | 433 | |
|
417 | 434 | @issue.init_journal(User.current) |
|
418 | 435 | |
|
419 | 436 | issue_attributes = params[:issue] |
|
420 | 437 | if issue_attributes && params[:conflict_resolution] |
|
421 | 438 | case params[:conflict_resolution] |
|
422 | 439 | when 'overwrite' |
|
423 | 440 | issue_attributes = issue_attributes.dup |
|
424 | 441 | issue_attributes.delete(:lock_version) |
|
425 | 442 | when 'add_notes' |
|
426 | 443 | issue_attributes = issue_attributes.slice(:notes, :private_notes) |
|
427 | 444 | when 'cancel' |
|
428 | 445 | redirect_to issue_path(@issue) |
|
429 | 446 | return false |
|
430 | 447 | end |
|
431 | 448 | end |
|
432 | 449 | @issue.safe_attributes = issue_attributes |
|
433 | 450 | @priorities = IssuePriority.active |
|
434 | 451 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
435 | 452 | true |
|
436 | 453 | end |
|
437 | 454 | |
|
438 | 455 | # Used by #new and #create to build a new issue from the params |
|
439 | 456 | # The new issue will be copied from an existing one if copy_from parameter is given |
|
440 | 457 | def build_new_issue_from_params |
|
441 | 458 | @issue = Issue.new |
|
442 | 459 | if params[:copy_from] |
|
443 | 460 | begin |
|
444 | 461 | @issue.init_journal(User.current) |
|
445 | 462 | @copy_from = Issue.visible.find(params[:copy_from]) |
|
446 | 463 | unless User.current.allowed_to?(:copy_issues, @copy_from.project) |
|
447 | 464 | raise ::Unauthorized |
|
448 | 465 | end |
|
449 | 466 | @link_copy = link_copy?(params[:link_copy]) || request.get? |
|
450 | 467 | @copy_attachments = params[:copy_attachments].present? || request.get? |
|
451 | 468 | @copy_subtasks = params[:copy_subtasks].present? || request.get? |
|
452 | 469 | @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy) |
|
453 | 470 | @issue.parent_issue_id = @copy_from.parent_id |
|
454 | 471 | rescue ActiveRecord::RecordNotFound |
|
455 | 472 | render_404 |
|
456 | 473 | return |
|
457 | 474 | end |
|
458 | 475 | end |
|
459 | 476 | @issue.project = @project |
|
460 | 477 | if request.get? |
|
461 | 478 | @issue.project ||= @issue.allowed_target_projects.first |
|
462 | 479 | end |
|
463 | 480 | @issue.author ||= User.current |
|
464 | 481 | @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date? |
|
465 | 482 | |
|
466 | 483 | attrs = (params[:issue] || {}).deep_dup |
|
467 | 484 | if action_name == 'new' && params[:was_default_status] == attrs[:status_id] |
|
468 | 485 | attrs.delete(:status_id) |
|
469 | 486 | end |
|
470 | 487 | if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id' |
|
471 | 488 | # Discard submitted version when changing the project on the issue form |
|
472 | 489 | # so we can use the default version for the new project |
|
473 | 490 | attrs.delete(:fixed_version_id) |
|
474 | 491 | end |
|
475 | 492 | @issue.safe_attributes = attrs |
|
476 | 493 | |
|
477 | 494 | if @issue.project |
|
478 | 495 | @issue.tracker ||= @issue.allowed_target_trackers.first |
|
479 | 496 | if @issue.tracker.nil? |
|
480 | 497 | if @issue.project.trackers.any? |
|
481 | 498 | # None of the project trackers is allowed to the user |
|
482 | 499 | render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403 |
|
483 | 500 | else |
|
484 | 501 | # Project has no trackers |
|
485 | 502 | render_error l(:error_no_tracker_in_project) |
|
486 | 503 | end |
|
487 | 504 | return false |
|
488 | 505 | end |
|
489 | 506 | if @issue.status.nil? |
|
490 | 507 | render_error l(:error_no_default_issue_status) |
|
491 | 508 | return false |
|
492 | 509 | end |
|
493 | 510 | elsif request.get? |
|
494 | 511 | render_error :message => l(:error_no_projects_with_tracker_allowed_for_new_issue), :status => 403 |
|
495 | 512 | return false |
|
496 | 513 | end |
|
497 | 514 | |
|
498 | 515 | @priorities = IssuePriority.active |
|
499 | 516 | @allowed_statuses = @issue.new_statuses_allowed_to(User.current) |
|
500 | 517 | end |
|
501 | 518 | |
|
502 | 519 | # Saves @issue and a time_entry from the parameters |
|
503 | 520 | def save_issue_with_child_records |
|
504 | 521 | Issue.transaction do |
|
505 | 522 | if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project) |
|
506 | 523 | time_entry = @time_entry || TimeEntry.new |
|
507 | 524 | time_entry.project = @issue.project |
|
508 | 525 | time_entry.issue = @issue |
|
509 | 526 | time_entry.user = User.current |
|
510 | 527 | time_entry.spent_on = User.current.today |
|
511 | 528 | time_entry.attributes = params[:time_entry] |
|
512 | 529 | @issue.time_entries << time_entry |
|
513 | 530 | end |
|
514 | 531 | |
|
515 | 532 | call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal}) |
|
516 | 533 | if @issue.save |
|
517 | 534 | call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal}) |
|
518 | 535 | else |
|
519 | 536 | raise ActiveRecord::Rollback |
|
520 | 537 | end |
|
521 | 538 | end |
|
522 | 539 | end |
|
523 | 540 | |
|
524 | 541 | # Returns true if the issue copy should be linked |
|
525 | 542 | # to the original issue |
|
526 | 543 | def link_copy?(param) |
|
527 | 544 | case Setting.link_copied_issue |
|
528 | 545 | when 'yes' |
|
529 | 546 | true |
|
530 | 547 | when 'no' |
|
531 | 548 | false |
|
532 | 549 | when 'ask' |
|
533 | 550 | param == '1' |
|
534 | 551 | end |
|
535 | 552 | end |
|
536 | 553 | |
|
537 | 554 | # Redirects user after a successful issue creation |
|
538 | 555 | def redirect_after_create |
|
539 | 556 | if params[:continue] |
|
540 | 557 | attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} |
|
541 | 558 | if params[:project_id] |
|
542 | 559 | redirect_to new_project_issue_path(@issue.project, :issue => attrs) |
|
543 | 560 | else |
|
544 | 561 | attrs.merge! :project_id => @issue.project_id |
|
545 | 562 | redirect_to new_issue_path(:issue => attrs) |
|
546 | 563 | end |
|
547 | 564 | else |
|
548 | 565 | redirect_to issue_path(@issue) |
|
549 | 566 | end |
|
550 | 567 | end |
|
551 | 568 | end |
@@ -1,215 +1,217 | |||
|
1 | 1 | <h2><%= @copy ? l(:button_copy) : l(:label_bulk_edit_selected_issues) %></h2> |
|
2 | 2 | |
|
3 | 3 | <% if @saved_issues && @unsaved_issues.present? %> |
|
4 | 4 | <div id="errorExplanation"> |
|
5 | 5 | <span> |
|
6 | 6 | <%= l(:notice_failed_to_save_issues, |
|
7 | 7 | :count => @unsaved_issues.size, |
|
8 | 8 | :total => @saved_issues.size, |
|
9 | 9 | :ids => @unsaved_issues.map {|i| "##{i.id}"}.join(', ')) %> |
|
10 | 10 | </span> |
|
11 | 11 | <ul> |
|
12 | 12 | <% bulk_edit_error_messages(@unsaved_issues).each do |message| %> |
|
13 | 13 | <li><%= message %></li> |
|
14 | 14 | <% end %> |
|
15 | 15 | </ul> |
|
16 | 16 | </div> |
|
17 | 17 | <% end %> |
|
18 | 18 | |
|
19 | 19 | <ul id="bulk-selection"> |
|
20 | 20 | <% @issues.each do |issue| %> |
|
21 | 21 | <%= content_tag 'li', link_to_issue(issue) %> |
|
22 | 22 | <% end %> |
|
23 | 23 | </ul> |
|
24 | 24 | |
|
25 | 25 | <%= form_tag(bulk_update_issues_path, :id => 'bulk_edit_form') do %> |
|
26 | 26 | <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id, :id => nil)}.join("\n").html_safe %> |
|
27 | 27 | <div class="box tabular"> |
|
28 | 28 | <fieldset class="attributes"> |
|
29 | 29 | <legend><%= l(:label_change_properties) %></legend> |
|
30 | 30 | |
|
31 | 31 | <div class="splitcontentleft"> |
|
32 | 32 | <% if @allowed_projects.present? %> |
|
33 | 33 | <p> |
|
34 | 34 | <label for="issue_project_id"><%= l(:field_project) %></label> |
|
35 | 35 | <%= select_tag('issue[project_id]', |
|
36 | 36 | project_tree_options_for_select(@allowed_projects, |
|
37 | 37 | :include_blank => ((!@copy || (@projects & @allowed_projects == @projects)) ? l(:label_no_change_option) : false), |
|
38 | 38 | :selected => @target_project), |
|
39 | 39 | :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %> |
|
40 | 40 | </p> |
|
41 | 41 | <% end %> |
|
42 | 42 | <p> |
|
43 | 43 | <label for="issue_tracker_id"><%= l(:field_tracker) %></label> |
|
44 | 44 | <%= select_tag('issue[tracker_id]', |
|
45 | 45 | content_tag('option', l(:label_no_change_option), :value => '') + |
|
46 |
options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id]) |
|
|
46 | options_from_collection_for_select(@trackers, :id, :name, @issue_params[:tracker_id]), | |
|
47 | :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %> | |
|
47 | 48 | </p> |
|
48 | 49 | <% if @available_statuses.any? %> |
|
49 | 50 | <p> |
|
50 | 51 | <label for='issue_status_id'><%= l(:field_status) %></label> |
|
51 | 52 | <%= select_tag('issue[status_id]', |
|
52 | 53 | content_tag('option', l(:label_no_change_option), :value => '') + |
|
53 |
options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id]) |
|
|
54 | options_from_collection_for_select(@available_statuses, :id, :name, @issue_params[:status_id]), | |
|
55 | :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')") %> | |
|
54 | 56 | </p> |
|
55 | 57 | <% end %> |
|
56 | 58 | |
|
57 | 59 | <% if @safe_attributes.include?('priority_id') -%> |
|
58 | 60 | <p> |
|
59 | 61 | <label for='issue_priority_id'><%= l(:field_priority) %></label> |
|
60 | 62 | <%= select_tag('issue[priority_id]', |
|
61 | 63 | content_tag('option', l(:label_no_change_option), :value => '') + |
|
62 | 64 | options_from_collection_for_select(IssuePriority.active, :id, :name, @issue_params[:priority_id])) %> |
|
63 | 65 | </p> |
|
64 | 66 | <% end %> |
|
65 | 67 | |
|
66 | 68 | <% if @safe_attributes.include?('assigned_to_id') -%> |
|
67 | 69 | <p> |
|
68 | 70 | <label for='issue_assigned_to_id'><%= l(:field_assigned_to) %></label> |
|
69 | 71 | <%= select_tag('issue[assigned_to_id]', |
|
70 | 72 | content_tag('option', l(:label_no_change_option), :value => '') + |
|
71 | 73 | content_tag('option', l(:label_nobody), :value => 'none', :selected => (@issue_params[:assigned_to_id] == 'none')) + |
|
72 | 74 | principals_options_for_select(@assignables, @issue_params[:assigned_to_id])) %> |
|
73 | 75 | </p> |
|
74 | 76 | <% end %> |
|
75 | 77 | |
|
76 | 78 | <% if @safe_attributes.include?('category_id') -%> |
|
77 | 79 | <p> |
|
78 | 80 | <label for='issue_category_id'><%= l(:field_category) %></label> |
|
79 | 81 | <%= select_tag('issue[category_id]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
80 | 82 | content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:category_id] == 'none')) + |
|
81 | 83 | options_from_collection_for_select(@categories, :id, :name, @issue_params[:category_id])) %> |
|
82 | 84 | </p> |
|
83 | 85 | <% end %> |
|
84 | 86 | |
|
85 | 87 | <% if @safe_attributes.include?('fixed_version_id') -%> |
|
86 | 88 | <p> |
|
87 | 89 | <label for='issue_fixed_version_id'><%= l(:field_fixed_version) %></label> |
|
88 | 90 | <%= select_tag('issue[fixed_version_id]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
89 | 91 | content_tag('option', l(:label_none), :value => 'none', :selected => (@issue_params[:fixed_version_id] == 'none')) + |
|
90 | 92 | version_options_for_select(@versions.sort, @issue_params[:fixed_version_id])) %> |
|
91 | 93 | </p> |
|
92 | 94 | <% end %> |
|
93 | 95 | |
|
94 | 96 | <% @custom_fields.each do |custom_field| %> |
|
95 | 97 | <p> |
|
96 | 98 | <label><%= custom_field.name %></label> |
|
97 | 99 | <%= custom_field_tag_for_bulk_edit('issue', custom_field, @issues, @issue_params[:custom_field_values][custom_field.id.to_s]) %> |
|
98 | 100 | </p> |
|
99 | 101 | <% end %> |
|
100 | 102 | |
|
101 | 103 | <% if @copy && Setting.link_copied_issue == 'ask' %> |
|
102 | 104 | <p> |
|
103 | 105 | <label for='link_copy'><%= l(:label_link_copied_issue) %></label> |
|
104 | 106 | <%= hidden_field_tag 'link_copy', '0' %> |
|
105 | 107 | <%= check_box_tag 'link_copy', '1', params[:link_copy] != 0 %> |
|
106 | 108 | </p> |
|
107 | 109 | <% end %> |
|
108 | 110 | |
|
109 | 111 | <% if @copy && @attachments_present %> |
|
110 | 112 | <%= hidden_field_tag 'copy_attachments', '0' %> |
|
111 | 113 | <p> |
|
112 | 114 | <label for='copy_attachments'><%= l(:label_copy_attachments) %></label> |
|
113 | 115 | <%= check_box_tag 'copy_attachments', '1', params[:copy_attachments] != '0' %> |
|
114 | 116 | </p> |
|
115 | 117 | <% end %> |
|
116 | 118 | |
|
117 | 119 | <% if @copy && @subtasks_present %> |
|
118 | 120 | <%= hidden_field_tag 'copy_subtasks', '0' %> |
|
119 | 121 | <p> |
|
120 | 122 | <label for='copy_subtasks'><%= l(:label_copy_subtasks) %></label> |
|
121 | 123 | <%= check_box_tag 'copy_subtasks', '1', params[:copy_subtasks] != '0' %> |
|
122 | 124 | </p> |
|
123 | 125 | <% end %> |
|
124 | 126 | |
|
125 | 127 | <%= call_hook(:view_issues_bulk_edit_details_bottom, { :issues => @issues }) %> |
|
126 | 128 | </div> |
|
127 | 129 | |
|
128 | 130 | <div class="splitcontentright"> |
|
129 | 131 | <% if @safe_attributes.include?('is_private') %> |
|
130 | 132 | <p> |
|
131 | 133 | <label for='issue_is_private'><%= l(:field_is_private) %></label> |
|
132 | 134 | <%= select_tag('issue[is_private]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
133 | 135 | content_tag('option', l(:general_text_Yes), :value => '1', :selected => (@issue_params[:is_private] == '1')) + |
|
134 | 136 | content_tag('option', l(:general_text_No), :value => '0', :selected => (@issue_params[:is_private] == '0'))) %> |
|
135 | 137 | </p> |
|
136 | 138 | <% end %> |
|
137 | 139 | |
|
138 | 140 | <% if @safe_attributes.include?('parent_issue_id') && @project %> |
|
139 | 141 | <p> |
|
140 | 142 | <label for='issue_parent_issue_id'><%= l(:field_parent_issue) %></label> |
|
141 | 143 | <%= text_field_tag 'issue[parent_issue_id]', '', :size => 10, :value => @issue_params[:parent_issue_id] %> |
|
142 | 144 | <label class="inline"><%= check_box_tag 'issue[parent_issue_id]', 'none', (@issue_params[:parent_issue_id] == 'none'), :id => nil, :data => {:disables => '#issue_parent_issue_id'} %><%= l(:button_clear) %></label> |
|
143 | 145 | </p> |
|
144 | 146 | <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => Setting.cross_project_subtasks)}')" %> |
|
145 | 147 | <% end %> |
|
146 | 148 | |
|
147 | 149 | <% if @safe_attributes.include?('start_date') %> |
|
148 | 150 | <p> |
|
149 | 151 | <label for='issue_start_date'><%= l(:field_start_date) %></label> |
|
150 | 152 | <%= date_field_tag 'issue[start_date]', '', :value => @issue_params[:start_date], :size => 10 %><%= calendar_for('issue_start_date') %> |
|
151 | 153 | <label class="inline"><%= check_box_tag 'issue[start_date]', 'none', (@issue_params[:start_date] == 'none'), :id => nil, :data => {:disables => '#issue_start_date'} %><%= l(:button_clear) %></label> |
|
152 | 154 | </p> |
|
153 | 155 | <% end %> |
|
154 | 156 | |
|
155 | 157 | <% if @safe_attributes.include?('due_date') %> |
|
156 | 158 | <p> |
|
157 | 159 | <label for='issue_due_date'><%= l(:field_due_date) %></label> |
|
158 | 160 | <%= date_field_tag 'issue[due_date]', '', :value => @issue_params[:due_date], :size => 10 %><%= calendar_for('issue_due_date') %> |
|
159 | 161 | <label class="inline"><%= check_box_tag 'issue[due_date]', 'none', (@issue_params[:due_date] == 'none'), :id => nil, :data => {:disables => '#issue_due_date'} %><%= l(:button_clear) %></label> |
|
160 | 162 | </p> |
|
161 | 163 | <% end %> |
|
162 | 164 | |
|
163 | 165 | <% if @safe_attributes.include?('estimated_hours') %> |
|
164 | 166 | <p> |
|
165 | 167 | <label for='issue_estimated_hours'><%= l(:field_estimated_hours) %></label> |
|
166 | 168 | <%= text_field_tag 'issue[estimated_hours]', '', :value => @issue_params[:estimated_hours], :size => 10 %> |
|
167 | 169 | <label class="inline"><%= check_box_tag 'issue[estimated_hours]', 'none', (@issue_params[:estimated_hours] == 'none'), :id => nil, :data => {:disables => '#issue_estimated_hours'} %><%= l(:button_clear) %></label> |
|
168 | 170 | </p> |
|
169 | 171 | <% end %> |
|
170 | 172 | |
|
171 | 173 | <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %> |
|
172 | 174 | <p> |
|
173 | 175 | <label for='issue_done_ratio'><%= l(:field_done_ratio) %></label> |
|
174 | 176 | <%= select_tag 'issue[done_ratio]', options_for_select([[l(:label_no_change_option), '']] + (0..10).to_a.collect {|r| ["#{r*10} %", r*10] }, @issue_params[:done_ratio]) %> |
|
175 | 177 | </p> |
|
176 | 178 | <% end %> |
|
177 | 179 | </div> |
|
178 | 180 | </fieldset> |
|
179 | 181 | |
|
180 | 182 | <fieldset> |
|
181 | 183 | <legend><%= l(:field_notes) %></legend> |
|
182 | 184 | <%= text_area_tag 'notes', @notes, :cols => 60, :rows => 10, :class => 'wiki-edit' %> |
|
183 | 185 | <%= wikitoolbar_for 'notes' %> |
|
184 | 186 | </fieldset> |
|
185 | 187 | </div> |
|
186 | 188 | |
|
187 | 189 | <p> |
|
188 | 190 | <% if @copy %> |
|
189 | 191 | <%= hidden_field_tag 'copy', '1' %> |
|
190 | 192 | <%= submit_tag l(:button_copy) %> |
|
191 | 193 | <%= submit_tag l(:button_copy_and_follow), :name => 'follow' %> |
|
192 | 194 | <% elsif @target_project %> |
|
193 | 195 | <%= submit_tag l(:button_move) %> |
|
194 | 196 | <%= submit_tag l(:button_move_and_follow), :name => 'follow' %> |
|
195 | 197 | <% else %> |
|
196 | 198 | <%= submit_tag l(:button_submit) %> |
|
197 | 199 | <% end %> |
|
198 | 200 | </p> |
|
199 | 201 | |
|
200 | 202 | <% end %> |
|
201 | 203 | |
|
202 | 204 | <%= javascript_tag do %> |
|
203 | 205 | $(window).load(function(){ |
|
204 | 206 | $(document).on('change', 'input[data-disables]', function(){ |
|
205 | 207 | if ($(this).prop('checked')){ |
|
206 | 208 | $($(this).data('disables')).attr('disabled', true).val(''); |
|
207 | 209 | } else { |
|
208 | 210 | $($(this).data('disables')).attr('disabled', false); |
|
209 | 211 | } |
|
210 | 212 | }); |
|
211 | 213 | }); |
|
212 | 214 | $(document).ready(function(){ |
|
213 | 215 | $('input[data-disables]').trigger('change'); |
|
214 | 216 | }); |
|
215 | 217 | <% end %> |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now