##// END OF EJS Templates
respond nothing in case of content type is not html with invalid query params (#8883, #6317)....
Toshi MARUYAMA -
r6904:3504fd038c1f
parent child
Show More
@@ -1,340 +1,341
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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, :move, :perform_move, :destroy]
23 before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
24 before_filter :check_project_uniqueness, :only => [:move, :perform_move]
25 before_filter :find_project, :only => [:new, :create]
25 before_filter :find_project, :only => [:new, :create]
26 before_filter :authorize, :except => [:index]
26 before_filter :authorize, :except => [:index]
27 before_filter :find_optional_project, :only => [:index]
27 before_filter :find_optional_project, :only => [:index]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
28 before_filter :check_for_default_issue_status, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
29 before_filter :build_new_issue_from_params, :only => [:new, :create]
30 accept_rss_auth :index, :show
30 accept_rss_auth :index, :show
31 accept_api_auth :index, :show, :create, :update, :destroy
31 accept_api_auth :index, :show, :create, :update, :destroy
32
32
33 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
33 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
34
34
35 helper :journals
35 helper :journals
36 helper :projects
36 helper :projects
37 include ProjectsHelper
37 include ProjectsHelper
38 helper :custom_fields
38 helper :custom_fields
39 include CustomFieldsHelper
39 include CustomFieldsHelper
40 helper :issue_relations
40 helper :issue_relations
41 include IssueRelationsHelper
41 include IssueRelationsHelper
42 helper :watchers
42 helper :watchers
43 include WatchersHelper
43 include WatchersHelper
44 helper :attachments
44 helper :attachments
45 include AttachmentsHelper
45 include AttachmentsHelper
46 helper :queries
46 helper :queries
47 include QueriesHelper
47 include QueriesHelper
48 helper :repositories
48 helper :repositories
49 include RepositoriesHelper
49 include RepositoriesHelper
50 helper :sort
50 helper :sort
51 include SortHelper
51 include SortHelper
52 include IssuesHelper
52 include IssuesHelper
53 helper :timelog
53 helper :timelog
54 helper :gantt
54 helper :gantt
55 include Redmine::Export::PDF
55 include Redmine::Export::PDF
56
56
57 verify :method => [:post, :delete],
57 verify :method => [:post, :delete],
58 :only => :destroy,
58 :only => :destroy,
59 :render => { :nothing => true, :status => :method_not_allowed }
59 :render => { :nothing => true, :status => :method_not_allowed }
60
60
61 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
61 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
62 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
62 verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
63 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
63 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
64
64
65 def index
65 def index
66 retrieve_query
66 retrieve_query
67 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
67 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
68 sort_update(@query.sortable_columns)
68 sort_update(@query.sortable_columns)
69
69
70 if @query.valid?
70 if @query.valid?
71 case params[:format]
71 case params[:format]
72 when 'csv', 'pdf'
72 when 'csv', 'pdf'
73 @limit = Setting.issues_export_limit.to_i
73 @limit = Setting.issues_export_limit.to_i
74 when 'atom'
74 when 'atom'
75 @limit = Setting.feeds_limit.to_i
75 @limit = Setting.feeds_limit.to_i
76 when 'xml', 'json'
76 when 'xml', 'json'
77 @offset, @limit = api_offset_and_limit
77 @offset, @limit = api_offset_and_limit
78 else
78 else
79 @limit = per_page_option
79 @limit = per_page_option
80 end
80 end
81
81
82 @issue_count = @query.issue_count
82 @issue_count = @query.issue_count
83 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
83 @issue_pages = Paginator.new self, @issue_count, @limit, params['page']
84 @offset ||= @issue_pages.current.offset
84 @offset ||= @issue_pages.current.offset
85 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
85 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
86 :order => sort_clause,
86 :order => sort_clause,
87 :offset => @offset,
87 :offset => @offset,
88 :limit => @limit)
88 :limit => @limit)
89 @issue_count_by_group = @query.issue_count_by_group
89 @issue_count_by_group = @query.issue_count_by_group
90
90
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.api {
93 format.api {
94 Issue.load_relations(@issues) if include_in_api_response?('relations')
94 Issue.load_relations(@issues) if include_in_api_response?('relations')
95 }
95 }
96 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
96 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
97 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
97 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
98 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
98 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
99 end
99 end
100 else
100 else
101 respond_to do |format|
101 respond_to do |format|
102 format.any(:html, :atom, :csv, :pdf) { render(:template => 'issues/index', :layout => !request.xhr?) }
102 format.html { render(:template => 'issues/index', :layout => !request.xhr?) }
103 format.any(:atom, :csv, :pdf) { render(:nothing => true) }
103 format.api { render_validation_errors(@query) }
104 format.api { render_validation_errors(@query) }
104 end
105 end
105 end
106 end
106 rescue ActiveRecord::RecordNotFound
107 rescue ActiveRecord::RecordNotFound
107 render_404
108 render_404
108 end
109 end
109
110
110 def show
111 def show
111 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
112 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
112 @journals.each_with_index {|j,i| j.indice = i+1}
113 @journals.each_with_index {|j,i| j.indice = i+1}
113 @journals.reverse! if User.current.wants_comments_in_reverse_order?
114 @journals.reverse! if User.current.wants_comments_in_reverse_order?
114
115
115 if User.current.allowed_to?(:view_changesets, @project)
116 if User.current.allowed_to?(:view_changesets, @project)
116 @changesets = @issue.changesets.visible.all
117 @changesets = @issue.changesets.visible.all
117 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
118 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
118 end
119 end
119
120
120 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
121 @relations = @issue.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
121 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
122 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
122 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
123 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
123 @priorities = IssuePriority.active
124 @priorities = IssuePriority.active
124 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
125 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
125 respond_to do |format|
126 respond_to do |format|
126 format.html { render :template => 'issues/show' }
127 format.html { render :template => 'issues/show' }
127 format.api
128 format.api
128 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
129 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
129 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
130 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
130 end
131 end
131 end
132 end
132
133
133 # Add a new issue
134 # Add a new issue
134 # The new issue will be created from an existing one if copy_from parameter is given
135 # The new issue will be created from an existing one if copy_from parameter is given
135 def new
136 def new
136 respond_to do |format|
137 respond_to do |format|
137 format.html { render :action => 'new', :layout => !request.xhr? }
138 format.html { render :action => 'new', :layout => !request.xhr? }
138 format.js { render :partial => 'attributes' }
139 format.js { render :partial => 'attributes' }
139 end
140 end
140 end
141 end
141
142
142 def create
143 def create
143 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
144 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
144 if @issue.save
145 if @issue.save
145 attachments = Attachment.attach_files(@issue, params[:attachments])
146 attachments = Attachment.attach_files(@issue, params[:attachments])
146 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
147 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
147 respond_to do |format|
148 respond_to do |format|
148 format.html {
149 format.html {
149 render_attachment_warning_if_needed(@issue)
150 render_attachment_warning_if_needed(@issue)
150 flash[:notice] = l(:notice_issue_successful_create, :id => "<a href='#{issue_path(@issue)}'>##{@issue.id}</a>")
151 flash[:notice] = l(:notice_issue_successful_create, :id => "<a href='#{issue_path(@issue)}'>##{@issue.id}</a>")
151 redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
152 redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
152 { :action => 'show', :id => @issue })
153 { :action => 'show', :id => @issue })
153 }
154 }
154 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
155 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
155 end
156 end
156 return
157 return
157 else
158 else
158 respond_to do |format|
159 respond_to do |format|
159 format.html { render :action => 'new' }
160 format.html { render :action => 'new' }
160 format.api { render_validation_errors(@issue) }
161 format.api { render_validation_errors(@issue) }
161 end
162 end
162 end
163 end
163 end
164 end
164
165
165 def edit
166 def edit
166 update_issue_from_params
167 update_issue_from_params
167
168
168 @journal = @issue.current_journal
169 @journal = @issue.current_journal
169
170
170 respond_to do |format|
171 respond_to do |format|
171 format.html { }
172 format.html { }
172 format.xml { }
173 format.xml { }
173 end
174 end
174 end
175 end
175
176
176 def update
177 def update
177 update_issue_from_params
178 update_issue_from_params
178
179
179 if @issue.save_issue_with_child_records(params, @time_entry)
180 if @issue.save_issue_with_child_records(params, @time_entry)
180 render_attachment_warning_if_needed(@issue)
181 render_attachment_warning_if_needed(@issue)
181 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
182 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
182
183
183 respond_to do |format|
184 respond_to do |format|
184 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
185 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
185 format.api { head :ok }
186 format.api { head :ok }
186 end
187 end
187 else
188 else
188 render_attachment_warning_if_needed(@issue)
189 render_attachment_warning_if_needed(@issue)
189 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
190 flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record?
190 @journal = @issue.current_journal
191 @journal = @issue.current_journal
191
192
192 respond_to do |format|
193 respond_to do |format|
193 format.html { render :action => 'edit' }
194 format.html { render :action => 'edit' }
194 format.api { render_validation_errors(@issue) }
195 format.api { render_validation_errors(@issue) }
195 end
196 end
196 end
197 end
197 end
198 end
198
199
199 # Bulk edit a set of issues
200 # Bulk edit a set of issues
200 def bulk_edit
201 def bulk_edit
201 @issues.sort!
202 @issues.sort!
202 @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
203 @available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
203 @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
204 @custom_fields = @projects.map{|p|p.all_issue_custom_fields}.inject{|memo,c|memo & c}
204 @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
205 @assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
205 @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
206 @trackers = @projects.map(&:trackers).inject{|memo,t| memo & t}
206 end
207 end
207
208
208 def bulk_update
209 def bulk_update
209 @issues.sort!
210 @issues.sort!
210 attributes = parse_params_for_bulk_issue_attributes(params)
211 attributes = parse_params_for_bulk_issue_attributes(params)
211
212
212 unsaved_issue_ids = []
213 unsaved_issue_ids = []
213 @issues.each do |issue|
214 @issues.each do |issue|
214 issue.reload
215 issue.reload
215 journal = issue.init_journal(User.current, params[:notes])
216 journal = issue.init_journal(User.current, params[:notes])
216 issue.safe_attributes = attributes
217 issue.safe_attributes = attributes
217 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
218 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
218 unless issue.save
219 unless issue.save
219 # Keep unsaved issue ids to display them in flash error
220 # Keep unsaved issue ids to display them in flash error
220 unsaved_issue_ids << issue.id
221 unsaved_issue_ids << issue.id
221 end
222 end
222 end
223 end
223 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
224 set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
224 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
225 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
225 end
226 end
226
227
227 def destroy
228 def destroy
228 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
229 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
229 if @hours > 0
230 if @hours > 0
230 case params[:todo]
231 case params[:todo]
231 when 'destroy'
232 when 'destroy'
232 # nothing to do
233 # nothing to do
233 when 'nullify'
234 when 'nullify'
234 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
235 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
235 when 'reassign'
236 when 'reassign'
236 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
237 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
237 if reassign_to.nil?
238 if reassign_to.nil?
238 flash.now[:error] = l(:error_issue_not_found_in_project)
239 flash.now[:error] = l(:error_issue_not_found_in_project)
239 return
240 return
240 else
241 else
241 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
242 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
242 end
243 end
243 else
244 else
244 # display the destroy form if it's a user request
245 # display the destroy form if it's a user request
245 return unless api_request?
246 return unless api_request?
246 end
247 end
247 end
248 end
248 @issues.each do |issue|
249 @issues.each do |issue|
249 begin
250 begin
250 issue.reload.destroy
251 issue.reload.destroy
251 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
252 rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists
252 # nothing to do, issue was already deleted (eg. by a parent)
253 # nothing to do, issue was already deleted (eg. by a parent)
253 end
254 end
254 end
255 end
255 respond_to do |format|
256 respond_to do |format|
256 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
257 format.html { redirect_back_or_default(:action => 'index', :project_id => @project) }
257 format.api { head :ok }
258 format.api { head :ok }
258 end
259 end
259 end
260 end
260
261
261 private
262 private
262 def find_issue
263 def find_issue
263 # Issue.visible.find(...) can not be used to redirect user to the login form
264 # Issue.visible.find(...) can not be used to redirect user to the login form
264 # if the issue actually exists but requires authentication
265 # if the issue actually exists but requires authentication
265 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
266 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
266 unless @issue.visible?
267 unless @issue.visible?
267 deny_access
268 deny_access
268 return
269 return
269 end
270 end
270 @project = @issue.project
271 @project = @issue.project
271 rescue ActiveRecord::RecordNotFound
272 rescue ActiveRecord::RecordNotFound
272 render_404
273 render_404
273 end
274 end
274
275
275 def find_project
276 def find_project
276 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
277 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
277 @project = Project.find(project_id)
278 @project = Project.find(project_id)
278 rescue ActiveRecord::RecordNotFound
279 rescue ActiveRecord::RecordNotFound
279 render_404
280 render_404
280 end
281 end
281
282
282 # Used by #edit and #update to set some common instance variables
283 # Used by #edit and #update to set some common instance variables
283 # from the params
284 # from the params
284 # TODO: Refactor, not everything in here is needed by #edit
285 # TODO: Refactor, not everything in here is needed by #edit
285 def update_issue_from_params
286 def update_issue_from_params
286 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
287 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
287 @priorities = IssuePriority.active
288 @priorities = IssuePriority.active
288 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
289 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
289 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
290 @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
290 @time_entry.attributes = params[:time_entry]
291 @time_entry.attributes = params[:time_entry]
291
292
292 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
293 @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
293 @issue.init_journal(User.current, @notes)
294 @issue.init_journal(User.current, @notes)
294 @issue.safe_attributes = params[:issue]
295 @issue.safe_attributes = params[:issue]
295 end
296 end
296
297
297 # TODO: Refactor, lots of extra code in here
298 # TODO: Refactor, lots of extra code in here
298 # TODO: Changing tracker on an existing issue should not trigger this
299 # TODO: Changing tracker on an existing issue should not trigger this
299 def build_new_issue_from_params
300 def build_new_issue_from_params
300 if params[:id].blank?
301 if params[:id].blank?
301 @issue = Issue.new
302 @issue = Issue.new
302 @issue.copy_from(params[:copy_from]) if params[:copy_from]
303 @issue.copy_from(params[:copy_from]) if params[:copy_from]
303 @issue.project = @project
304 @issue.project = @project
304 else
305 else
305 @issue = @project.issues.visible.find(params[:id])
306 @issue = @project.issues.visible.find(params[:id])
306 end
307 end
307
308
308 @issue.project = @project
309 @issue.project = @project
309 @issue.author = User.current
310 @issue.author = User.current
310 # Tracker must be set before custom field values
311 # Tracker must be set before custom field values
311 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
312 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
312 if @issue.tracker.nil?
313 if @issue.tracker.nil?
313 render_error l(:error_no_tracker_in_project)
314 render_error l(:error_no_tracker_in_project)
314 return false
315 return false
315 end
316 end
316 @issue.start_date ||= Date.today
317 @issue.start_date ||= Date.today
317 if params[:issue].is_a?(Hash)
318 if params[:issue].is_a?(Hash)
318 @issue.safe_attributes = params[:issue]
319 @issue.safe_attributes = params[:issue]
319 if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
320 if User.current.allowed_to?(:add_issue_watchers, @project) && @issue.new_record?
320 @issue.watcher_user_ids = params[:issue]['watcher_user_ids']
321 @issue.watcher_user_ids = params[:issue]['watcher_user_ids']
321 end
322 end
322 end
323 end
323 @priorities = IssuePriority.active
324 @priorities = IssuePriority.active
324 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
325 @allowed_statuses = @issue.new_statuses_allowed_to(User.current, true)
325 end
326 end
326
327
327 def check_for_default_issue_status
328 def check_for_default_issue_status
328 if IssueStatus.default.nil?
329 if IssueStatus.default.nil?
329 render_error l(:error_no_default_issue_status)
330 render_error l(:error_no_default_issue_status)
330 return false
331 return false
331 end
332 end
332 end
333 end
333
334
334 def parse_params_for_bulk_issue_attributes(params)
335 def parse_params_for_bulk_issue_attributes(params)
335 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
336 attributes = (params[:issue] || {}).reject {|k,v| v.blank?}
336 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
337 attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
337 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
338 attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
338 attributes
339 attributes
339 end
340 end
340 end
341 end
General Comments 0
You need to be logged in to leave comments. Login now