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