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