##// END OF EJS Templates
Don't create a journal when creating an issue with attachments....
Jean-Philippe Lang -
r13351:95810125bf1d
parent child
Show More

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

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