##// END OF EJS Templates
Do not copy subtasks twice when copying an issue and its descendants (#6965)....
Jean-Philippe Lang -
r10146:b72d40a4292a
parent child
Show More

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

@@ -1,431 +1,438
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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]
24 before_filter :find_project, :only => [:new, :create]
25 before_filter :authorize, :except => [:index]
25 before_filter :authorize, :except => [:index]
26 before_filter :find_optional_project, :only => [:index]
26 before_filter :find_optional_project, :only => [:index]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
27 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :build_new_issue_from_params, :only => [:new, :create]
28 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 accept_rss_auth :index, :show
29 accept_rss_auth :index, :show
30 accept_api_auth :index, :show, :create, :update, :destroy
30 accept_api_auth :index, :show, :create, :update, :destroy
31
31
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
32 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33
33
34 helper :journals
34 helper :journals
35 helper :projects
35 helper :projects
36 include ProjectsHelper
36 include ProjectsHelper
37 helper :custom_fields
37 helper :custom_fields
38 include CustomFieldsHelper
38 include CustomFieldsHelper
39 helper :issue_relations
39 helper :issue_relations
40 include IssueRelationsHelper
40 include IssueRelationsHelper
41 helper :watchers
41 helper :watchers
42 include WatchersHelper
42 include WatchersHelper
43 helper :attachments
43 helper :attachments
44 include AttachmentsHelper
44 include AttachmentsHelper
45 helper :queries
45 helper :queries
46 include QueriesHelper
46 include QueriesHelper
47 helper :repositories
47 helper :repositories
48 include RepositoriesHelper
48 include RepositoriesHelper
49 helper :sort
49 helper :sort
50 include SortHelper
50 include SortHelper
51 include IssuesHelper
51 include IssuesHelper
52 helper :timelog
52 helper :timelog
53 include Redmine::Export::PDF
53 include Redmine::Export::PDF
54
54
55 def index
55 def index
56 retrieve_query
56 retrieve_query
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
58 sort_update(@query.sortable_columns)
58 sort_update(@query.sortable_columns)
59
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 when 'atom'
64 when 'atom'
65 @limit = Setting.feeds_limit.to_i
65 @limit = Setting.feeds_limit.to_i
66 when 'xml', 'json'
66 when 'xml', 'json'
67 @offset, @limit = api_offset_and_limit
67 @offset, @limit = api_offset_and_limit
68 else
68 else
69 @limit = per_page_option
69 @limit = per_page_option
70 end
70 end
71
71
72 @issue_count = @query.issue_count
72 @issue_count = @query.issue_count
73 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
73 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
74 @offset ||= @issue_pages.current.offset
74 @offset ||= @issue_pages.current.offset
75 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
75 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
76 :order => sort_clause,
76 :order => sort_clause,
77 :offset => @offset,
77 :offset => @offset,
78 :limit => @limit)
78 :limit => @limit)
79 @issue_count_by_group = @query.issue_count_by_group
79 @issue_count_by_group = @query.issue_count_by_group
80
80
81 respond_to do |format|
81 respond_to do |format|
82 format.html { render :template => 'issues/index', :layout => !request.xhr? }
82 format.html { render :template => 'issues/index', :layout => !request.xhr? }
83 format.api {
83 format.api {
84 Issue.load_relations(@issues) if include_in_api_response?('relations')
84 Issue.load_relations(@issues) if include_in_api_response?('relations')
85 }
85 }
86 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
86 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') }
87 format.csv { send_data(issues_to_csv(@issues, @project, @query, params), :type => 'text/csv; header=present', :filename => 'export.csv') }
88 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
88 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
89 end
89 end
90 else
90 else
91 respond_to do |format|
91 respond_to do |format|
92 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
92 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
93 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
93 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
94 format.api { render_validation_errors(@query) }
94 format.api { render_validation_errors(@query) }
95 end
95 end
96 end
96 end
97 rescue ActiveRecord::RecordNotFound
97 rescue ActiveRecord::RecordNotFound
98 render_404
98 render_404
99 end
99 end
100
100
101 def show
101 def show
102 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
102 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
103 @journals.each_with_index {|j,i| j.indice = i+1}
103 @journals.each_with_index {|j,i| j.indice = i+1}
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.all
106 @changesets = @issue.changesets.visible.all
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 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
111 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
112 @priorities = IssuePriority.active
112 @priorities = IssuePriority.active
113 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
113 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
114 respond_to do |format|
114 respond_to do |format|
115 format.html {
115 format.html {
116 retrieve_previous_and_next_issue_ids
116 retrieve_previous_and_next_issue_ids
117 render :template => 'issues/show'
117 render :template => 'issues/show'
118 }
118 }
119 format.api
119 format.api
120 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
120 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
122 end
122 end
123 end
123 end
124
124
125 # Add a new issue
125 # Add a new issue
126 # The new issue will be created from an existing one if copy_from parameter is given
126 # The new issue will be created from an existing one if copy_from parameter is given
127 def new
127 def new
128 respond_to do |format|
128 respond_to do |format|
129 format.html { render :action => 'new', :layout => !request.xhr? }
129 format.html { render :action => 'new', :layout => !request.xhr? }
130 format.js { render :partial => 'update_form' }
130 format.js { render :partial => 'update_form' }
131 end
131 end
132 end
132 end
133
133
134 def create
134 def create
135 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
135 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
136 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
136 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
137 if @issue.save
137 if @issue.save
138 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
138 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
139 respond_to do |format|
139 respond_to do |format|
140 format.html {
140 format.html {
141 render_attachment_warning_if_needed(@issue)
141 render_attachment_warning_if_needed(@issue)
142 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
142 flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject))
143 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
143 redirect_to(params[:continue] ? { :action => 'new', :project_id => @issue.project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
144 { :action => 'show', :id => @issue })
144 { :action => 'show', :id => @issue })
145 }
145 }
146 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
146 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
147 end
147 end
148 return
148 return
149 else
149 else
150 respond_to do |format|
150 respond_to do |format|
151 format.html { render :action => 'new' }
151 format.html { render :action => 'new' }
152 format.api { render_validation_errors(@issue) }
152 format.api { render_validation_errors(@issue) }
153 end
153 end
154 end
154 end
155 end
155 end
156
156
157 def edit
157 def edit
158 return unless update_issue_from_params
158 return unless update_issue_from_params
159
159
160 respond_to do |format|
160 respond_to do |format|
161 format.html { }
161 format.html { }
162 format.xml { }
162 format.xml { }
163 end
163 end
164 end
164 end
165
165
166 def update
166 def update
167 return unless update_issue_from_params
167 return unless update_issue_from_params
168 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
168 @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads]))
169 saved = false
169 saved = false
170 begin
170 begin
171 saved = @issue.save_issue_with_child_records(params, @time_entry)
171 saved = @issue.save_issue_with_child_records(params, @time_entry)
172 rescue ActiveRecord::StaleObjectError
172 rescue ActiveRecord::StaleObjectError
173 @conflict = true
173 @conflict = true
174 if params[:last_journal_id]
174 if params[:last_journal_id]
175 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
175 @conflict_journals = @issue.journals_after(params[:last_journal_id]).all
176 end
176 end
177 end
177 end
178
178
179 if saved
179 if saved
180 render_attachment_warning_if_needed(@issue)
180 render_attachment_warning_if_needed(@issue)
181 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
181 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
182
182
183 respond_to do |format|
183 respond_to do |format|
184 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
184 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
185 format.api { render_api_ok }
185 format.api { render_api_ok }
186 end
186 end
187 else
187 else
188 respond_to do |format|
188 respond_to do |format|
189 format.html { render :action => 'edit' }
189 format.html { render :action => 'edit' }
190 format.api { render_validation_errors(@issue) }
190 format.api { render_validation_errors(@issue) }
191 end
191 end
192 end
192 end
193 end
193 end
194
194
195 # Bulk edit/copy a set of issues
195 # Bulk edit/copy a set of issues
196 def bulk_edit
196 def bulk_edit
197 @issues.sort!
197 @issues.sort!
198 @copy = params[:copy].present?
198 @copy = params[:copy].present?
199 @notes = params[:notes]
199 @notes = params[:notes]
200
200
201 if User.current.allowed_to?(:move_issues, @projects)
201 if User.current.allowed_to?(:move_issues, @projects)
202 @allowed_projects = Issue.allowed_target_projects_on_move
202 @allowed_projects = Issue.allowed_target_projects_on_move
203 if params[:issue]
203 if params[:issue]
204 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
204 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s}
205 if @target_project
205 if @target_project
206 target_projects = [@target_project]
206 target_projects = [@target_project]
207 end
207 end
208 end
208 end
209 end
209 end
210 target_projects ||= @projects
210 target_projects ||= @projects
211
211
212 if @copy
212 if @copy
213 @available_statuses = [IssueStatus.default]
213 @available_statuses = [IssueStatus.default]
214 else
214 else
215 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
215 @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
216 end
216 end
217 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
217 @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&)
218 @assignables = target_projects.map(&:assignable_users).reduce(:&)
218 @assignables = target_projects.map(&:assignable_users).reduce(:&)
219 @trackers = target_projects.map(&:trackers).reduce(:&)
219 @trackers = target_projects.map(&:trackers).reduce(:&)
220 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
220 @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&)
221 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
221 @categories = target_projects.map {|p| p.issue_categories}.reduce(:&)
222 if @copy
222 if @copy
223 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
223 @attachments_present = @issues.detect {|i| i.attachments.any?}.present?
224 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
224 @subtasks_present = @issues.detect {|i| !i.leaf?}.present?
225 end
225 end
226
226
227 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
227 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
228 render :layout => false if request.xhr?
228 render :layout => false if request.xhr?
229 end
229 end
230
230
231 def bulk_update
231 def bulk_update
232 @issues.sort!
232 @issues.sort!
233 @copy = params[:copy].present?
233 @copy = params[:copy].present?
234 attributes = parse_params_for_bulk_issue_attributes(params)
234 attributes = parse_params_for_bulk_issue_attributes(params)
235
235
236 unsaved_issue_ids = []
236 unsaved_issue_ids = []
237 moved_issues = []
237 moved_issues = []
238
239 if @copy && params[:copy_subtasks].present?
240 # Descendant issues will be copied with the parent task
241 # Don't copy them twice
242 @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}}
243 end
244
238 @issues.each do |issue|
245 @issues.each do |issue|
239 issue.reload
246 issue.reload
240 if @copy
247 if @copy
241 issue = issue.copy({},
248 issue = issue.copy({},
242 :attachments => params[:copy_attachments].present?,
249 :attachments => params[:copy_attachments].present?,
243 :subtasks => params[:copy_subtasks].present?
250 :subtasks => params[:copy_subtasks].present?
244 )
251 )
245 end
252 end
246 journal = issue.init_journal(User.current, params[:notes])
253 journal = issue.init_journal(User.current, params[:notes])
247 issue.safe_attributes = attributes
254 issue.safe_attributes = attributes
248 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
255 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
249 if issue.save
256 if issue.save
250 moved_issues << issue
257 moved_issues << issue
251 else
258 else
252 # Keep unsaved issue ids to display them in flash error
259 # Keep unsaved issue ids to display them in flash error
253 unsaved_issue_ids << issue.id
260 unsaved_issue_ids << issue.id
254 end
261 end
255 end
262 end
256 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
263 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
257
264
258 if params[:follow]
265 if params[:follow]
259 if @issues.size == 1 && moved_issues.size == 1
266 if @issues.size == 1 && moved_issues.size == 1
260 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
267 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
261 elsif moved_issues.map(&:project).uniq.size == 1
268 elsif moved_issues.map(&:project).uniq.size == 1
262 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
269 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
263 end
270 end
264 else
271 else
265 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
272 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
266 end
273 end
267 end
274 end
268
275
269 def destroy
276 def destroy
270 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
277 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
271 if @hours > 0
278 if @hours > 0
272 case params[:todo]
279 case params[:todo]
273 when 'destroy'
280 when 'destroy'
274 # nothing to do
281 # nothing to do
275 when 'nullify'
282 when 'nullify'
276 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
283 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
277 when 'reassign'
284 when 'reassign'
278 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
285 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
279 if reassign_to.nil?
286 if reassign_to.nil?
280 flash.now[:error] = l(:error_issue_not_found_in_project)
287 flash.now[:error] = l(:error_issue_not_found_in_project)
281 return
288 return
282 else
289 else
283 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
290 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
284 end
291 end
285 else
292 else
286 # display the destroy form if it's a user request
293 # display the destroy form if it's a user request
287 return unless api_request?
294 return unless api_request?
288 end
295 end
289 end
296 end
290 @issues.each do |issue|
297 @issues.each do |issue|
291 begin
298 begin
292 issue.reload.destroy
299 issue.reload.destroy
293 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
300 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
294 # nothing to do, issue was already deleted (eg. by a parent)
301 # nothing to do, issue was already deleted (eg. by a parent)
295 end
302 end
296 end
303 end
297 respond_to do |format|
304 respond_to do |format|
298 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
305 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
299 format.api { render_api_ok }
306 format.api { render_api_ok }
300 end
307 end
301 end
308 end
302
309
303 private
310 private
304 def find_issue
311 def find_issue
305 # Issue.visible.find(...) can not be used to redirect user to the login form
312 # Issue.visible.find(...) can not be used to redirect user to the login form
306 # if the issue actually exists but requires authentication
313 # if the issue actually exists but requires authentication
307 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
314 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
308 unless @issue.visible?
315 unless @issue.visible?
309 deny_access
316 deny_access
310 return
317 return
311 end
318 end
312 @project = @issue.project
319 @project = @issue.project
313 rescue ActiveRecord::RecordNotFound
320 rescue ActiveRecord::RecordNotFound
314 render_404
321 render_404
315 end
322 end
316
323
317 def find_project
324 def find_project
318 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
325 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
319 @project = Project.find(project_id)
326 @project = Project.find(project_id)
320 rescue ActiveRecord::RecordNotFound
327 rescue ActiveRecord::RecordNotFound
321 render_404
328 render_404
322 end
329 end
323
330
324 def retrieve_previous_and_next_issue_ids
331 def retrieve_previous_and_next_issue_ids
325 retrieve_query_from_session
332 retrieve_query_from_session
326 if @query
333 if @query
327 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
334 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
328 sort_update(@query.sortable_columns, 'issues_index_sort')
335 sort_update(@query.sortable_columns, 'issues_index_sort')
329 limit = 500
336 limit = 500
330 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
337 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
331 if (idx = issue_ids.index(@issue.id)) && idx < limit
338 if (idx = issue_ids.index(@issue.id)) && idx < limit
332 if issue_ids.size < 500
339 if issue_ids.size < 500
333 @issue_position = idx + 1
340 @issue_position = idx + 1
334 @issue_count = issue_ids.size
341 @issue_count = issue_ids.size
335 end
342 end
336 @prev_issue_id = issue_ids[idx - 1] if idx > 0
343 @prev_issue_id = issue_ids[idx - 1] if idx > 0
337 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
344 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
338 end
345 end
339 end
346 end
340 end
347 end
341
348
342 # Used by #edit and #update to set some common instance variables
349 # Used by #edit and #update to set some common instance variables
343 # from the params
350 # from the params
344 # TODO: Refactor, not everything in here is needed by #edit
351 # TODO: Refactor, not everything in here is needed by #edit
345 def update_issue_from_params
352 def update_issue_from_params
346 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
353 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
347 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
354 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
348 @time_entry.attributes = params[:time_entry]
355 @time_entry.attributes = params[:time_entry]
349
356
350 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
357 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
351 @issue.init_journal(User.current, @notes)
358 @issue.init_journal(User.current, @notes)
352
359
353 issue_attributes = params[:issue]
360 issue_attributes = params[:issue]
354 if issue_attributes && params[:conflict_resolution]
361 if issue_attributes && params[:conflict_resolution]
355 case params[:conflict_resolution]
362 case params[:conflict_resolution]
356 when 'overwrite'
363 when 'overwrite'
357 issue_attributes = issue_attributes.dup
364 issue_attributes = issue_attributes.dup
358 issue_attributes.delete(:lock_version)
365 issue_attributes.delete(:lock_version)
359 when 'add_notes'
366 when 'add_notes'
360 issue_attributes = {}
367 issue_attributes = {}
361 when 'cancel'
368 when 'cancel'
362 redirect_to issue_path(@issue)
369 redirect_to issue_path(@issue)
363 return false
370 return false
364 end
371 end
365 end
372 end
366 @issue.safe_attributes = issue_attributes
373 @issue.safe_attributes = issue_attributes
367 @priorities = IssuePriority.active
374 @priorities = IssuePriority.active
368 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
375 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
369 true
376 true
370 end
377 end
371
378
372 # TODO: Refactor, lots of extra code in here
379 # TODO: Refactor, lots of extra code in here
373 # TODO: Changing tracker on an existing issue should not trigger this
380 # TODO: Changing tracker on an existing issue should not trigger this
374 def build_new_issue_from_params
381 def build_new_issue_from_params
375 if params[:id].blank?
382 if params[:id].blank?
376 @issue = Issue.new
383 @issue = Issue.new
377 if params[:copy_from]
384 if params[:copy_from]
378 begin
385 begin
379 @copy_from = Issue.visible.find(params[:copy_from])
386 @copy_from = Issue.visible.find(params[:copy_from])
380 @copy_attachments = params[:copy_attachments].present? || request.get?
387 @copy_attachments = params[:copy_attachments].present? || request.get?
381 @copy_subtasks = params[:copy_subtasks].present? || request.get?
388 @copy_subtasks = params[:copy_subtasks].present? || request.get?
382 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
389 @issue.copy_from(@copy_from, :attachments => @copy_attachments, :subtasks => @copy_subtasks)
383 rescue ActiveRecord::RecordNotFound
390 rescue ActiveRecord::RecordNotFound
384 render_404
391 render_404
385 return
392 return
386 end
393 end
387 end
394 end
388 @issue.project = @project
395 @issue.project = @project
389 else
396 else
390 @issue = @project.issues.visible.find(params[:id])
397 @issue = @project.issues.visible.find(params[:id])
391 end
398 end
392
399
393 @issue.project = @project
400 @issue.project = @project
394 @issue.author = User.current
401 @issue.author = User.current
395 # Tracker must be set before custom field values
402 # Tracker must be set before custom field values
396 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
403 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
397 if @issue.tracker.nil?
404 if @issue.tracker.nil?
398 render_error l(:error_no_tracker_in_project)
405 render_error l(:error_no_tracker_in_project)
399 return false
406 return false
400 end
407 end
401 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
408 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
402 @issue.safe_attributes = params[:issue]
409 @issue.safe_attributes = params[:issue]
403
410
404 @priorities = IssuePriority.active
411 @priorities = IssuePriority.active
405 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
412 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
406 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
413 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
407 end
414 end
408
415
409 def check_for_default_issue_status
416 def check_for_default_issue_status
410 if IssueStatus.default.nil?
417 if IssueStatus.default.nil?
411 render_error l(:error_no_default_issue_status)
418 render_error l(:error_no_default_issue_status)
412 return false
419 return false
413 end
420 end
414 end
421 end
415
422
416 def parse_params_for_bulk_issue_attributes(params)
423 def parse_params_for_bulk_issue_attributes(params)
417 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
424 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
418 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
425 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
419 if custom = attributes[:custom_field_values]
426 if custom = attributes[:custom_field_values]
420 custom.reject! {|k,v| v.blank?}
427 custom.reject! {|k,v| v.blank?}
421 custom.keys.each do |k|
428 custom.keys.each do |k|
422 if custom[k].is_a?(Array)
429 if custom[k].is_a?(Array)
423 custom[k] << '' if custom[k].delete('__none__')
430 custom[k] << '' if custom[k].delete('__none__')
424 else
431 else
425 custom[k] = '' if custom[k] == '__none__'
432 custom[k] = '' if custom[k] == '__none__'
426 end
433 end
427 end
434 end
428 end
435 end
429 attributes
436 attributes
430 end
437 end
431 end
438 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