##// END OF EJS Templates
Fixed that update_form always proposes the default status when updating an existing issue (#15344)....
Jean-Philippe Lang -
r12047:71c61f4996ae
parent child
Show More

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

@@ -1,477 +1,477
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 Journal.preload_journals_details_custom_fields(@journals)
106 Journal.preload_journals_details_custom_fields(@journals)
107 # TODO: use #select! when ruby1.8 support is dropped
107 # TODO: use #select! when ruby1.8 support is dropped
108 @journals.reject! {|journal| !journal.notes? && journal.visible_details.empty?}
108 @journals.reject! {|journal| !journal.notes? && journal.visible_details.empty?}
109 @journals.reverse! if User.current.wants_comments_in_reverse_order?
109 @journals.reverse! if User.current.wants_comments_in_reverse_order?
110
110
111 @changesets = @issue.changesets.visible.all
111 @changesets = @issue.changesets.visible.all
112 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
112 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
113
113
114 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
114 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
115 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
115 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
116 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
116 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
117 @priorities = IssuePriority.active
117 @priorities = IssuePriority.active
118 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
118 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
119 @relation = IssueRelation.new
119 @relation = IssueRelation.new
120
120
121 respond_to do |format|
121 respond_to do |format|
122 format.html {
122 format.html {
123 retrieve_previous_and_next_issue_ids
123 retrieve_previous_and_next_issue_ids
124 render :template => 'issues/show'
124 render :template => 'issues/show'
125 }
125 }
126 format.api
126 format.api
127 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
127 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
128 format.pdf {
128 format.pdf {
129 pdf = issue_to_pdf(@issue, :journals => @journals)
129 pdf = issue_to_pdf(@issue, :journals => @journals)
130 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
130 send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
131 }
131 }
132 end
132 end
133 end
133 end
134
134
135 # Add a new issue
135 # Add a new issue
136 # The new issue will be created from an existing one if copy_from parameter is given
136 # The new issue will be created from an existing one if copy_from parameter is given
137 def new
137 def new
138 respond_to do |format|
138 respond_to do |format|
139 format.html { render :action => 'new', :layout => !request.xhr? }
139 format.html { render :action => 'new', :layout => !request.xhr? }
140 end
140 end
141 end
141 end
142
142
143 def create
143 def create
144 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
144 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
145 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
145 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
146 if @issue.save
146 if @issue.save
147 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
147 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
148 respond_to do |format|
148 respond_to do |format|
149 format.html {
149 format.html {
150 render_attachment_warning_if_needed(@issue)
150 render_attachment_warning_if_needed(@issue)
151 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
151 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
152 if params[:continue]
152 if params[:continue]
153 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
153 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
154 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
154 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
155 else
155 else
156 redirect_to issue_path(@issue)
156 redirect_to issue_path(@issue)
157 end
157 end
158 }
158 }
159 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
159 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
160 end
160 end
161 return
161 return
162 else
162 else
163 respond_to do |format|
163 respond_to do |format|
164 format.html { render :action => 'new' }
164 format.html { render :action => 'new' }
165 format.api { render_validation_errors(@issue) }
165 format.api { render_validation_errors(@issue) }
166 end
166 end
167 end
167 end
168 end
168 end
169
169
170 def edit
170 def edit
171 return unless update_issue_from_params
171 return unless update_issue_from_params
172
172
173 respond_to do |format|
173 respond_to do |format|
174 format.html { }
174 format.html { }
175 format.xml { }
175 format.xml { }
176 end
176 end
177 end
177 end
178
178
179 def update
179 def update
180 return unless update_issue_from_params
180 return unless update_issue_from_params
181 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
181 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
182 saved = false
182 saved = false
183 begin
183 begin
184 saved = save_issue_with_child_records
184 saved = save_issue_with_child_records
185 rescue ActiveRecord::StaleObjectError
185 rescue ActiveRecord::StaleObjectError
186 @conflict = true
186 @conflict = true
187 if params[:last_journal_id]
187 if params[:last_journal_id]
188 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
188 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
189 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
189 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
190 end
190 end
191 end
191 end
192
192
193 if saved
193 if saved
194 render_attachment_warning_if_needed(@issue)
194 render_attachment_warning_if_needed(@issue)
195 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
195 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
196
196
197 respond_to do |format|
197 respond_to do |format|
198 format.html { redirect_back_or_default issue_path(@issue) }
198 format.html { redirect_back_or_default issue_path(@issue) }
199 format.api { render_api_ok }
199 format.api { render_api_ok }
200 end
200 end
201 else
201 else
202 respond_to do |format|
202 respond_to do |format|
203 format.html { render :action => 'edit' }
203 format.html { render :action => 'edit' }
204 format.api { render_validation_errors(@issue) }
204 format.api { render_validation_errors(@issue) }
205 end
205 end
206 end
206 end
207 end
207 end
208
208
209 # Updates the issue form when changing the project, status or tracker
209 # Updates the issue form when changing the project, status or tracker
210 # on issue creation/update
210 # on issue creation/update
211 def update_form
211 def update_form
212 end
212 end
213
213
214 # Bulk edit/copy a set of issues
214 # Bulk edit/copy a set of issues
215 def bulk_edit
215 def bulk_edit
216 @issues.sort!
216 @issues.sort!
217 @copy = params[:copy].present?
217 @copy = params[:copy].present?
218 @notes = params[:notes]
218 @notes = params[:notes]
219
219
220 if User.current.allowed_to?(:move_issues, @projects)
220 if User.current.allowed_to?(:move_issues, @projects)
221 @allowed_projects = Issue.allowed_target_projects_on_move
221 @allowed_projects = Issue.allowed_target_projects_on_move
222 if params[:issue]
222 if params[:issue]
223 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
223 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
224 if @target_project
224 if @target_project
225 target_projects = [@target_project]
225 target_projects = [@target_project]
226 end
226 end
227 end
227 end
228 end
228 end
229 target_projects ||= @projects
229 target_projects ||= @projects
230
230
231 if @copy
231 if @copy
232 @available_statuses = [IssueStatus.default]
232 @available_statuses = [IssueStatus.default]
233 else
233 else
234 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
234 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
235 end
235 end
236 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
236 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
237 @assignables = target_projects.map(&:assignable_users).reduce(:&)
237 @assignables = target_projects.map(&:assignable_users).reduce(:&)
238 @trackers = target_projects.map(&:trackers).reduce(:&)
238 @trackers = target_projects.map(&:trackers).reduce(:&)
239 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
239 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
240 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
240 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
241 if @copy
241 if @copy
242 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
242 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
243 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
243 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
244 end
244 end
245
245
246 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
246 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
247
247
248 @issue_params = params[:issue] || {}
248 @issue_params = params[:issue] || {}
249 @issue_params[:custom_field_values] ||= {}
249 @issue_params[:custom_field_values] ||= {}
250 end
250 end
251
251
252 def bulk_update
252 def bulk_update
253 @issues.sort!
253 @issues.sort!
254 @copy = params[:copy].present?
254 @copy = params[:copy].present?
255 attributes = parse_params_for_bulk_issue_attributes(params)
255 attributes = parse_params_for_bulk_issue_attributes(params)
256
256
257 unsaved_issues = []
257 unsaved_issues = []
258 saved_issues = []
258 saved_issues = []
259
259
260 if @copy && params[:copy_subtasks].present?
260 if @copy && params[:copy_subtasks].present?
261 # Descendant issues will be copied with the parent task
261 # Descendant issues will be copied with the parent task
262 # Don't copy them twice
262 # Don't copy them twice
263 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
263 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
264 end
264 end
265
265
266 @issues.each do |orig_issue|
266 @issues.each do |orig_issue|
267 orig_issue.reload
267 orig_issue.reload
268 if @copy
268 if @copy
269 issue = orig_issue.copy({},
269 issue = orig_issue.copy({},
270 :attachments => params[:copy_attachments].present?,
270 :attachments => params[:copy_attachments].present?,
271 :subtasks => params[:copy_subtasks].present?
271 :subtasks => params[:copy_subtasks].present?
272 )
272 )
273 else
273 else
274 issue = orig_issue
274 issue = orig_issue
275 end
275 end
276 journal = issue.init_journal(User.current, params[:notes])
276 journal = issue.init_journal(User.current, params[:notes])
277 issue.safe_attributes = attributes
277 issue.safe_attributes = attributes
278 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
278 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
279 if issue.save
279 if issue.save
280 saved_issues << issue
280 saved_issues << issue
281 else
281 else
282 unsaved_issues << orig_issue
282 unsaved_issues << orig_issue
283 end
283 end
284 end
284 end
285
285
286 if unsaved_issues.empty?
286 if unsaved_issues.empty?
287 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
287 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
288 if params[:follow]
288 if params[:follow]
289 if @issues.size == 1 && saved_issues.size == 1
289 if @issues.size == 1 && saved_issues.size == 1
290 redirect_to issue_path(saved_issues.first)
290 redirect_to issue_path(saved_issues.first)
291 elsif saved_issues.map(&:project).uniq.size == 1
291 elsif saved_issues.map(&:project).uniq.size == 1
292 redirect_to project_issues_path(saved_issues.map(&:project).first)
292 redirect_to project_issues_path(saved_issues.map(&:project).first)
293 end
293 end
294 else
294 else
295 redirect_back_or_default _project_issues_path(@project)
295 redirect_back_or_default _project_issues_path(@project)
296 end
296 end
297 else
297 else
298 @saved_issues = @issues
298 @saved_issues = @issues
299 @unsaved_issues = unsaved_issues
299 @unsaved_issues = unsaved_issues
300 @issues = Issue.visible.find_all_by_id(@unsaved_issues.map(&:id))
300 @issues = Issue.visible.find_all_by_id(@unsaved_issues.map(&:id))
301 bulk_edit
301 bulk_edit
302 render :action => 'bulk_edit'
302 render :action => 'bulk_edit'
303 end
303 end
304 end
304 end
305
305
306 def destroy
306 def destroy
307 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
307 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
308 if @hours > 0
308 if @hours > 0
309 case params[:todo]
309 case params[:todo]
310 when 'destroy'
310 when 'destroy'
311 # nothing to do
311 # nothing to do
312 when 'nullify'
312 when 'nullify'
313 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
313 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
314 when 'reassign'
314 when 'reassign'
315 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
315 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
316 if reassign_to.nil?
316 if reassign_to.nil?
317 flash.now[:error] = l(:error_issue_not_found_in_project)
317 flash.now[:error] = l(:error_issue_not_found_in_project)
318 return
318 return
319 else
319 else
320 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
320 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
321 end
321 end
322 else
322 else
323 # display the destroy form if it's a user request
323 # display the destroy form if it's a user request
324 return unless api_request?
324 return unless api_request?
325 end
325 end
326 end
326 end
327 @issues.each do |issue|
327 @issues.each do |issue|
328 begin
328 begin
329 issue.reload.destroy
329 issue.reload.destroy
330 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
330 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
331 # nothing to do, issue was already deleted (eg. by a parent)
331 # nothing to do, issue was already deleted (eg. by a parent)
332 end
332 end
333 end
333 end
334 respond_to do |format|
334 respond_to do |format|
335 format.html { redirect_back_or_default _project_issues_path(@project) }
335 format.html { redirect_back_or_default _project_issues_path(@project) }
336 format.api { render_api_ok }
336 format.api { render_api_ok }
337 end
337 end
338 end
338 end
339
339
340 private
340 private
341
341
342 def find_project
342 def find_project
343 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
343 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
344 @project = Project.find(project_id)
344 @project = Project.find(project_id)
345 rescue ActiveRecord::RecordNotFound
345 rescue ActiveRecord::RecordNotFound
346 render_404
346 render_404
347 end
347 end
348
348
349 def retrieve_previous_and_next_issue_ids
349 def retrieve_previous_and_next_issue_ids
350 retrieve_query_from_session
350 retrieve_query_from_session
351 if @query
351 if @query
352 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
352 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
353 sort_update(@query.sortable_columns, 'issues_index_sort')
353 sort_update(@query.sortable_columns, 'issues_index_sort')
354 limit = 500
354 limit = 500
355 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
355 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
356 if (idx = issue_ids.index(@issue.id)) && idx < limit
356 if (idx = issue_ids.index(@issue.id)) && idx < limit
357 if issue_ids.size < 500
357 if issue_ids.size < 500
358 @issue_position = idx + 1
358 @issue_position = idx + 1
359 @issue_count = issue_ids.size
359 @issue_count = issue_ids.size
360 end
360 end
361 @prev_issue_id = issue_ids[idx - 1] if idx > 0
361 @prev_issue_id = issue_ids[idx - 1] if idx > 0
362 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
362 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
363 end
363 end
364 end
364 end
365 end
365 end
366
366
367 # Used by #edit and #update to set some common instance variables
367 # Used by #edit and #update to set some common instance variables
368 # from the params
368 # from the params
369 # TODO: Refactor, not everything in here is needed by #edit
369 # TODO: Refactor, not everything in here is needed by #edit
370 def update_issue_from_params
370 def update_issue_from_params
371 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
371 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
372 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
372 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
373 @time_entry.attributes = params[:time_entry]
373 @time_entry.attributes = params[:time_entry]
374
374
375 @issue.init_journal(User.current)
375 @issue.init_journal(User.current)
376
376
377 issue_attributes = params[:issue]
377 issue_attributes = params[:issue]
378 if issue_attributes && params[:conflict_resolution]
378 if issue_attributes && params[:conflict_resolution]
379 case params[:conflict_resolution]
379 case params[:conflict_resolution]
380 when 'overwrite'
380 when 'overwrite'
381 issue_attributes = issue_attributes.dup
381 issue_attributes = issue_attributes.dup
382 issue_attributes.delete(:lock_version)
382 issue_attributes.delete(:lock_version)
383 when 'add_notes'
383 when 'add_notes'
384 issue_attributes = issue_attributes.slice(:notes)
384 issue_attributes = issue_attributes.slice(:notes)
385 when 'cancel'
385 when 'cancel'
386 redirect_to issue_path(@issue)
386 redirect_to issue_path(@issue)
387 return false
387 return false
388 end
388 end
389 end
389 end
390 @issue.safe_attributes = issue_attributes
390 @issue.safe_attributes = issue_attributes
391 @priorities = IssuePriority.active
391 @priorities = IssuePriority.active
392 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
392 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
393 true
393 true
394 end
394 end
395
395
396 # TODO: Refactor, lots of extra code in here
396 # TODO: Refactor, lots of extra code in here
397 # TODO: Changing tracker on an existing issue should not trigger this
397 # TODO: Changing tracker on an existing issue should not trigger this
398 def build_new_issue_from_params
398 def build_new_issue_from_params
399 if params[:id].blank?
399 if params[:id].blank?
400 @issue = Issue.new
400 @issue = Issue.new
401 if params[:copy_from]
401 if params[:copy_from]
402 begin
402 begin
403 @copy_from = Issue.visible.find(params[:copy_from])
403 @copy_from = Issue.visible.find(params[:copy_from])
404 @copy_attachments = params[:copy_attachments].present? || request.get?
404 @copy_attachments = params[:copy_attachments].present? || request.get?
405 @copy_subtasks = params[:copy_subtasks].present? || request.get?
405 @copy_subtasks = params[:copy_subtasks].present? || request.get?
406 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
406 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
407 rescue ActiveRecord::RecordNotFound
407 rescue ActiveRecord::RecordNotFound
408 render_404
408 render_404
409 return
409 return
410 end
410 end
411 end
411 end
412 @issue.project = @project
412 @issue.project = @project
413 else
413 else
414 @issue = @project.issues.visible.find(params[:id])
414 @issue = @project.issues.visible.find(params[:id])
415 end
415 end
416
416
417 @issue.project = @project
417 @issue.project = @project
418 @issue.author ||= User.current
418 @issue.author ||= User.current
419 # Tracker must be set before custom field values
419 # Tracker must be set before custom field values
420 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
420 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
421 if @issue.tracker.nil?
421 if @issue.tracker.nil?
422 render_error l(:error_no_tracker_in_project)
422 render_error l(:error_no_tracker_in_project)
423 return false
423 return false
424 end
424 end
425 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
425 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
426 @issue.safe_attributes = params[:issue]
426 @issue.safe_attributes = params[:issue]
427
427
428 @priorities = IssuePriority.active
428 @priorities = IssuePriority.active
429 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
429 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
430 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
430 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
431 end
431 end
432
432
433 def check_for_default_issue_status
433 def check_for_default_issue_status
434 if IssueStatus.default.nil?
434 if IssueStatus.default.nil?
435 render_error l(:error_no_default_issue_status)
435 render_error l(:error_no_default_issue_status)
436 return false
436 return false
437 end
437 end
438 end
438 end
439
439
440 def parse_params_for_bulk_issue_attributes(params)
440 def parse_params_for_bulk_issue_attributes(params)
441 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
441 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
442 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
442 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
443 if custom = attributes[:custom_field_values]
443 if custom = attributes[:custom_field_values]
444 custom.reject! {|k,v| v.blank?}
444 custom.reject! {|k,v| v.blank?}
445 custom.keys.each do |k|
445 custom.keys.each do |k|
446 if custom[k].is_a?(Array)
446 if custom[k].is_a?(Array)
447 custom[k] << '' if custom[k].delete('__none__')
447 custom[k] << '' if custom[k].delete('__none__')
448 else
448 else
449 custom[k] = '' if custom[k] == '__none__'
449 custom[k] = '' if custom[k] == '__none__'
450 end
450 end
451 end
451 end
452 end
452 end
453 attributes
453 attributes
454 end
454 end
455
455
456 # Saves @issue and a time_entry from the parameters
456 # Saves @issue and a time_entry from the parameters
457 def save_issue_with_child_records
457 def save_issue_with_child_records
458 Issue.transaction do
458 Issue.transaction do
459 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
459 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
460 time_entry = @time_entry || TimeEntry.new
460 time_entry = @time_entry || TimeEntry.new
461 time_entry.project = @issue.project
461 time_entry.project = @issue.project
462 time_entry.issue = @issue
462 time_entry.issue = @issue
463 time_entry.user = User.current
463 time_entry.user = User.current
464 time_entry.spent_on = User.current.today
464 time_entry.spent_on = User.current.today
465 time_entry.attributes = params[:time_entry]
465 time_entry.attributes = params[:time_entry]
466 @issue.time_entries << time_entry
466 @issue.time_entries << time_entry
467 end
467 end
468
468
469 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
469 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
470 if @issue.save
470 if @issue.save
471 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
471 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
472 else
472 else
473 raise ActiveRecord::Rollback
473 raise ActiveRecord::Rollback
474 end
474 end
475 end
475 end
476 end
476 end
477 end
477 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