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