##// END OF EJS Templates
Don't include unused helper modules....
Jean-Philippe Lang -
r13619:efbbabe620b7
parent child
Show More
@@ -1,515 +1,508
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
2 # Copyright (C) 2006-2015 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 :authorize, :except => [:index, :new, :create]
24 before_filter :authorize, :except => [:index, :new, :create]
25 before_filter :find_optional_project, :only => [:index, :new, :create]
25 before_filter :find_optional_project, :only => [:index, :new, :create]
26 before_filter :build_new_issue_from_params, :only => [:new, :create]
26 before_filter :build_new_issue_from_params, :only => [:new, :create]
27 accept_rss_auth :index, :show
27 accept_rss_auth :index, :show
28 accept_api_auth :index, :show, :create, :update, :destroy
28 accept_api_auth :index, :show, :create, :update, :destroy
29
29
30 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
31
31
32 helper :journals
32 helper :journals
33 helper :projects
33 helper :projects
34 include ProjectsHelper
35 helper :custom_fields
34 helper :custom_fields
36 include CustomFieldsHelper
37 helper :issue_relations
35 helper :issue_relations
38 include IssueRelationsHelper
39 helper :watchers
36 helper :watchers
40 include WatchersHelper
41 helper :attachments
37 helper :attachments
42 include AttachmentsHelper
43 helper :queries
38 helper :queries
44 include QueriesHelper
39 include QueriesHelper
45 helper :repositories
40 helper :repositories
46 include RepositoriesHelper
47 helper :sort
41 helper :sort
48 include SortHelper
42 include SortHelper
49 include IssuesHelper
50 helper :timelog
43 helper :timelog
51
44
52 def index
45 def index
53 retrieve_query
46 retrieve_query
54 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
47 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
55 sort_update(@query.sortable_columns)
48 sort_update(@query.sortable_columns)
56 @query.sort_criteria = sort_criteria.to_a
49 @query.sort_criteria = sort_criteria.to_a
57
50
58 if @query.valid?
51 if @query.valid?
59 case params[:format]
52 case params[:format]
60 when 'csv', 'pdf'
53 when 'csv', 'pdf'
61 @limit = Setting.issues_export_limit.to_i
54 @limit = Setting.issues_export_limit.to_i
62 if params[:columns] == 'all'
55 if params[:columns] == 'all'
63 @query.column_names = @query.available_inline_columns.map(&:name)
56 @query.column_names = @query.available_inline_columns.map(&:name)
64 end
57 end
65 when 'atom'
58 when 'atom'
66 @limit = Setting.feeds_limit.to_i
59 @limit = Setting.feeds_limit.to_i
67 when 'xml', 'json'
60 when 'xml', 'json'
68 @offset, @limit = api_offset_and_limit
61 @offset, @limit = api_offset_and_limit
69 @query.column_names = %w(author)
62 @query.column_names = %w(author)
70 else
63 else
71 @limit = per_page_option
64 @limit = per_page_option
72 end
65 end
73
66
74 @issue_count = @query.issue_count
67 @issue_count = @query.issue_count
75 @issue_pages = Paginator.new @issue_count, @limit, params['page']
68 @issue_pages = Paginator.new @issue_count, @limit, params['page']
76 @offset ||= @issue_pages.offset
69 @offset ||= @issue_pages.offset
77 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
70 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
78 :order => sort_clause,
71 :order => sort_clause,
79 :offset => @offset,
72 :offset => @offset,
80 :limit => @limit)
73 :limit => @limit)
81 @issue_count_by_group = @query.issue_count_by_group
74 @issue_count_by_group = @query.issue_count_by_group
82
75
83 respond_to do |format|
76 respond_to do |format|
84 format.html { render :template => 'issues/index', :layout => !request.xhr? }
77 format.html { render :template => 'issues/index', :layout => !request.xhr? }
85 format.api {
78 format.api {
86 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
79 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
87 }
80 }
88 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
81 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
89 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
82 format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
90 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
83 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
91 end
84 end
92 else
85 else
93 respond_to do |format|
86 respond_to do |format|
94 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
87 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
95 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
88 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
96 format.api { render_validation_errors(@query) }
89 format.api { render_validation_errors(@query) }
97 end
90 end
98 end
91 end
99 rescue ActiveRecord::RecordNotFound
92 rescue ActiveRecord::RecordNotFound
100 render_404
93 render_404
101 end
94 end
102
95
103 def show
96 def show
104 @journals = @issue.journals.includes(:user, :details).
97 @journals = @issue.journals.includes(:user, :details).
105 references(:user, :details).
98 references(:user, :details).
106 reorder("#{Journal.table_name}.id ASC").to_a
99 reorder("#{Journal.table_name}.id ASC").to_a
107 @journals.each_with_index {|j,i| j.indice = i+1}
100 @journals.each_with_index {|j,i| j.indice = i+1}
108 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
101 @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
109 Journal.preload_journals_details_custom_fields(@journals)
102 Journal.preload_journals_details_custom_fields(@journals)
110 @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
103 @journals.select! {|journal| journal.notes? || journal.visible_details.any?}
111 @journals.reverse! if User.current.wants_comments_in_reverse_order?
104 @journals.reverse! if User.current.wants_comments_in_reverse_order?
112
105
113 @changesets = @issue.changesets.visible.to_a
106 @changesets = @issue.changesets.visible.to_a
114 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
107 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
115
108
116 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
109 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
117 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
110 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
118 @priorities = IssuePriority.active
111 @priorities = IssuePriority.active
119 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
112 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
120 @relation = IssueRelation.new
113 @relation = IssueRelation.new
121
114
122 respond_to do |format|
115 respond_to do |format|
123 format.html {
116 format.html {
124 retrieve_previous_and_next_issue_ids
117 retrieve_previous_and_next_issue_ids
125 render :template => 'issues/show'
118 render :template => 'issues/show'
126 }
119 }
127 format.api
120 format.api
128 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
121 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
129 format.pdf {
122 format.pdf {
130 send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
123 send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
131 }
124 }
132 end
125 end
133 end
126 end
134
127
135 def new
128 def new
136 respond_to do |format|
129 respond_to do |format|
137 format.html { render :action => 'new', :layout => !request.xhr? }
130 format.html { render :action => 'new', :layout => !request.xhr? }
138 format.js
131 format.js
139 end
132 end
140 end
133 end
141
134
142 def create
135 def create
143 unless User.current.allowed_to?(:add_issues, @issue.project)
136 unless User.current.allowed_to?(:add_issues, @issue.project)
144 raise ::Unauthorized
137 raise ::Unauthorized
145 end
138 end
146 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
139 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
147 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
140 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
148 if @issue.save
141 if @issue.save
149 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
142 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
150 respond_to do |format|
143 respond_to do |format|
151 format.html {
144 format.html {
152 render_attachment_warning_if_needed(@issue)
145 render_attachment_warning_if_needed(@issue)
153 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
146 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
154 redirect_after_create
147 redirect_after_create
155 }
148 }
156 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
149 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
157 end
150 end
158 return
151 return
159 else
152 else
160 respond_to do |format|
153 respond_to do |format|
161 format.html { render :action => 'new' }
154 format.html { render :action => 'new' }
162 format.api { render_validation_errors(@issue) }
155 format.api { render_validation_errors(@issue) }
163 end
156 end
164 end
157 end
165 end
158 end
166
159
167 def edit
160 def edit
168 return unless update_issue_from_params
161 return unless update_issue_from_params
169
162
170 respond_to do |format|
163 respond_to do |format|
171 format.html { }
164 format.html { }
172 format.js
165 format.js
173 end
166 end
174 end
167 end
175
168
176 def update
169 def update
177 return unless update_issue_from_params
170 return unless update_issue_from_params
178 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
171 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
179 saved = false
172 saved = false
180 begin
173 begin
181 saved = save_issue_with_child_records
174 saved = save_issue_with_child_records
182 rescue ActiveRecord::StaleObjectError
175 rescue ActiveRecord::StaleObjectError
183 @conflict = true
176 @conflict = true
184 if params[:last_journal_id]
177 if params[:last_journal_id]
185 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
178 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
186 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
179 @conflict_journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)
187 end
180 end
188 end
181 end
189
182
190 if saved
183 if saved
191 render_attachment_warning_if_needed(@issue)
184 render_attachment_warning_if_needed(@issue)
192 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
185 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
193
186
194 respond_to do |format|
187 respond_to do |format|
195 format.html { redirect_back_or_default issue_path(@issue) }
188 format.html { redirect_back_or_default issue_path(@issue) }
196 format.api { render_api_ok }
189 format.api { render_api_ok }
197 end
190 end
198 else
191 else
199 respond_to do |format|
192 respond_to do |format|
200 format.html { render :action => 'edit' }
193 format.html { render :action => 'edit' }
201 format.api { render_validation_errors(@issue) }
194 format.api { render_validation_errors(@issue) }
202 end
195 end
203 end
196 end
204 end
197 end
205
198
206 # Bulk edit/copy a set of issues
199 # Bulk edit/copy a set of issues
207 def bulk_edit
200 def bulk_edit
208 @issues.sort!
201 @issues.sort!
209 @copy = params[:copy].present?
202 @copy = params[:copy].present?
210 @notes = params[:notes]
203 @notes = params[:notes]
211
204
212 if @copy
205 if @copy
213 unless User.current.allowed_to?(:copy_issues, @projects)
206 unless User.current.allowed_to?(:copy_issues, @projects)
214 raise ::Unauthorized
207 raise ::Unauthorized
215 end
208 end
216 end
209 end
217
210
218 @allowed_projects = Issue.allowed_target_projects
211 @allowed_projects = Issue.allowed_target_projects
219 if params[:issue]
212 if params[:issue]
220 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
213 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
221 if @target_project
214 if @target_project
222 target_projects = [@target_project]
215 target_projects = [@target_project]
223 end
216 end
224 end
217 end
225 target_projects ||= @projects
218 target_projects ||= @projects
226
219
227 if @copy
220 if @copy
228 # Copied issues will get their default statuses
221 # Copied issues will get their default statuses
229 @available_statuses = []
222 @available_statuses = []
230 else
223 else
231 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
224 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
232 end
225 end
233 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
226 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields.visible}.reduce(:&)
234 @assignables = target_projects.map(&:assignable_users).reduce(:&)
227 @assignables = target_projects.map(&:assignable_users).reduce(:&)
235 @trackers = target_projects.map(&:trackers).reduce(:&)
228 @trackers = target_projects.map(&:trackers).reduce(:&)
236 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
229 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
237 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
230 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
238 if @copy
231 if @copy
239 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
232 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
240 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
233 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
241 end
234 end
242
235
243 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
236 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
244
237
245 @issue_params = params[:issue] || {}
238 @issue_params = params[:issue] || {}
246 @issue_params[:custom_field_values] ||= {}
239 @issue_params[:custom_field_values] ||= {}
247 end
240 end
248
241
249 def bulk_update
242 def bulk_update
250 @issues.sort!
243 @issues.sort!
251 @copy = params[:copy].present?
244 @copy = params[:copy].present?
252 attributes = parse_params_for_bulk_issue_attributes(params)
245 attributes = parse_params_for_bulk_issue_attributes(params)
253
246
254 if @copy
247 if @copy
255 unless User.current.allowed_to?(:copy_issues, @projects)
248 unless User.current.allowed_to?(:copy_issues, @projects)
256 raise ::Unauthorized
249 raise ::Unauthorized
257 end
250 end
258 target_projects = @projects
251 target_projects = @projects
259 if attributes['project_id'].present?
252 if attributes['project_id'].present?
260 target_projects = Project.where(:id => attributes['project_id']).to_a
253 target_projects = Project.where(:id => attributes['project_id']).to_a
261 end
254 end
262 unless User.current.allowed_to?(:add_issues, target_projects)
255 unless User.current.allowed_to?(:add_issues, target_projects)
263 raise ::Unauthorized
256 raise ::Unauthorized
264 end
257 end
265 end
258 end
266
259
267 unsaved_issues = []
260 unsaved_issues = []
268 saved_issues = []
261 saved_issues = []
269
262
270 if @copy && params[:copy_subtasks].present?
263 if @copy && params[:copy_subtasks].present?
271 # Descendant issues will be copied with the parent task
264 # Descendant issues will be copied with the parent task
272 # Don't copy them twice
265 # Don't copy them twice
273 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
266 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
274 end
267 end
275
268
276 @issues.each do |orig_issue|
269 @issues.each do |orig_issue|
277 orig_issue.reload
270 orig_issue.reload
278 if @copy
271 if @copy
279 issue = orig_issue.copy({},
272 issue = orig_issue.copy({},
280 :attachments => params[:copy_attachments].present?,
273 :attachments => params[:copy_attachments].present?,
281 :subtasks => params[:copy_subtasks].present?,
274 :subtasks => params[:copy_subtasks].present?,
282 :link => link_copy?(params[:link_copy])
275 :link => link_copy?(params[:link_copy])
283 )
276 )
284 else
277 else
285 issue = orig_issue
278 issue = orig_issue
286 end
279 end
287 journal = issue.init_journal(User.current, params[:notes])
280 journal = issue.init_journal(User.current, params[:notes])
288 issue.safe_attributes = attributes
281 issue.safe_attributes = attributes
289 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
282 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
290 if issue.save
283 if issue.save
291 saved_issues << issue
284 saved_issues << issue
292 else
285 else
293 unsaved_issues << orig_issue
286 unsaved_issues << orig_issue
294 end
287 end
295 end
288 end
296
289
297 if unsaved_issues.empty?
290 if unsaved_issues.empty?
298 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
291 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
299 if params[:follow]
292 if params[:follow]
300 if @issues.size == 1 && saved_issues.size == 1
293 if @issues.size == 1 && saved_issues.size == 1
301 redirect_to issue_path(saved_issues.first)
294 redirect_to issue_path(saved_issues.first)
302 elsif saved_issues.map(&:project).uniq.size == 1
295 elsif saved_issues.map(&:project).uniq.size == 1
303 redirect_to project_issues_path(saved_issues.map(&:project).first)
296 redirect_to project_issues_path(saved_issues.map(&:project).first)
304 end
297 end
305 else
298 else
306 redirect_back_or_default _project_issues_path(@project)
299 redirect_back_or_default _project_issues_path(@project)
307 end
300 end
308 else
301 else
309 @saved_issues = @issues
302 @saved_issues = @issues
310 @unsaved_issues = unsaved_issues
303 @unsaved_issues = unsaved_issues
311 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
304 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
312 bulk_edit
305 bulk_edit
313 render :action => 'bulk_edit'
306 render :action => 'bulk_edit'
314 end
307 end
315 end
308 end
316
309
317 def destroy
310 def destroy
318 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
311 @hours = TimeEntry.where(:issue_id => @issues.map(&:id)).sum(:hours).to_f
319 if @hours > 0
312 if @hours > 0
320 case params[:todo]
313 case params[:todo]
321 when 'destroy'
314 when 'destroy'
322 # nothing to do
315 # nothing to do
323 when 'nullify'
316 when 'nullify'
324 TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
317 TimeEntry.where(['issue_id IN (?)', @issues]).update_all('issue_id = NULL')
325 when 'reassign'
318 when 'reassign'
326 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
319 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
327 if reassign_to.nil?
320 if reassign_to.nil?
328 flash.now[:error] = l(:error_issue_not_found_in_project)
321 flash.now[:error] = l(:error_issue_not_found_in_project)
329 return
322 return
330 else
323 else
331 TimeEntry.where(['issue_id IN (?)', @issues]).
324 TimeEntry.where(['issue_id IN (?)', @issues]).
332 update_all("issue_id = #{reassign_to.id}")
325 update_all("issue_id = #{reassign_to.id}")
333 end
326 end
334 else
327 else
335 # display the destroy form if it's a user request
328 # display the destroy form if it's a user request
336 return unless api_request?
329 return unless api_request?
337 end
330 end
338 end
331 end
339 @issues.each do |issue|
332 @issues.each do |issue|
340 begin
333 begin
341 issue.reload.destroy
334 issue.reload.destroy
342 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
335 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
343 # nothing to do, issue was already deleted (eg. by a parent)
336 # nothing to do, issue was already deleted (eg. by a parent)
344 end
337 end
345 end
338 end
346 respond_to do |format|
339 respond_to do |format|
347 format.html { redirect_back_or_default _project_issues_path(@project) }
340 format.html { redirect_back_or_default _project_issues_path(@project) }
348 format.api { render_api_ok }
341 format.api { render_api_ok }
349 end
342 end
350 end
343 end
351
344
352 private
345 private
353
346
354 def retrieve_previous_and_next_issue_ids
347 def retrieve_previous_and_next_issue_ids
355 retrieve_query_from_session
348 retrieve_query_from_session
356 if @query
349 if @query
357 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
350 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
358 sort_update(@query.sortable_columns, 'issues_index_sort')
351 sort_update(@query.sortable_columns, 'issues_index_sort')
359 limit = 500
352 limit = 500
360 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
353 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
361 if (idx = issue_ids.index(@issue.id)) && idx < limit
354 if (idx = issue_ids.index(@issue.id)) && idx < limit
362 if issue_ids.size < 500
355 if issue_ids.size < 500
363 @issue_position = idx + 1
356 @issue_position = idx + 1
364 @issue_count = issue_ids.size
357 @issue_count = issue_ids.size
365 end
358 end
366 @prev_issue_id = issue_ids[idx - 1] if idx > 0
359 @prev_issue_id = issue_ids[idx - 1] if idx > 0
367 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
360 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
368 end
361 end
369 end
362 end
370 end
363 end
371
364
372 # Used by #edit and #update to set some common instance variables
365 # Used by #edit and #update to set some common instance variables
373 # from the params
366 # from the params
374 def update_issue_from_params
367 def update_issue_from_params
375 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
368 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
376 if params[:time_entry]
369 if params[:time_entry]
377 @time_entry.attributes = params[:time_entry]
370 @time_entry.attributes = params[:time_entry]
378 end
371 end
379
372
380 @issue.init_journal(User.current)
373 @issue.init_journal(User.current)
381
374
382 issue_attributes = params[:issue]
375 issue_attributes = params[:issue]
383 if issue_attributes && params[:conflict_resolution]
376 if issue_attributes && params[:conflict_resolution]
384 case params[:conflict_resolution]
377 case params[:conflict_resolution]
385 when 'overwrite'
378 when 'overwrite'
386 issue_attributes = issue_attributes.dup
379 issue_attributes = issue_attributes.dup
387 issue_attributes.delete(:lock_version)
380 issue_attributes.delete(:lock_version)
388 when 'add_notes'
381 when 'add_notes'
389 issue_attributes = issue_attributes.slice(:notes)
382 issue_attributes = issue_attributes.slice(:notes)
390 when 'cancel'
383 when 'cancel'
391 redirect_to issue_path(@issue)
384 redirect_to issue_path(@issue)
392 return false
385 return false
393 end
386 end
394 end
387 end
395 @issue.safe_attributes = issue_attributes
388 @issue.safe_attributes = issue_attributes
396 @priorities = IssuePriority.active
389 @priorities = IssuePriority.active
397 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
390 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
398 true
391 true
399 end
392 end
400
393
401 # Used by #new and #create to build a new issue from the params
394 # Used by #new and #create to build a new issue from the params
402 # The new issue will be copied from an existing one if copy_from parameter is given
395 # The new issue will be copied from an existing one if copy_from parameter is given
403 def build_new_issue_from_params
396 def build_new_issue_from_params
404 @issue = Issue.new
397 @issue = Issue.new
405 if params[:copy_from]
398 if params[:copy_from]
406 begin
399 begin
407 @issue.init_journal(User.current)
400 @issue.init_journal(User.current)
408 @copy_from = Issue.visible.find(params[:copy_from])
401 @copy_from = Issue.visible.find(params[:copy_from])
409 unless User.current.allowed_to?(:copy_issues, @copy_from.project)
402 unless User.current.allowed_to?(:copy_issues, @copy_from.project)
410 raise ::Unauthorized
403 raise ::Unauthorized
411 end
404 end
412 @link_copy = link_copy?(params[:link_copy]) || request.get?
405 @link_copy = link_copy?(params[:link_copy]) || request.get?
413 @copy_attachments = params[:copy_attachments].present? || request.get?
406 @copy_attachments = params[:copy_attachments].present? || request.get?
414 @copy_subtasks = params[:copy_subtasks].present? || request.get?
407 @copy_subtasks = params[:copy_subtasks].present? || request.get?
415 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
408 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
416 rescue ActiveRecord::RecordNotFound
409 rescue ActiveRecord::RecordNotFound
417 render_404
410 render_404
418 return
411 return
419 end
412 end
420 end
413 end
421 @issue.project = @project
414 @issue.project = @project
422 if request.get?
415 if request.get?
423 @issue.project ||= @issue.allowed_target_projects.first
416 @issue.project ||= @issue.allowed_target_projects.first
424 end
417 end
425 @issue.author ||= User.current
418 @issue.author ||= User.current
426 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
419 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
427
420
428 if attrs = params[:issue].deep_dup
421 if attrs = params[:issue].deep_dup
429 if params[:was_default_status] == attrs[:status_id]
422 if params[:was_default_status] == attrs[:status_id]
430 attrs.delete(:status_id)
423 attrs.delete(:status_id)
431 end
424 end
432 @issue.safe_attributes = attrs
425 @issue.safe_attributes = attrs
433 end
426 end
434 if @issue.project
427 if @issue.project
435 @issue.tracker ||= @issue.project.trackers.first
428 @issue.tracker ||= @issue.project.trackers.first
436 if @issue.tracker.nil?
429 if @issue.tracker.nil?
437 render_error l(:error_no_tracker_in_project)
430 render_error l(:error_no_tracker_in_project)
438 return false
431 return false
439 end
432 end
440 if @issue.status.nil?
433 if @issue.status.nil?
441 render_error l(:error_no_default_issue_status)
434 render_error l(:error_no_default_issue_status)
442 return false
435 return false
443 end
436 end
444 end
437 end
445
438
446 @priorities = IssuePriority.active
439 @priorities = IssuePriority.active
447 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
440 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
448 end
441 end
449
442
450 def parse_params_for_bulk_issue_attributes(params)
443 def parse_params_for_bulk_issue_attributes(params)
451 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
444 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
452 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
445 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
453 if custom = attributes[:custom_field_values]
446 if custom = attributes[:custom_field_values]
454 custom.reject! {|k,v| v.blank?}
447 custom.reject! {|k,v| v.blank?}
455 custom.keys.each do |k|
448 custom.keys.each do |k|
456 if custom[k].is_a?(Array)
449 if custom[k].is_a?(Array)
457 custom[k] << '' if custom[k].delete('__none__')
450 custom[k] << '' if custom[k].delete('__none__')
458 else
451 else
459 custom[k] = '' if custom[k] == '__none__'
452 custom[k] = '' if custom[k] == '__none__'
460 end
453 end
461 end
454 end
462 end
455 end
463 attributes
456 attributes
464 end
457 end
465
458
466 # Saves @issue and a time_entry from the parameters
459 # Saves @issue and a time_entry from the parameters
467 def save_issue_with_child_records
460 def save_issue_with_child_records
468 Issue.transaction do
461 Issue.transaction do
469 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
462 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
470 time_entry = @time_entry || TimeEntry.new
463 time_entry = @time_entry || TimeEntry.new
471 time_entry.project = @issue.project
464 time_entry.project = @issue.project
472 time_entry.issue = @issue
465 time_entry.issue = @issue
473 time_entry.user = User.current
466 time_entry.user = User.current
474 time_entry.spent_on = User.current.today
467 time_entry.spent_on = User.current.today
475 time_entry.attributes = params[:time_entry]
468 time_entry.attributes = params[:time_entry]
476 @issue.time_entries << time_entry
469 @issue.time_entries << time_entry
477 end
470 end
478
471
479 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
472 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
480 if @issue.save
473 if @issue.save
481 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
474 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
482 else
475 else
483 raise ActiveRecord::Rollback
476 raise ActiveRecord::Rollback
484 end
477 end
485 end
478 end
486 end
479 end
487
480
488 # Returns true if the issue copy should be linked
481 # Returns true if the issue copy should be linked
489 # to the original issue
482 # to the original issue
490 def link_copy?(param)
483 def link_copy?(param)
491 case Setting.link_copied_issue
484 case Setting.link_copied_issue
492 when 'yes'
485 when 'yes'
493 true
486 true
494 when 'no'
487 when 'no'
495 false
488 false
496 when 'ask'
489 when 'ask'
497 param == '1'
490 param == '1'
498 end
491 end
499 end
492 end
500
493
501 # Redirects user after a successful issue creation
494 # Redirects user after a successful issue creation
502 def redirect_after_create
495 def redirect_after_create
503 if params[:continue]
496 if params[:continue]
504 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
497 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
505 if params[:project_id]
498 if params[:project_id]
506 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
499 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
507 else
500 else
508 attrs.merge! :project_id => @issue.project_id
501 attrs.merge! :project_id => @issue.project_id
509 redirect_to new_issue_path(:issue => attrs)
502 redirect_to new_issue_path(:issue => attrs)
510 end
503 end
511 else
504 else
512 redirect_to issue_path(@issue)
505 redirect_to issue_path(@issue)
513 end
506 end
514 end
507 end
515 end
508 end
General Comments 0
You need to be logged in to leave comments. Login now