##// END OF EJS Templates
Fixed that bulk copy raises an error on validation failure (#13943)....
Jean-Philippe Lang -
r11558:d69de691a79b
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,450 +1,452
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssuesController < ApplicationController
18 class IssuesController < ApplicationController
19 menu_item :new_issue, :only => [:new, :create]
19 menu_item :new_issue, :only => [:new, :create]
20 default_search_scope :issues
20 default_search_scope :issues
21
21
22 before_filter :find_issue, :only => [:show, :edit, :update]
22 before_filter :find_issue, :only => [:show, :edit, :update]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
24 before_filter :find_project, :only => [:new, :create, :update_form]
24 before_filter :find_project, :only => [:new, :create, :update_form]
25 before_filter :authorize, :except => [:index]
25 before_filter :authorize, :except => [:index]
26 before_filter :find_optional_project, :only => [:index]
26 before_filter :find_optional_project, :only => [:index]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
28 before_filter :build_new_issue_from_params, :only => [:new, :create, :update_form]
29 accept_rss_auth :index, :show
29 accept_rss_auth :index, :show
30 accept_api_auth :index, :show, :create, :update, :destroy
30 accept_api_auth :index, :show, :create, :update, :destroy
31
31
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33
33
34 helper :journals
34 helper :journals
35 helper :projects
35 helper :projects
36 include ProjectsHelper
36 include ProjectsHelper
37 helper :custom_fields
37 helper :custom_fields
38 include CustomFieldsHelper
38 include CustomFieldsHelper
39 helper :issue_relations
39 helper :issue_relations
40 include IssueRelationsHelper
40 include IssueRelationsHelper
41 helper :watchers
41 helper :watchers
42 include WatchersHelper
42 include WatchersHelper
43 helper :attachments
43 helper :attachments
44 include AttachmentsHelper
44 include AttachmentsHelper
45 helper :queries
45 helper :queries
46 include QueriesHelper
46 include QueriesHelper
47 helper :repositories
47 helper :repositories
48 include RepositoriesHelper
48 include RepositoriesHelper
49 helper :sort
49 helper :sort
50 include SortHelper
50 include SortHelper
51 include IssuesHelper
51 include IssuesHelper
52 helper :timelog
52 helper :timelog
53 include Redmine::Export::PDF
53 include Redmine::Export::PDF
54
54
55 def index
55 def index
56 retrieve_query
56 retrieve_query
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
58 sort_update(@query.sortable_columns)
58 sort_update(@query.sortable_columns)
59 @query.sort_criteria = sort_criteria.to_a
59 @query.sort_criteria = sort_criteria.to_a
60
60
61 if @query.valid?
61 if @query.valid?
62 case params[:format]
62 case params[:format]
63 when 'csv', 'pdf'
63 when 'csv', 'pdf'
64 @limit = Setting.issues_export_limit.to_i
64 @limit = Setting.issues_export_limit.to_i
65 when 'atom'
65 when 'atom'
66 @limit = Setting.feeds_limit.to_i
66 @limit = Setting.feeds_limit.to_i
67 when 'xml', 'json'
67 when 'xml', 'json'
68 @offset, @limit = api_offset_and_limit
68 @offset, @limit = api_offset_and_limit
69 else
69 else
70 @limit = per_page_option
70 @limit = per_page_option
71 end
71 end
72
72
73 @issue_count = @query.issue_count
73 @issue_count = @query.issue_count
74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
74 @issue_pages = Paginator.new @issue_count, @limit, params['page']
75 @offset ||= @issue_pages.offset
75 @offset ||= @issue_pages.offset
76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
76 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
77 :order => sort_clause,
77 :order => sort_clause,
78 :offset => @offset,
78 :offset => @offset,
79 :limit => @limit)
79 :limit => @limit)
80 @issue_count_by_group = @query.issue_count_by_group
80 @issue_count_by_group = @query.issue_count_by_group
81
81
82 respond_to do |format|
82 respond_to do |format|
83 format.html { render :template => 'issues/index', :layout => !request.xhr? }
83 format.html { render :template => 'issues/index', :layout => !request.xhr? }
84 format.api {
84 format.api {
85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
85 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
86 }
86 }
87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
88 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
88 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
89 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
90 end
90 end
91 else
91 else
92 respond_to do |format|
92 respond_to do |format|
93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
93 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
94 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
94 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
95 format.api { render_validation_errors(@query) }
95 format.api { render_validation_errors(@query) }
96 end
96 end
97 end
97 end
98 rescue ActiveRecord::RecordNotFound
98 rescue ActiveRecord::RecordNotFound
99 render_404
99 render_404
100 end
100 end
101
101
102 def show
102 def show
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
103 @journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
104 @journals.each_with_index {|j,i| j.indice = i+1}
104 @journals.each_with_index {|j,i| j.indice = i+1}
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
105 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
106 @journals.reverse! if User.current.wants_comments_in_reverse_order?
107
107
108 @changesets = @issue.changesets.visible.all
108 @changesets = @issue.changesets.visible.all
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
109 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
110
110
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
111 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
112 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
113 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
114 @priorities = IssuePriority.active
114 @priorities = IssuePriority.active
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
115 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
116 @relation = IssueRelation.new
116 @relation = IssueRelation.new
117
117
118 respond_to do |format|
118 respond_to do |format|
119 format.html {
119 format.html {
120 retrieve_previous_and_next_issue_ids
120 retrieve_previous_and_next_issue_ids
121 render :template => 'issues/show'
121 render :template => 'issues/show'
122 }
122 }
123 format.api
123 format.api
124 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
124 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
125 format.pdf {
125 format.pdf {
126 pdf = issue_to_pdf(@issue, :journals => @journals)
126 pdf = issue_to_pdf(@issue, :journals => @journals)
127 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
127 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
128 }
128 }
129 end
129 end
130 end
130 end
131
131
132 # Add a new issue
132 # Add a new issue
133 # The new issue will be created from an existing one if copy_from parameter is given
133 # The new issue will be created from an existing one if copy_from parameter is given
134 def new
134 def new
135 respond_to do |format|
135 respond_to do |format|
136 format.html { render :action => 'new', :layout => !request.xhr? }
136 format.html { render :action => 'new', :layout => !request.xhr? }
137 end
137 end
138 end
138 end
139
139
140 def create
140 def create
141 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
141 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
142 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
142 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
143 if @issue.save
143 if @issue.save
144 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
144 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
145 respond_to do |format|
145 respond_to do |format|
146 format.html {
146 format.html {
147 render_attachment_warning_if_needed(@issue)
147 render_attachment_warning_if_needed(@issue)
148 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
148 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
149 if params[:continue]
149 if params[:continue]
150 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
150 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
151 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
151 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
152 else
152 else
153 redirect_to issue_path(@issue)
153 redirect_to issue_path(@issue)
154 end
154 end
155 }
155 }
156 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
156 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
157 end
157 end
158 return
158 return
159 else
159 else
160 respond_to do |format|
160 respond_to do |format|
161 format.html { render :action => 'new' }
161 format.html { render :action => 'new' }
162 format.api { render_validation_errors(@issue) }
162 format.api { render_validation_errors(@issue) }
163 end
163 end
164 end
164 end
165 end
165 end
166
166
167 def edit
167 def edit
168 return unless update_issue_from_params
168 return unless update_issue_from_params
169
169
170 respond_to do |format|
170 respond_to do |format|
171 format.html { }
171 format.html { }
172 format.xml { }
172 format.xml { }
173 end
173 end
174 end
174 end
175
175
176 def update
176 def update
177 return unless update_issue_from_params
177 return unless update_issue_from_params
178 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
178 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
179 saved = false
179 saved = false
180 begin
180 begin
181 saved = @issue.save_issue_with_child_records(params, @time_entry)
181 saved = @issue.save_issue_with_child_records(params, @time_entry)
182 rescue ActiveRecord::StaleObjectError
182 rescue ActiveRecord::StaleObjectError
183 @conflict = true
183 @conflict = true
184 if params[:last_journal_id]
184 if params[:last_journal_id]
185 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
185 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
186 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
186 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
187 end
187 end
188 end
188 end
189
189
190 if saved
190 if saved
191 render_attachment_warning_if_needed(@issue)
191 render_attachment_warning_if_needed(@issue)
192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
193
193
194 respond_to do |format|
194 respond_to do |format|
195 format.html { redirect_back_or_default issue_path(@issue) }
195 format.html { redirect_back_or_default issue_path(@issue) }
196 format.api { render_api_ok }
196 format.api { render_api_ok }
197 end
197 end
198 else
198 else
199 respond_to do |format|
199 respond_to do |format|
200 format.html { render :action => 'edit' }
200 format.html { render :action => 'edit' }
201 format.api { render_validation_errors(@issue) }
201 format.api { render_validation_errors(@issue) }
202 end
202 end
203 end
203 end
204 end
204 end
205
205
206 # Updates the issue form when changing the project, status or tracker
206 # Updates the issue form when changing the project, status or tracker
207 # on issue creation/update
207 # on issue creation/update
208 def update_form
208 def update_form
209 end
209 end
210
210
211 # Bulk edit/copy a set of issues
211 # Bulk edit/copy a set of issues
212 def bulk_edit
212 def bulk_edit
213 @issues.sort!
213 @issues.sort!
214 @copy = params[:copy].present?
214 @copy = params[:copy].present?
215 @notes = params[:notes]
215 @notes = params[:notes]
216
216
217 if User.current.allowed_to?(:move_issues, @projects)
217 if User.current.allowed_to?(:move_issues, @projects)
218 @allowed_projects = Issue.allowed_target_projects_on_move
218 @allowed_projects = Issue.allowed_target_projects_on_move
219 if params[:issue]
219 if params[:issue]
220 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
220 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
221 if @target_project
221 if @target_project
222 target_projects = [@target_project]
222 target_projects = [@target_project]
223 end
223 end
224 end
224 end
225 end
225 end
226 target_projects ||= @projects
226 target_projects ||= @projects
227
227
228 if @copy
228 if @copy
229 @available_statuses = [IssueStatus.default]
229 @available_statuses = [IssueStatus.default]
230 else
230 else
231 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
231 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
232 end
232 end
233 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
233 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
234 @assignables = target_projects.map(&:assignable_users).reduce(:&)
234 @assignables = target_projects.map(&:assignable_users).reduce(:&)
235 @trackers = target_projects.map(&:trackers).reduce(:&)
235 @trackers = target_projects.map(&:trackers).reduce(:&)
236 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
236 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
237 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
237 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
238 if @copy
238 if @copy
239 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
239 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
240 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
240 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
241 end
241 end
242
242
243 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
243 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
244
244
245 @issue_params = params[:issue] || {}
245 @issue_params = params[:issue] || {}
246 @issue_params[:custom_field_values] ||= {}
246 @issue_params[:custom_field_values] ||= {}
247 end
247 end
248
248
249 def bulk_update
249 def bulk_update
250 @issues.sort!
250 @issues.sort!
251 @copy = params[:copy].present?
251 @copy = params[:copy].present?
252 attributes = parse_params_for_bulk_issue_attributes(params)
252 attributes = parse_params_for_bulk_issue_attributes(params)
253
253
254 unsaved_issues = []
254 unsaved_issues = []
255 saved_issues = []
255 saved_issues = []
256
256
257 if @copy && params[:copy_subtasks].present?
257 if @copy && params[:copy_subtasks].present?
258 # Descendant issues will be copied with the parent task
258 # Descendant issues will be copied with the parent task
259 # Don't copy them twice
259 # Don't copy them twice
260 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
260 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
261 end
261 end
262
262
263 @issues.each do |issue|
263 @issues.each do |orig_issue|
264 issue.reload
264 orig_issue.reload
265 if @copy
265 if @copy
266 issue = issue.copy({},
266 issue = orig_issue.copy({},
267 :attachments => params[:copy_attachments].present?,
267 :attachments => params[:copy_attachments].present?,
268 :subtasks => params[:copy_subtasks].present?
268 :subtasks => params[:copy_subtasks].present?
269 )
269 )
270 else
271 issue = orig_issue
270 end
272 end
271 journal = issue.init_journal(User.current, params[:notes])
273 journal = issue.init_journal(User.current, params[:notes])
272 issue.safe_attributes = attributes
274 issue.safe_attributes = attributes
273 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
275 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
274 if issue.save
276 if issue.save
275 saved_issues << issue
277 saved_issues << issue
276 else
278 else
277 unsaved_issues << issue
279 unsaved_issues << orig_issue
278 end
280 end
279 end
281 end
280
282
281 if unsaved_issues.empty?
283 if unsaved_issues.empty?
282 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
284 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
283 if params[:follow]
285 if params[:follow]
284 if @issues.size == 1 && saved_issues.size == 1
286 if @issues.size == 1 && saved_issues.size == 1
285 redirect_to issue_path(saved_issues.first)
287 redirect_to issue_path(saved_issues.first)
286 elsif saved_issues.map(&:project).uniq.size == 1
288 elsif saved_issues.map(&:project).uniq.size == 1
287 redirect_to project_issues_path(saved_issues.map(&:project).first)
289 redirect_to project_issues_path(saved_issues.map(&:project).first)
288 end
290 end
289 else
291 else
290 redirect_back_or_default _project_issues_path(@project)
292 redirect_back_or_default _project_issues_path(@project)
291 end
293 end
292 else
294 else
293 @saved_issues = @issues
295 @saved_issues = @issues
294 @unsaved_issues = unsaved_issues
296 @unsaved_issues = unsaved_issues
295 @issues = Issue.visible.find_all_by_id(@unsaved_issues.map(&:id))
297 @issues = Issue.visible.find_all_by_id(@unsaved_issues.map(&:id))
296 bulk_edit
298 bulk_edit
297 render :action => 'bulk_edit'
299 render :action => 'bulk_edit'
298 end
300 end
299 end
301 end
300
302
301 def destroy
303 def destroy
302 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
304 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
303 if @hours > 0
305 if @hours > 0
304 case params[:todo]
306 case params[:todo]
305 when 'destroy'
307 when 'destroy'
306 # nothing to do
308 # nothing to do
307 when 'nullify'
309 when 'nullify'
308 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
310 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
309 when 'reassign'
311 when 'reassign'
310 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
312 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
311 if reassign_to.nil?
313 if reassign_to.nil?
312 flash.now[:error] = l(:error_issue_not_found_in_project)
314 flash.now[:error] = l(:error_issue_not_found_in_project)
313 return
315 return
314 else
316 else
315 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
317 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
316 end
318 end
317 else
319 else
318 # display the destroy form if it's a user request
320 # display the destroy form if it's a user request
319 return unless api_request?
321 return unless api_request?
320 end
322 end
321 end
323 end
322 @issues.each do |issue|
324 @issues.each do |issue|
323 begin
325 begin
324 issue.reload.destroy
326 issue.reload.destroy
325 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
327 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
326 # nothing to do, issue was already deleted (eg. by a parent)
328 # nothing to do, issue was already deleted (eg. by a parent)
327 end
329 end
328 end
330 end
329 respond_to do |format|
331 respond_to do |format|
330 format.html { redirect_back_or_default _project_issues_path(@project) }
332 format.html { redirect_back_or_default _project_issues_path(@project) }
331 format.api { render_api_ok }
333 format.api { render_api_ok }
332 end
334 end
333 end
335 end
334
336
335 private
337 private
336
338
337 def find_project
339 def find_project
338 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
340 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
339 @project = Project.find(project_id)
341 @project = Project.find(project_id)
340 rescue ActiveRecord::RecordNotFound
342 rescue ActiveRecord::RecordNotFound
341 render_404
343 render_404
342 end
344 end
343
345
344 def retrieve_previous_and_next_issue_ids
346 def retrieve_previous_and_next_issue_ids
345 retrieve_query_from_session
347 retrieve_query_from_session
346 if @query
348 if @query
347 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
349 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
348 sort_update(@query.sortable_columns, 'issues_index_sort')
350 sort_update(@query.sortable_columns, 'issues_index_sort')
349 limit = 500
351 limit = 500
350 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
352 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
351 if (idx = issue_ids.index(@issue.id)) && idx < limit
353 if (idx = issue_ids.index(@issue.id)) && idx < limit
352 if issue_ids.size < 500
354 if issue_ids.size < 500
353 @issue_position = idx + 1
355 @issue_position = idx + 1
354 @issue_count = issue_ids.size
356 @issue_count = issue_ids.size
355 end
357 end
356 @prev_issue_id = issue_ids[idx - 1] if idx > 0
358 @prev_issue_id = issue_ids[idx - 1] if idx > 0
357 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
359 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
358 end
360 end
359 end
361 end
360 end
362 end
361
363
362 # Used by #edit and #update to set some common instance variables
364 # Used by #edit and #update to set some common instance variables
363 # from the params
365 # from the params
364 # TODO: Refactor, not everything in here is needed by #edit
366 # TODO: Refactor, not everything in here is needed by #edit
365 def update_issue_from_params
367 def update_issue_from_params
366 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
368 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
367 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
369 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
368 @time_entry.attributes = params[:time_entry]
370 @time_entry.attributes = params[:time_entry]
369
371
370 @issue.init_journal(User.current)
372 @issue.init_journal(User.current)
371
373
372 issue_attributes = params[:issue]
374 issue_attributes = params[:issue]
373 if issue_attributes && params[:conflict_resolution]
375 if issue_attributes && params[:conflict_resolution]
374 case params[:conflict_resolution]
376 case params[:conflict_resolution]
375 when 'overwrite'
377 when 'overwrite'
376 issue_attributes = issue_attributes.dup
378 issue_attributes = issue_attributes.dup
377 issue_attributes.delete(:lock_version)
379 issue_attributes.delete(:lock_version)
378 when 'add_notes'
380 when 'add_notes'
379 issue_attributes = issue_attributes.slice(:notes)
381 issue_attributes = issue_attributes.slice(:notes)
380 when 'cancel'
382 when 'cancel'
381 redirect_to issue_path(@issue)
383 redirect_to issue_path(@issue)
382 return false
384 return false
383 end
385 end
384 end
386 end
385 @issue.safe_attributes = issue_attributes
387 @issue.safe_attributes = issue_attributes
386 @priorities = IssuePriority.active
388 @priorities = IssuePriority.active
387 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
389 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
388 true
390 true
389 end
391 end
390
392
391 # TODO: Refactor, lots of extra code in here
393 # TODO: Refactor, lots of extra code in here
392 # TODO: Changing tracker on an existing issue should not trigger this
394 # TODO: Changing tracker on an existing issue should not trigger this
393 def build_new_issue_from_params
395 def build_new_issue_from_params
394 if params[:id].blank?
396 if params[:id].blank?
395 @issue = Issue.new
397 @issue = Issue.new
396 if params[:copy_from]
398 if params[:copy_from]
397 begin
399 begin
398 @copy_from = Issue.visible.find(params[:copy_from])
400 @copy_from = Issue.visible.find(params[:copy_from])
399 @copy_attachments = params[:copy_attachments].present? || request.get?
401 @copy_attachments = params[:copy_attachments].present? || request.get?
400 @copy_subtasks = params[:copy_subtasks].present? || request.get?
402 @copy_subtasks = params[:copy_subtasks].present? || request.get?
401 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
403 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
402 rescue ActiveRecord::RecordNotFound
404 rescue ActiveRecord::RecordNotFound
403 render_404
405 render_404
404 return
406 return
405 end
407 end
406 end
408 end
407 @issue.project = @project
409 @issue.project = @project
408 else
410 else
409 @issue = @project.issues.visible.find(params[:id])
411 @issue = @project.issues.visible.find(params[:id])
410 end
412 end
411
413
412 @issue.project = @project
414 @issue.project = @project
413 @issue.author ||= User.current
415 @issue.author ||= User.current
414 # Tracker must be set before custom field values
416 # Tracker must be set before custom field values
415 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
417 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
416 if @issue.tracker.nil?
418 if @issue.tracker.nil?
417 render_error l(:error_no_tracker_in_project)
419 render_error l(:error_no_tracker_in_project)
418 return false
420 return false
419 end
421 end
420 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
422 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
421 @issue.safe_attributes = params[:issue]
423 @issue.safe_attributes = params[:issue]
422
424
423 @priorities = IssuePriority.active
425 @priorities = IssuePriority.active
424 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
426 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
425 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
427 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
426 end
428 end
427
429
428 def check_for_default_issue_status
430 def check_for_default_issue_status
429 if IssueStatus.default.nil?
431 if IssueStatus.default.nil?
430 render_error l(:error_no_default_issue_status)
432 render_error l(:error_no_default_issue_status)
431 return false
433 return false
432 end
434 end
433 end
435 end
434
436
435 def parse_params_for_bulk_issue_attributes(params)
437 def parse_params_for_bulk_issue_attributes(params)
436 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
438 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
437 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
439 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
438 if custom = attributes[:custom_field_values]
440 if custom = attributes[:custom_field_values]
439 custom.reject! {|k,v| v.blank?}
441 custom.reject! {|k,v| v.blank?}
440 custom.keys.each do |k|
442 custom.keys.each do |k|
441 if custom[k].is_a?(Array)
443 if custom[k].is_a?(Array)
442 custom[k] << '' if custom[k].delete('__none__')
444 custom[k] << '' if custom[k].delete('__none__')
443 else
445 else
444 custom[k] = '' if custom[k] == '__none__'
446 custom[k] = '' if custom[k] == '__none__'
445 end
447 end
446 end
448 end
447 end
449 end
448 attributes
450 attributes
449 end
451 end
450 end
452 end
1 NO CONTENT: modified file
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