##// END OF EJS Templates
Don't render the issue form if issue.project is nil (#19276)....
Jean-Philippe Lang -
r13764:ea099fb771a8
parent child
Show More

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

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