##// END OF EJS Templates
Adds a title to the issue link in the flash message....
Jean-Philippe Lang -
r10015:91c875437d5d
parent child
Show More

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

@@ -1,426 +1,426
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)))
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 end
224 end
225
225
226 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
226 @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
227 render :layout => false if request.xhr?
227 render :layout => false if request.xhr?
228 end
228 end
229
229
230 def bulk_update
230 def bulk_update
231 @issues.sort!
231 @issues.sort!
232 @copy = params[:copy].present?
232 @copy = params[:copy].present?
233 attributes = parse_params_for_bulk_issue_attributes(params)
233 attributes = parse_params_for_bulk_issue_attributes(params)
234
234
235 unsaved_issue_ids = []
235 unsaved_issue_ids = []
236 moved_issues = []
236 moved_issues = []
237 @issues.each do |issue|
237 @issues.each do |issue|
238 issue.reload
238 issue.reload
239 if @copy
239 if @copy
240 issue = issue.copy({}, :attachments => params[:copy_attachments].present?)
240 issue = issue.copy({}, :attachments => params[:copy_attachments].present?)
241 end
241 end
242 journal = issue.init_journal(User.current, params[:notes])
242 journal = issue.init_journal(User.current, params[:notes])
243 issue.safe_attributes = attributes
243 issue.safe_attributes = attributes
244 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
244 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
245 if issue.save
245 if issue.save
246 moved_issues << issue
246 moved_issues << issue
247 else
247 else
248 # Keep unsaved issue ids to display them in flash error
248 # Keep unsaved issue ids to display them in flash error
249 unsaved_issue_ids << issue.id
249 unsaved_issue_ids << issue.id
250 end
250 end
251 end
251 end
252 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
252 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
253
253
254 if params[:follow]
254 if params[:follow]
255 if @issues.size == 1 && moved_issues.size == 1
255 if @issues.size == 1 && moved_issues.size == 1
256 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
256 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
257 elsif moved_issues.map(&:project).uniq.size == 1
257 elsif moved_issues.map(&:project).uniq.size == 1
258 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
258 redirect_to :controller => 'issues', :action => 'index', :project_id => moved_issues.map(&:project).first
259 end
259 end
260 else
260 else
261 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
261 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
262 end
262 end
263 end
263 end
264
264
265 def destroy
265 def destroy
266 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
266 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
267 if @hours > 0
267 if @hours > 0
268 case params[:todo]
268 case params[:todo]
269 when 'destroy'
269 when 'destroy'
270 # nothing to do
270 # nothing to do
271 when 'nullify'
271 when 'nullify'
272 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
272 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
273 when 'reassign'
273 when 'reassign'
274 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
274 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
275 if reassign_to.nil?
275 if reassign_to.nil?
276 flash.now[:error] = l(:error_issue_not_found_in_project)
276 flash.now[:error] = l(:error_issue_not_found_in_project)
277 return
277 return
278 else
278 else
279 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
279 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
280 end
280 end
281 else
281 else
282 # display the destroy form if it's a user request
282 # display the destroy form if it's a user request
283 return unless api_request?
283 return unless api_request?
284 end
284 end
285 end
285 end
286 @issues.each do |issue|
286 @issues.each do |issue|
287 begin
287 begin
288 issue.reload.destroy
288 issue.reload.destroy
289 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
289 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
290 # nothing to do, issue was already deleted (eg. by a parent)
290 # nothing to do, issue was already deleted (eg. by a parent)
291 end
291 end
292 end
292 end
293 respond_to do |format|
293 respond_to do |format|
294 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
294 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
295 format.api { render_api_ok }
295 format.api { render_api_ok }
296 end
296 end
297 end
297 end
298
298
299 private
299 private
300 def find_issue
300 def find_issue
301 # Issue.visible.find(...) can not be used to redirect user to the login form
301 # Issue.visible.find(...) can not be used to redirect user to the login form
302 # if the issue actually exists but requires authentication
302 # if the issue actually exists but requires authentication
303 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
303 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
304 unless @issue.visible?
304 unless @issue.visible?
305 deny_access
305 deny_access
306 return
306 return
307 end
307 end
308 @project = @issue.project
308 @project = @issue.project
309 rescue ActiveRecord::RecordNotFound
309 rescue ActiveRecord::RecordNotFound
310 render_404
310 render_404
311 end
311 end
312
312
313 def find_project
313 def find_project
314 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
314 project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id])
315 @project = Project.find(project_id)
315 @project = Project.find(project_id)
316 rescue ActiveRecord::RecordNotFound
316 rescue ActiveRecord::RecordNotFound
317 render_404
317 render_404
318 end
318 end
319
319
320 def retrieve_previous_and_next_issue_ids
320 def retrieve_previous_and_next_issue_ids
321 retrieve_query_from_session
321 retrieve_query_from_session
322 if @query
322 if @query
323 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
323 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
324 sort_update(@query.sortable_columns, 'issues_index_sort')
324 sort_update(@query.sortable_columns, 'issues_index_sort')
325 limit = 500
325 limit = 500
326 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
326 issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version])
327 if (idx = issue_ids.index(@issue.id)) && idx < limit
327 if (idx = issue_ids.index(@issue.id)) && idx < limit
328 if issue_ids.size < 500
328 if issue_ids.size < 500
329 @issue_position = idx + 1
329 @issue_position = idx + 1
330 @issue_count = issue_ids.size
330 @issue_count = issue_ids.size
331 end
331 end
332 @prev_issue_id = issue_ids[idx - 1] if idx > 0
332 @prev_issue_id = issue_ids[idx - 1] if idx > 0
333 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
333 @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1)
334 end
334 end
335 end
335 end
336 end
336 end
337
337
338 # Used by #edit and #update to set some common instance variables
338 # Used by #edit and #update to set some common instance variables
339 # from the params
339 # from the params
340 # TODO: Refactor, not everything in here is needed by #edit
340 # TODO: Refactor, not everything in here is needed by #edit
341 def update_issue_from_params
341 def update_issue_from_params
342 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
342 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
343 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
343 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
344 @time_entry.attributes = params[:time_entry]
344 @time_entry.attributes = params[:time_entry]
345
345
346 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
346 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
347 @issue.init_journal(User.current, @notes)
347 @issue.init_journal(User.current, @notes)
348
348
349 issue_attributes = params[:issue]
349 issue_attributes = params[:issue]
350 if issue_attributes && params[:conflict_resolution]
350 if issue_attributes && params[:conflict_resolution]
351 case params[:conflict_resolution]
351 case params[:conflict_resolution]
352 when 'overwrite'
352 when 'overwrite'
353 issue_attributes = issue_attributes.dup
353 issue_attributes = issue_attributes.dup
354 issue_attributes.delete(:lock_version)
354 issue_attributes.delete(:lock_version)
355 when 'add_notes'
355 when 'add_notes'
356 issue_attributes = {}
356 issue_attributes = {}
357 when 'cancel'
357 when 'cancel'
358 redirect_to issue_path(@issue)
358 redirect_to issue_path(@issue)
359 return false
359 return false
360 end
360 end
361 end
361 end
362 @issue.safe_attributes = issue_attributes
362 @issue.safe_attributes = issue_attributes
363 @priorities = IssuePriority.active
363 @priorities = IssuePriority.active
364 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
364 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
365 true
365 true
366 end
366 end
367
367
368 # TODO: Refactor, lots of extra code in here
368 # TODO: Refactor, lots of extra code in here
369 # TODO: Changing tracker on an existing issue should not trigger this
369 # TODO: Changing tracker on an existing issue should not trigger this
370 def build_new_issue_from_params
370 def build_new_issue_from_params
371 if params[:id].blank?
371 if params[:id].blank?
372 @issue = Issue.new
372 @issue = Issue.new
373 if params[:copy_from]
373 if params[:copy_from]
374 begin
374 begin
375 @copy_from = Issue.visible.find(params[:copy_from])
375 @copy_from = Issue.visible.find(params[:copy_from])
376 @copy_attachments = params[:copy_attachments].present? || request.get?
376 @copy_attachments = params[:copy_attachments].present? || request.get?
377 @issue.copy_from(@copy_from, :attachments => @copy_attachments)
377 @issue.copy_from(@copy_from, :attachments => @copy_attachments)
378 rescue ActiveRecord::RecordNotFound
378 rescue ActiveRecord::RecordNotFound
379 render_404
379 render_404
380 return
380 return
381 end
381 end
382 end
382 end
383 @issue.project = @project
383 @issue.project = @project
384 else
384 else
385 @issue = @project.issues.visible.find(params[:id])
385 @issue = @project.issues.visible.find(params[:id])
386 end
386 end
387
387
388 @issue.project = @project
388 @issue.project = @project
389 @issue.author = User.current
389 @issue.author = User.current
390 # Tracker must be set before custom field values
390 # Tracker must be set before custom field values
391 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
391 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
392 if @issue.tracker.nil?
392 if @issue.tracker.nil?
393 render_error l(:error_no_tracker_in_project)
393 render_error l(:error_no_tracker_in_project)
394 return false
394 return false
395 end
395 end
396 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
396 @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
397 @issue.safe_attributes = params[:issue]
397 @issue.safe_attributes = params[:issue]
398
398
399 @priorities = IssuePriority.active
399 @priorities = IssuePriority.active
400 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
400 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
401 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
401 @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq
402 end
402 end
403
403
404 def check_for_default_issue_status
404 def check_for_default_issue_status
405 if IssueStatus.default.nil?
405 if IssueStatus.default.nil?
406 render_error l(:error_no_default_issue_status)
406 render_error l(:error_no_default_issue_status)
407 return false
407 return false
408 end
408 end
409 end
409 end
410
410
411 def parse_params_for_bulk_issue_attributes(params)
411 def parse_params_for_bulk_issue_attributes(params)
412 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
412 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
413 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
413 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
414 if custom = attributes[:custom_field_values]
414 if custom = attributes[:custom_field_values]
415 custom.reject! {|k,v| v.blank?}
415 custom.reject! {|k,v| v.blank?}
416 custom.keys.each do |k|
416 custom.keys.each do |k|
417 if custom[k].is_a?(Array)
417 if custom[k].is_a?(Array)
418 custom[k] << '' if custom[k].delete('__none__')
418 custom[k] << '' if custom[k].delete('__none__')
419 else
419 else
420 custom[k] = '' if custom[k] == '__none__'
420 custom[k] = '' if custom[k] == '__none__'
421 end
421 end
422 end
422 end
423 end
423 end
424 attributes
424 attributes
425 end
425 end
426 end
426 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