##// END OF EJS Templates
Don't show the "reassign" option when deleting issues from different projects (#24722)....
Jean-Philippe Lang -
r15739:1bda8ce9405f
parent child
Show More
@@ -1,575 +1,575
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 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 default_search_scope :issues
19 default_search_scope :issues
20
20
21 before_action :find_issue, :only => [:show, :edit, :update]
21 before_action :find_issue, :only => [:show, :edit, :update]
22 before_action :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
22 before_action :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_action :authorize, :except => [:index, :new, :create]
23 before_action :authorize, :except => [:index, :new, :create]
24 before_action :find_optional_project, :only => [:index, :new, :create]
24 before_action :find_optional_project, :only => [:index, :new, :create]
25 before_action :build_new_issue_from_params, :only => [:new, :create]
25 before_action :build_new_issue_from_params, :only => [:new, :create]
26 accept_rss_auth :index, :show
26 accept_rss_auth :index, :show
27 accept_api_auth :index, :show, :create, :update, :destroy
27 accept_api_auth :index, :show, :create, :update, :destroy
28
28
29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30
30
31 helper :journals
31 helper :journals
32 helper :projects
32 helper :projects
33 helper :custom_fields
33 helper :custom_fields
34 helper :issue_relations
34 helper :issue_relations
35 helper :watchers
35 helper :watchers
36 helper :attachments
36 helper :attachments
37 helper :queries
37 helper :queries
38 include QueriesHelper
38 include QueriesHelper
39 helper :repositories
39 helper :repositories
40 helper :sort
40 helper :sort
41 include SortHelper
41 include SortHelper
42 helper :timelog
42 helper :timelog
43
43
44 def index
44 def index
45 retrieve_query
45 retrieve_query
46 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
46 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
47 sort_update(@query.sortable_columns)
47 sort_update(@query.sortable_columns)
48 @query.sort_criteria = sort_criteria.to_a
48 @query.sort_criteria = sort_criteria.to_a
49
49
50 if @query.valid?
50 if @query.valid?
51 case params[:format]
51 case params[:format]
52 when 'csv', 'pdf'
52 when 'csv', 'pdf'
53 @limit = Setting.issues_export_limit.to_i
53 @limit = Setting.issues_export_limit.to_i
54 if params[:columns] == 'all'
54 if params[:columns] == 'all'
55 @query.column_names = @query.available_inline_columns.map(&:name)
55 @query.column_names = @query.available_inline_columns.map(&:name)
56 end
56 end
57 when 'atom'
57 when 'atom'
58 @limit = Setting.feeds_limit.to_i
58 @limit = Setting.feeds_limit.to_i
59 when 'xml', 'json'
59 when 'xml', 'json'
60 @offset, @limit = api_offset_and_limit
60 @offset, @limit = api_offset_and_limit
61 @query.column_names = %w(author)
61 @query.column_names = %w(author)
62 else
62 else
63 @limit = per_page_option
63 @limit = per_page_option
64 end
64 end
65
65
66 @issue_count = @query.issue_count
66 @issue_count = @query.issue_count
67 @issue_pages = Paginator.new @issue_count, @limit, params['page']
67 @issue_pages = Paginator.new @issue_count, @limit, params['page']
68 @offset ||= @issue_pages.offset
68 @offset ||= @issue_pages.offset
69 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
69 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
70 :order => sort_clause,
70 :order => sort_clause,
71 :offset => @offset,
71 :offset => @offset,
72 :limit => @limit)
72 :limit => @limit)
73 @issue_count_by_group = @query.issue_count_by_group
73 @issue_count_by_group = @query.issue_count_by_group
74
74
75 respond_to do |format|
75 respond_to do |format|
76 format.html { render :template => 'issues/index', :layout => !request.xhr? }
76 format.html { render :template => 'issues/index', :layout => !request.xhr? }
77 format.api {
77 format.api {
78 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
78 Issue.load_visible_relations(@issues) if include_in_api_response?('relations')
79 }
79 }
80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
81 format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') }
81 format.csv { send_data(query_to_csv(@issues, @query, params[:csv]), :type => 'text/csv; header=present', :filename => 'issues.csv') }
82 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
82 format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
83 end
83 end
84 else
84 else
85 respond_to do |format|
85 respond_to do |format|
86 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
86 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
87 format.any(:atom, :csv, :pdf) { head 422 }
87 format.any(:atom, :csv, :pdf) { head 422 }
88 format.api { render_validation_errors(@query) }
88 format.api { render_validation_errors(@query) }
89 end
89 end
90 end
90 end
91 rescue ActiveRecord::RecordNotFound
91 rescue ActiveRecord::RecordNotFound
92 render_404
92 render_404
93 end
93 end
94
94
95 def show
95 def show
96 @journals = @issue.journals.
96 @journals = @issue.journals.
97 preload(:details).
97 preload(:details).
98 preload(:user => :email_address).
98 preload(:user => :email_address).
99 reorder(:created_on, :id).to_a
99 reorder(:created_on, :id).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.preload(:repository, :user).to_a
106 @changesets = @issue.changesets.visible.preload(:repository, :user).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 {
154 format.html {
155 if @issue.project.nil?
155 if @issue.project.nil?
156 render_error :status => 422
156 render_error :status => 422
157 else
157 else
158 render :action => 'new'
158 render :action => 'new'
159 end
159 end
160 }
160 }
161 format.api { render_validation_errors(@issue) }
161 format.api { render_validation_errors(@issue) }
162 end
162 end
163 end
163 end
164 end
164 end
165
165
166 def edit
166 def edit
167 return unless update_issue_from_params
167 return unless update_issue_from_params
168
168
169 respond_to do |format|
169 respond_to do |format|
170 format.html { }
170 format.html { }
171 format.js
171 format.js
172 end
172 end
173 end
173 end
174
174
175 def update
175 def update
176 return unless update_issue_from_params
176 return unless update_issue_from_params
177 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
177 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
178 saved = false
178 saved = false
179 begin
179 begin
180 saved = save_issue_with_child_records
180 saved = save_issue_with_child_records
181 rescue ActiveRecord::StaleObjectError
181 rescue ActiveRecord::StaleObjectError
182 @conflict = true
182 @conflict = true
183 if params[:last_journal_id]
183 if params[:last_journal_id]
184 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
184 @conflict_journals = @issue.journals_after(params[:last_journal_id]).to_a
185 @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)
186 end
186 end
187 end
187 end
188
188
189 if saved
189 if saved
190 render_attachment_warning_if_needed(@issue)
190 render_attachment_warning_if_needed(@issue)
191 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?
192
192
193 respond_to do |format|
193 respond_to do |format|
194 format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) }
194 format.html { redirect_back_or_default issue_path(@issue, previous_and_next_issue_ids_params) }
195 format.api { render_api_ok }
195 format.api { render_api_ok }
196 end
196 end
197 else
197 else
198 respond_to do |format|
198 respond_to do |format|
199 format.html { render :action => 'edit' }
199 format.html { render :action => 'edit' }
200 format.api { render_validation_errors(@issue) }
200 format.api { render_validation_errors(@issue) }
201 end
201 end
202 end
202 end
203 end
203 end
204
204
205 # Bulk edit/copy a set of issues
205 # Bulk edit/copy a set of issues
206 def bulk_edit
206 def bulk_edit
207 @issues.sort!
207 @issues.sort!
208 @copy = params[:copy].present?
208 @copy = params[:copy].present?
209 @notes = params[:notes]
209 @notes = params[:notes]
210
210
211 if @copy
211 if @copy
212 unless User.current.allowed_to?(:copy_issues, @projects)
212 unless User.current.allowed_to?(:copy_issues, @projects)
213 raise ::Unauthorized
213 raise ::Unauthorized
214 end
214 end
215 else
215 else
216 unless @issues.all?(&:attributes_editable?)
216 unless @issues.all?(&:attributes_editable?)
217 raise ::Unauthorized
217 raise ::Unauthorized
218 end
218 end
219 end
219 end
220
220
221 edited_issues = Issue.where(:id => @issues.map(&:id)).to_a
221 edited_issues = Issue.where(:id => @issues.map(&:id)).to_a
222
222
223 @allowed_projects = Issue.allowed_target_projects
223 @allowed_projects = Issue.allowed_target_projects
224 if params[:issue]
224 if params[:issue]
225 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
225 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
226 if @target_project
226 if @target_project
227 target_projects = [@target_project]
227 target_projects = [@target_project]
228 edited_issues.each {|issue| issue.project = @target_project}
228 edited_issues.each {|issue| issue.project = @target_project}
229 end
229 end
230 end
230 end
231 target_projects ||= @projects
231 target_projects ||= @projects
232
232
233 @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
233 @trackers = target_projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
234 if params[:issue]
234 if params[:issue]
235 @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s}
235 @target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s}
236 if @target_tracker
236 if @target_tracker
237 edited_issues.each {|issue| issue.tracker = @target_tracker}
237 edited_issues.each {|issue| issue.tracker = @target_tracker}
238 end
238 end
239 end
239 end
240
240
241 if @copy
241 if @copy
242 # Copied issues will get their default statuses
242 # Copied issues will get their default statuses
243 @available_statuses = []
243 @available_statuses = []
244 else
244 else
245 @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&)
245 @available_statuses = edited_issues.map(&:new_statuses_allowed_to).reduce(:&)
246 end
246 end
247 if params[:issue]
247 if params[:issue]
248 @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s}
248 @target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s}
249 if @target_status
249 if @target_status
250 edited_issues.each {|issue| issue.status = @target_status}
250 edited_issues.each {|issue| issue.status = @target_status}
251 end
251 end
252 end
252 end
253
253
254 @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&).select {|field| field.format.bulk_edit_supported}
254 @custom_fields = edited_issues.map{|i|i.editable_custom_fields}.reduce(:&).select {|field| field.format.bulk_edit_supported}
255 @assignables = target_projects.map(&:assignable_users).reduce(:&)
255 @assignables = target_projects.map(&:assignable_users).reduce(:&)
256 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
256 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
257 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
257 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
258 if @copy
258 if @copy
259 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
259 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
260 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
260 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
261 end
261 end
262
262
263 @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&)
263 @safe_attributes = edited_issues.map(&:safe_attribute_names).reduce(:&)
264
264
265 @issue_params = params[:issue] || {}
265 @issue_params = params[:issue] || {}
266 @issue_params[:custom_field_values] ||= {}
266 @issue_params[:custom_field_values] ||= {}
267 end
267 end
268
268
269 def bulk_update
269 def bulk_update
270 @issues.sort!
270 @issues.sort!
271 @copy = params[:copy].present?
271 @copy = params[:copy].present?
272
272
273 attributes = parse_params_for_bulk_update(params[:issue])
273 attributes = parse_params_for_bulk_update(params[:issue])
274 copy_subtasks = (params[:copy_subtasks] == '1')
274 copy_subtasks = (params[:copy_subtasks] == '1')
275 copy_attachments = (params[:copy_attachments] == '1')
275 copy_attachments = (params[:copy_attachments] == '1')
276
276
277 if @copy
277 if @copy
278 unless User.current.allowed_to?(:copy_issues, @projects)
278 unless User.current.allowed_to?(:copy_issues, @projects)
279 raise ::Unauthorized
279 raise ::Unauthorized
280 end
280 end
281 target_projects = @projects
281 target_projects = @projects
282 if attributes['project_id'].present?
282 if attributes['project_id'].present?
283 target_projects = Project.where(:id => attributes['project_id']).to_a
283 target_projects = Project.where(:id => attributes['project_id']).to_a
284 end
284 end
285 unless User.current.allowed_to?(:add_issues, target_projects)
285 unless User.current.allowed_to?(:add_issues, target_projects)
286 raise ::Unauthorized
286 raise ::Unauthorized
287 end
287 end
288 else
288 else
289 unless @issues.all?(&:attributes_editable?)
289 unless @issues.all?(&:attributes_editable?)
290 raise ::Unauthorized
290 raise ::Unauthorized
291 end
291 end
292 end
292 end
293
293
294 unsaved_issues = []
294 unsaved_issues = []
295 saved_issues = []
295 saved_issues = []
296
296
297 if @copy && copy_subtasks
297 if @copy && copy_subtasks
298 # Descendant issues will be copied with the parent task
298 # Descendant issues will be copied with the parent task
299 # Don't copy them twice
299 # Don't copy them twice
300 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
300 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
301 end
301 end
302
302
303 @issues.each do |orig_issue|
303 @issues.each do |orig_issue|
304 orig_issue.reload
304 orig_issue.reload
305 if @copy
305 if @copy
306 issue = orig_issue.copy({},
306 issue = orig_issue.copy({},
307 :attachments => copy_attachments,
307 :attachments => copy_attachments,
308 :subtasks => copy_subtasks,
308 :subtasks => copy_subtasks,
309 :link => link_copy?(params[:link_copy])
309 :link => link_copy?(params[:link_copy])
310 )
310 )
311 else
311 else
312 issue = orig_issue
312 issue = orig_issue
313 end
313 end
314 journal = issue.init_journal(User.current, params[:notes])
314 journal = issue.init_journal(User.current, params[:notes])
315 issue.safe_attributes = attributes
315 issue.safe_attributes = attributes
316 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
316 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
317 if issue.save
317 if issue.save
318 saved_issues << issue
318 saved_issues << issue
319 else
319 else
320 unsaved_issues << orig_issue
320 unsaved_issues << orig_issue
321 end
321 end
322 end
322 end
323
323
324 if unsaved_issues.empty?
324 if unsaved_issues.empty?
325 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
325 flash[:notice] = l(:notice_successful_update) unless saved_issues.empty?
326 if params[:follow]
326 if params[:follow]
327 if @issues.size == 1 && saved_issues.size == 1
327 if @issues.size == 1 && saved_issues.size == 1
328 redirect_to issue_path(saved_issues.first)
328 redirect_to issue_path(saved_issues.first)
329 elsif saved_issues.map(&:project).uniq.size == 1
329 elsif saved_issues.map(&:project).uniq.size == 1
330 redirect_to project_issues_path(saved_issues.map(&:project).first)
330 redirect_to project_issues_path(saved_issues.map(&:project).first)
331 end
331 end
332 else
332 else
333 redirect_back_or_default _project_issues_path(@project)
333 redirect_back_or_default _project_issues_path(@project)
334 end
334 end
335 else
335 else
336 @saved_issues = @issues
336 @saved_issues = @issues
337 @unsaved_issues = unsaved_issues
337 @unsaved_issues = unsaved_issues
338 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
338 @issues = Issue.visible.where(:id => @unsaved_issues.map(&:id)).to_a
339 bulk_edit
339 bulk_edit
340 render :action => 'bulk_edit'
340 render :action => 'bulk_edit'
341 end
341 end
342 end
342 end
343
343
344 def destroy
344 def destroy
345 raise Unauthorized unless @issues.all?(&:deletable?)
345 raise Unauthorized unless @issues.all?(&:deletable?)
346
346
347 # all issues and their descendants are about to be deleted
347 # all issues and their descendants are about to be deleted
348 issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
348 issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
349 time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids)
349 time_entries = TimeEntry.where(:issue_id => issues_and_descendants_ids)
350 @hours = time_entries.sum(:hours).to_f
350 @hours = time_entries.sum(:hours).to_f
351
351
352 if @hours > 0
352 if @hours > 0
353 case params[:todo]
353 case params[:todo]
354 when 'destroy'
354 when 'destroy'
355 # nothing to do
355 # nothing to do
356 when 'nullify'
356 when 'nullify'
357 time_entries.update_all(:issue_id => nil)
357 time_entries.update_all(:issue_id => nil)
358 when 'reassign'
358 when 'reassign'
359 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
359 reassign_to = @project && @project.issues.find_by_id(params[:reassign_to_id])
360 if reassign_to.nil?
360 if reassign_to.nil?
361 flash.now[:error] = l(:error_issue_not_found_in_project)
361 flash.now[:error] = l(:error_issue_not_found_in_project)
362 return
362 return
363 elsif issues_and_descendants_ids.include?(reassign_to.id)
363 elsif issues_and_descendants_ids.include?(reassign_to.id)
364 flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
364 flash.now[:error] = l(:error_cannot_reassign_time_entries_to_an_issue_about_to_be_deleted)
365 return
365 return
366 else
366 else
367 time_entries.update_all(:issue_id => reassign_to.id, :project_id => reassign_to.project_id)
367 time_entries.update_all(:issue_id => reassign_to.id, :project_id => reassign_to.project_id)
368 end
368 end
369 else
369 else
370 # display the destroy form if it's a user request
370 # display the destroy form if it's a user request
371 return unless api_request?
371 return unless api_request?
372 end
372 end
373 end
373 end
374 @issues.each do |issue|
374 @issues.each do |issue|
375 begin
375 begin
376 issue.reload.destroy
376 issue.reload.destroy
377 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
377 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
378 # nothing to do, issue was already deleted (eg. by a parent)
378 # nothing to do, issue was already deleted (eg. by a parent)
379 end
379 end
380 end
380 end
381 respond_to do |format|
381 respond_to do |format|
382 format.html { redirect_back_or_default _project_issues_path(@project) }
382 format.html { redirect_back_or_default _project_issues_path(@project) }
383 format.api { render_api_ok }
383 format.api { render_api_ok }
384 end
384 end
385 end
385 end
386
386
387 # Overrides Redmine::MenuManager::MenuController::ClassMethods for
387 # Overrides Redmine::MenuManager::MenuController::ClassMethods for
388 # when the "New issue" tab is enabled
388 # when the "New issue" tab is enabled
389 def current_menu_item
389 def current_menu_item
390 if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym)
390 if Setting.new_item_menu_tab == '1' && [:new, :create].include?(action_name.to_sym)
391 :new_issue
391 :new_issue
392 else
392 else
393 super
393 super
394 end
394 end
395 end
395 end
396
396
397 private
397 private
398
398
399 def retrieve_previous_and_next_issue_ids
399 def retrieve_previous_and_next_issue_ids
400 if params[:prev_issue_id].present? || params[:next_issue_id].present?
400 if params[:prev_issue_id].present? || params[:next_issue_id].present?
401 @prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
401 @prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
402 @next_issue_id = params[:next_issue_id].presence.try(:to_i)
402 @next_issue_id = params[:next_issue_id].presence.try(:to_i)
403 @issue_position = params[:issue_position].presence.try(:to_i)
403 @issue_position = params[:issue_position].presence.try(:to_i)
404 @issue_count = params[:issue_count].presence.try(:to_i)
404 @issue_count = params[:issue_count].presence.try(:to_i)
405 else
405 else
406 retrieve_query_from_session
406 retrieve_query_from_session
407 if @query
407 if @query
408 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
408 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
409 sort_update(@query.sortable_columns, 'issues_index_sort')
409 sort_update(@query.sortable_columns, 'issues_index_sort')
410 limit = 500
410 limit = 500
411 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
411 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
412 if (idx = issue_ids.index(@issue.id)) && idx < limit
412 if (idx = issue_ids.index(@issue.id)) && idx < limit
413 if issue_ids.size < 500
413 if issue_ids.size < 500
414 @issue_position = idx + 1
414 @issue_position = idx + 1
415 @issue_count = issue_ids.size
415 @issue_count = issue_ids.size
416 end
416 end
417 @prev_issue_id = issue_ids[idx - 1] if idx > 0
417 @prev_issue_id = issue_ids[idx - 1] if idx > 0
418 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
418 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
419 end
419 end
420 end
420 end
421 end
421 end
422 end
422 end
423
423
424 def previous_and_next_issue_ids_params
424 def previous_and_next_issue_ids_params
425 {
425 {
426 :prev_issue_id => params[:prev_issue_id],
426 :prev_issue_id => params[:prev_issue_id],
427 :next_issue_id => params[:next_issue_id],
427 :next_issue_id => params[:next_issue_id],
428 :issue_position => params[:issue_position],
428 :issue_position => params[:issue_position],
429 :issue_count => params[:issue_count]
429 :issue_count => params[:issue_count]
430 }.reject {|k,v| k.blank?}
430 }.reject {|k,v| k.blank?}
431 end
431 end
432
432
433 # Used by #edit and #update to set some common instance variables
433 # Used by #edit and #update to set some common instance variables
434 # from the params
434 # from the params
435 def update_issue_from_params
435 def update_issue_from_params
436 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
436 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
437 if params[:time_entry]
437 if params[:time_entry]
438 @time_entry.safe_attributes = params[:time_entry]
438 @time_entry.safe_attributes = params[:time_entry]
439 end
439 end
440
440
441 @issue.init_journal(User.current)
441 @issue.init_journal(User.current)
442
442
443 issue_attributes = params[:issue]
443 issue_attributes = params[:issue]
444 if issue_attributes && params[:conflict_resolution]
444 if issue_attributes && params[:conflict_resolution]
445 case params[:conflict_resolution]
445 case params[:conflict_resolution]
446 when 'overwrite'
446 when 'overwrite'
447 issue_attributes = issue_attributes.dup
447 issue_attributes = issue_attributes.dup
448 issue_attributes.delete(:lock_version)
448 issue_attributes.delete(:lock_version)
449 when 'add_notes'
449 when 'add_notes'
450 issue_attributes = issue_attributes.slice(:notes, :private_notes)
450 issue_attributes = issue_attributes.slice(:notes, :private_notes)
451 when 'cancel'
451 when 'cancel'
452 redirect_to issue_path(@issue)
452 redirect_to issue_path(@issue)
453 return false
453 return false
454 end
454 end
455 end
455 end
456 @issue.safe_attributes = issue_attributes
456 @issue.safe_attributes = issue_attributes
457 @priorities = IssuePriority.active
457 @priorities = IssuePriority.active
458 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
458 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
459 true
459 true
460 end
460 end
461
461
462 # Used by #new and #create to build a new issue from the params
462 # Used by #new and #create to build a new issue from the params
463 # The new issue will be copied from an existing one if copy_from parameter is given
463 # The new issue will be copied from an existing one if copy_from parameter is given
464 def build_new_issue_from_params
464 def build_new_issue_from_params
465 @issue = Issue.new
465 @issue = Issue.new
466 if params[:copy_from]
466 if params[:copy_from]
467 begin
467 begin
468 @issue.init_journal(User.current)
468 @issue.init_journal(User.current)
469 @copy_from = Issue.visible.find(params[:copy_from])
469 @copy_from = Issue.visible.find(params[:copy_from])
470 unless User.current.allowed_to?(:copy_issues, @copy_from.project)
470 unless User.current.allowed_to?(:copy_issues, @copy_from.project)
471 raise ::Unauthorized
471 raise ::Unauthorized
472 end
472 end
473 @link_copy = link_copy?(params[:link_copy]) || request.get?
473 @link_copy = link_copy?(params[:link_copy]) || request.get?
474 @copy_attachments = params[:copy_attachments].present? || request.get?
474 @copy_attachments = params[:copy_attachments].present? || request.get?
475 @copy_subtasks = params[:copy_subtasks].present? || request.get?
475 @copy_subtasks = params[:copy_subtasks].present? || request.get?
476 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
476 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks, :link => @link_copy)
477 @issue.parent_issue_id = @copy_from.parent_id
477 @issue.parent_issue_id = @copy_from.parent_id
478 rescue ActiveRecord::RecordNotFound
478 rescue ActiveRecord::RecordNotFound
479 render_404
479 render_404
480 return
480 return
481 end
481 end
482 end
482 end
483 @issue.project = @project
483 @issue.project = @project
484 if request.get?
484 if request.get?
485 @issue.project ||= @issue.allowed_target_projects.first
485 @issue.project ||= @issue.allowed_target_projects.first
486 end
486 end
487 @issue.author ||= User.current
487 @issue.author ||= User.current
488 @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
488 @issue.start_date ||= User.current.today if Setting.default_issue_start_date_to_creation_date?
489
489
490 attrs = (params[:issue] || {}).deep_dup
490 attrs = (params[:issue] || {}).deep_dup
491 if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
491 if action_name == 'new' && params[:was_default_status] == attrs[:status_id]
492 attrs.delete(:status_id)
492 attrs.delete(:status_id)
493 end
493 end
494 if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id'
494 if action_name == 'new' && params[:form_update_triggered_by] == 'issue_project_id'
495 # Discard submitted version when changing the project on the issue form
495 # Discard submitted version when changing the project on the issue form
496 # so we can use the default version for the new project
496 # so we can use the default version for the new project
497 attrs.delete(:fixed_version_id)
497 attrs.delete(:fixed_version_id)
498 end
498 end
499 @issue.safe_attributes = attrs
499 @issue.safe_attributes = attrs
500
500
501 if @issue.project
501 if @issue.project
502 @issue.tracker ||= @issue.allowed_target_trackers.first
502 @issue.tracker ||= @issue.allowed_target_trackers.first
503 if @issue.tracker.nil?
503 if @issue.tracker.nil?
504 if @issue.project.trackers.any?
504 if @issue.project.trackers.any?
505 # None of the project trackers is allowed to the user
505 # None of the project trackers is allowed to the user
506 render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403
506 render_error :message => l(:error_no_tracker_allowed_for_new_issue_in_project), :status => 403
507 else
507 else
508 # Project has no trackers
508 # Project has no trackers
509 render_error l(:error_no_tracker_in_project)
509 render_error l(:error_no_tracker_in_project)
510 end
510 end
511 return false
511 return false
512 end
512 end
513 if @issue.status.nil?
513 if @issue.status.nil?
514 render_error l(:error_no_default_issue_status)
514 render_error l(:error_no_default_issue_status)
515 return false
515 return false
516 end
516 end
517 elsif request.get?
517 elsif request.get?
518 render_error :message => l(:error_no_projects_with_tracker_allowed_for_new_issue), :status => 403
518 render_error :message => l(:error_no_projects_with_tracker_allowed_for_new_issue), :status => 403
519 return false
519 return false
520 end
520 end
521
521
522 @priorities = IssuePriority.active
522 @priorities = IssuePriority.active
523 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
523 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
524 end
524 end
525
525
526 # Saves @issue and a time_entry from the parameters
526 # Saves @issue and a time_entry from the parameters
527 def save_issue_with_child_records
527 def save_issue_with_child_records
528 Issue.transaction do
528 Issue.transaction do
529 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
529 if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, @issue.project)
530 time_entry = @time_entry || TimeEntry.new
530 time_entry = @time_entry || TimeEntry.new
531 time_entry.project = @issue.project
531 time_entry.project = @issue.project
532 time_entry.issue = @issue
532 time_entry.issue = @issue
533 time_entry.user = User.current
533 time_entry.user = User.current
534 time_entry.spent_on = User.current.today
534 time_entry.spent_on = User.current.today
535 time_entry.attributes = params[:time_entry]
535 time_entry.attributes = params[:time_entry]
536 @issue.time_entries << time_entry
536 @issue.time_entries << time_entry
537 end
537 end
538
538
539 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
539 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
540 if @issue.save
540 if @issue.save
541 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
541 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => time_entry, :journal => @issue.current_journal})
542 else
542 else
543 raise ActiveRecord::Rollback
543 raise ActiveRecord::Rollback
544 end
544 end
545 end
545 end
546 end
546 end
547
547
548 # Returns true if the issue copy should be linked
548 # Returns true if the issue copy should be linked
549 # to the original issue
549 # to the original issue
550 def link_copy?(param)
550 def link_copy?(param)
551 case Setting.link_copied_issue
551 case Setting.link_copied_issue
552 when 'yes'
552 when 'yes'
553 true
553 true
554 when 'no'
554 when 'no'
555 false
555 false
556 when 'ask'
556 when 'ask'
557 param == '1'
557 param == '1'
558 end
558 end
559 end
559 end
560
560
561 # Redirects user after a successful issue creation
561 # Redirects user after a successful issue creation
562 def redirect_after_create
562 def redirect_after_create
563 if params[:continue]
563 if params[:continue]
564 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
564 attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?}
565 if params[:project_id]
565 if params[:project_id]
566 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
566 redirect_to new_project_issue_path(@issue.project, :issue => attrs)
567 else
567 else
568 attrs.merge! :project_id => @issue.project_id
568 attrs.merge! :project_id => @issue.project_id
569 redirect_to new_issue_path(:issue => attrs)
569 redirect_to new_issue_path(:issue => attrs)
570 end
570 end
571 else
571 else
572 redirect_to issue_path(@issue)
572 redirect_to issue_path(@issue)
573 end
573 end
574 end
574 end
575 end
575 end
@@ -1,15 +1,17
1 <h2><%= l(:label_confirmation) %></h2>
1 <h2><%= l(:label_confirmation) %></h2>
2
2
3 <%= form_tag({}, :method => :delete) do %>
3 <%= form_tag({}, :method => :delete) do %>
4 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id, :id => nil)}.join("\n").html_safe %>
4 <%= @issues.collect {|i| hidden_field_tag('ids[]', i.id, :id => nil)}.join("\n").html_safe %>
5 <div class="box">
5 <div class="box">
6 <p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
6 <p><strong><%= l(:text_destroy_time_entries_question, :hours => number_with_precision(@hours, :precision => 2)) %></strong></p>
7 <p>
7 <p>
8 <label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
8 <label><%= radio_button_tag 'todo', 'destroy', true %> <%= l(:text_destroy_time_entries) %></label><br />
9 <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
9 <label><%= radio_button_tag 'todo', 'nullify', false %> <%= l(:text_assign_time_entries_to_project) %></label><br />
10 <% if @project %>
10 <label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("#reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
11 <label><%= radio_button_tag 'todo', 'reassign', false, :onchange => 'if (this.checked) { $("#reassign_to_id").focus(); }' %> <%= l(:text_reassign_time_entries) %></label>
11 <%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("#todo_reassign").attr("checked", true);' %>
12 <%= text_field_tag 'reassign_to_id', params[:reassign_to_id], :size => 6, :onfocus => '$("#todo_reassign").attr("checked", true);' %>
13 <% end %>
12 </p>
14 </p>
13 </div>
15 </div>
14 <%= submit_tag l(:button_apply) %>
16 <%= submit_tag l(:button_apply) %>
15 <% end %>
17 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now