##// END OF EJS Templates
Reverts r3366....
Jean-Philippe Lang -
r3253:ea51dcf91196
parent child
Show More
@@ -1,574 +1,572
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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
20 20 default_search_scope :issues
21 21
22 22 before_filter :find_issue, :only => [:show, :edit, :reply]
23 23 before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 24 before_filter :find_project, :only => [:new, :update_form, :preview]
25 25 before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
26 26 before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
27 27 accept_key_auth :index, :show, :changes
28 28
29 29 rescue_from Query::StatementInvalid, :with => :query_statement_invalid
30 30
31 31 helper :journals
32 32 helper :projects
33 33 include ProjectsHelper
34 34 helper :custom_fields
35 35 include CustomFieldsHelper
36 36 helper :issue_relations
37 37 include IssueRelationsHelper
38 38 helper :watchers
39 39 include WatchersHelper
40 40 helper :attachments
41 41 include AttachmentsHelper
42 42 helper :queries
43 43 include QueriesHelper
44 44 helper :sort
45 45 include SortHelper
46 46 include IssuesHelper
47 47 helper :timelog
48 48 include Redmine::Export::PDF
49 49
50 50 verify :method => [:post, :delete],
51 51 :only => :destroy,
52 52 :render => { :nothing => true, :status => :method_not_allowed }
53 53
54 54 def index
55 55 retrieve_query
56 56 sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
57 57 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
58 58
59 59 if @query.valid?
60 limit = case params[:format]
61 when 'csv', 'pdf'
62 Setting.issues_export_limit.to_i
63 when 'atom'
64 Setting.feeds_limit.to_i
65 else
66 per_page_option
60 limit = per_page_option
61 respond_to do |format|
62 format.html { }
63 format.xml { }
64 format.atom { limit = Setting.feeds_limit.to_i }
65 format.csv { limit = Setting.issues_export_limit.to_i }
66 format.pdf { limit = Setting.issues_export_limit.to_i }
67 67 end
68 68
69 69 @issue_count = @query.issue_count
70 70 @issue_pages = Paginator.new self, @issue_count, limit, params['page']
71 71 @issues = @query.issues(:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
72 72 :order => sort_clause,
73 73 :offset => @issue_pages.current.offset,
74 74 :limit => limit)
75 75 @issue_count_by_group = @query.issue_count_by_group
76 76
77 77 respond_to do |format|
78 78 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
79 79 format.xml { render :layout => false }
80 80 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
81 81 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
82 82 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
83 83 end
84 84 else
85 85 # Send html if the query is not valid
86 86 render(:template => 'issues/index.rhtml', :layout => !request.xhr?)
87 87 end
88 88 rescue ActiveRecord::RecordNotFound
89 89 render_404
90 90 end
91 91
92 92 def changes
93 93 retrieve_query
94 94 sort_init 'id', 'desc'
95 95 sort_update({'id' => "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h}))
96 96
97 97 if @query.valid?
98 98 @journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
99 99 :limit => 25)
100 100 end
101 101 @title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
102 102 render :layout => false, :content_type => 'application/atom+xml'
103 103 rescue ActiveRecord::RecordNotFound
104 104 render_404
105 105 end
106 106
107 107 def show
108 108 @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
109 109 @journals.each_with_index {|j,i| j.indice = i+1}
110 110 @journals.reverse! if User.current.wants_comments_in_reverse_order?
111 111 @changesets = @issue.changesets.visible.all
112 112 @changesets.reverse! if User.current.wants_comments_in_reverse_order?
113 113 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
114 114 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
115 115 @priorities = IssuePriority.all
116 116 @time_entry = TimeEntry.new
117 117 respond_to do |format|
118 118 format.html { render :template => 'issues/show.rhtml' }
119 119 format.xml { render :layout => false }
120 120 format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
121 121 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
122 122 end
123 123 end
124 124
125 125 # Add a new issue
126 126 # The new issue will be created from an existing one if copy_from parameter is given
127 127 def new
128 128 @issue = Issue.new
129 129 @issue.copy_from(params[:copy_from]) if params[:copy_from]
130 130 @issue.project = @project
131 131 # Tracker must be set before custom field values
132 132 @issue.tracker ||= @project.trackers.find((params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id] || :first)
133 133 if @issue.tracker.nil?
134 134 render_error l(:error_no_tracker_in_project)
135 135 return
136 136 end
137 137 if params[:issue].is_a?(Hash)
138 138 @issue.safe_attributes = params[:issue]
139 139 @issue.watcher_user_ids = params[:issue]['watcher_user_ids'] if User.current.allowed_to?(:add_issue_watchers, @project)
140 140 end
141 141 @issue.author = User.current
142 142
143 143 default_status = IssueStatus.default
144 144 unless default_status
145 145 render_error l(:error_no_default_issue_status)
146 146 return
147 147 end
148 148 @issue.status = default_status
149 149 @allowed_statuses = ([default_status] + default_status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
150 150
151 151 if request.get? || request.xhr?
152 152 @issue.start_date ||= Date.today
153 153 else
154 154 requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
155 155 # Check that the user is allowed to apply the requested status
156 156 @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
157 157 call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue })
158 158 if @issue.save
159 159 attach_files(@issue, params[:attachments])
160 flash[:notice] = l(:notice_successful_create)
160 161 call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue})
161 162 respond_to do |format|
162 163 format.html {
163 # Displays a link to the newly created issue in the flash message
164 link = @template.link_to("##{@issue.id}", {:controller => 'issues', :action => 'show', :id => @issue})
165 flash[:notice] = l(:notice_issue_created, :value => link)
166 164 redirect_to(params[:continue] ? { :action => 'new', :tracker_id => @issue.tracker } :
167 165 { :action => 'show', :id => @issue })
168 166 }
169 167 format.xml { render :action => 'show', :status => :created, :location => url_for(:controller => 'issues', :action => 'show', :id => @issue) }
170 168 end
171 169 return
172 170 else
173 171 respond_to do |format|
174 172 format.html { }
175 173 format.xml { render(:xml => @issue.errors, :status => :unprocessable_entity); return }
176 174 end
177 175 end
178 176 end
179 177 @priorities = IssuePriority.all
180 178 render :layout => !request.xhr?
181 179 end
182 180
183 181 # Attributes that can be updated on workflow transition (without :edit permission)
184 182 # TODO: make it configurable (at least per role)
185 183 UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
186 184
187 185 def edit
188 186 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
189 187 @priorities = IssuePriority.all
190 188 @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
191 189 @time_entry = TimeEntry.new
192 190
193 191 @notes = params[:notes]
194 192 journal = @issue.init_journal(User.current, @notes)
195 193 # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
196 194 if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
197 195 attrs = params[:issue].dup
198 196 attrs.delete_if {|k,v| !UPDATABLE_ATTRS_ON_TRANSITION.include?(k) } unless @edit_allowed
199 197 attrs.delete(:status_id) unless @allowed_statuses.detect {|s| s.id.to_s == attrs[:status_id].to_s}
200 198 @issue.safe_attributes = attrs
201 199 end
202 200
203 201 if request.get?
204 202 # nop
205 203 else
206 204 @time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
207 205 @time_entry.attributes = params[:time_entry]
208 206 if (@time_entry.hours.nil? || @time_entry.valid?) && @issue.valid?
209 207 attachments = attach_files(@issue, params[:attachments])
210 208 attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
211 209 call_hook(:controller_issues_edit_before_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
212 210 if @issue.save
213 211 # Log spend time
214 212 if User.current.allowed_to?(:log_time, @project)
215 213 @time_entry.save
216 214 end
217 215 if !journal.new_record?
218 216 # Only send notification if something was actually changed
219 217 flash[:notice] = l(:notice_successful_update)
220 218 end
221 219 call_hook(:controller_issues_edit_after_save, { :params => params, :issue => @issue, :time_entry => @time_entry, :journal => journal})
222 220 respond_to do |format|
223 221 format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
224 222 format.xml { head :ok }
225 223 end
226 224 return
227 225 end
228 226 end
229 227 # failure
230 228 respond_to do |format|
231 229 format.html { }
232 230 format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
233 231 end
234 232 end
235 233 rescue ActiveRecord::StaleObjectError
236 234 # Optimistic locking exception
237 235 flash.now[:error] = l(:notice_locking_conflict)
238 236 # Remove the previously added attachments if issue was not updated
239 237 attachments.each(&:destroy)
240 238 end
241 239
242 240 def reply
243 241 journal = Journal.find(params[:journal_id]) if params[:journal_id]
244 242 if journal
245 243 user = journal.user
246 244 text = journal.notes
247 245 else
248 246 user = @issue.author
249 247 text = @issue.description
250 248 end
251 249 content = "#{ll(Setting.default_language, :text_user_wrote, user)}\\n> "
252 250 content << text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]').gsub('"', '\"').gsub(/(\r?\n|\r\n?)/, "\\n> ") + "\\n\\n"
253 251 render(:update) { |page|
254 252 page.<< "$('notes').value = \"#{content}\";"
255 253 page.show 'update'
256 254 page << "Form.Element.focus('notes');"
257 255 page << "Element.scrollTo('update');"
258 256 page << "$('notes').scrollTop = $('notes').scrollHeight - $('notes').clientHeight;"
259 257 }
260 258 end
261 259
262 260 # Bulk edit a set of issues
263 261 def bulk_edit
264 262 if request.post?
265 263 tracker = params[:tracker_id].blank? ? nil : @project.trackers.find_by_id(params[:tracker_id])
266 264 status = params[:status_id].blank? ? nil : IssueStatus.find_by_id(params[:status_id])
267 265 priority = params[:priority_id].blank? ? nil : IssuePriority.find_by_id(params[:priority_id])
268 266 assigned_to = (params[:assigned_to_id].blank? || params[:assigned_to_id] == 'none') ? nil : User.find_by_id(params[:assigned_to_id])
269 267 category = (params[:category_id].blank? || params[:category_id] == 'none') ? nil : @project.issue_categories.find_by_id(params[:category_id])
270 268 fixed_version = (params[:fixed_version_id].blank? || params[:fixed_version_id] == 'none') ? nil : @project.shared_versions.find_by_id(params[:fixed_version_id])
271 269 custom_field_values = params[:custom_field_values] ? params[:custom_field_values].reject {|k,v| v.blank?} : nil
272 270
273 271 unsaved_issue_ids = []
274 272 @issues.each do |issue|
275 273 journal = issue.init_journal(User.current, params[:notes])
276 274 issue.tracker = tracker if tracker
277 275 issue.priority = priority if priority
278 276 issue.assigned_to = assigned_to if assigned_to || params[:assigned_to_id] == 'none'
279 277 issue.category = category if category || params[:category_id] == 'none'
280 278 issue.fixed_version = fixed_version if fixed_version || params[:fixed_version_id] == 'none'
281 279 issue.start_date = params[:start_date] unless params[:start_date].blank?
282 280 issue.due_date = params[:due_date] unless params[:due_date].blank?
283 281 issue.done_ratio = params[:done_ratio] unless params[:done_ratio].blank?
284 282 issue.custom_field_values = custom_field_values if custom_field_values && !custom_field_values.empty?
285 283 call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
286 284 # Don't save any change to the issue if the user is not authorized to apply the requested status
287 285 unless (status.nil? || (issue.new_statuses_allowed_to(User.current).include?(status) && issue.status = status)) && issue.save
288 286 # Keep unsaved issue ids to display them in flash error
289 287 unsaved_issue_ids << issue.id
290 288 end
291 289 end
292 290 if unsaved_issue_ids.empty?
293 291 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
294 292 else
295 293 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
296 294 :total => @issues.size,
297 295 :ids => '#' + unsaved_issue_ids.join(', #'))
298 296 end
299 297 redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
300 298 return
301 299 end
302 300 @available_statuses = Workflow.available_statuses(@project)
303 301 @custom_fields = @project.all_issue_custom_fields
304 302 end
305 303
306 304 def move
307 305 @copy = params[:copy_options] && params[:copy_options][:copy]
308 306 @allowed_projects = []
309 307 # find projects to which the user is allowed to move the issue
310 308 if User.current.admin?
311 309 # admin is allowed to move issues to any active (visible) project
312 310 @allowed_projects = Project.find(:all, :conditions => Project.visible_by(User.current))
313 311 else
314 312 User.current.memberships.each {|m| @allowed_projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
315 313 end
316 314 @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:new_project_id]} if params[:new_project_id]
317 315 @target_project ||= @project
318 316 @trackers = @target_project.trackers
319 317 @available_statuses = Workflow.available_statuses(@project)
320 318 if request.post?
321 319 new_tracker = params[:new_tracker_id].blank? ? nil : @target_project.trackers.find_by_id(params[:new_tracker_id])
322 320 unsaved_issue_ids = []
323 321 moved_issues = []
324 322 @issues.each do |issue|
325 323 changed_attributes = {}
326 324 [:assigned_to_id, :status_id, :start_date, :due_date].each do |valid_attribute|
327 325 unless params[valid_attribute].blank?
328 326 changed_attributes[valid_attribute] = (params[valid_attribute] == 'none' ? nil : params[valid_attribute])
329 327 end
330 328 end
331 329 issue.init_journal(User.current)
332 330 if r = issue.move_to(@target_project, new_tracker, {:copy => @copy, :attributes => changed_attributes})
333 331 moved_issues << r
334 332 else
335 333 unsaved_issue_ids << issue.id
336 334 end
337 335 end
338 336 if unsaved_issue_ids.empty?
339 337 flash[:notice] = l(:notice_successful_update) unless @issues.empty?
340 338 else
341 339 flash[:error] = l(:notice_failed_to_save_issues, :count => unsaved_issue_ids.size,
342 340 :total => @issues.size,
343 341 :ids => '#' + unsaved_issue_ids.join(', #'))
344 342 end
345 343 if params[:follow]
346 344 if @issues.size == 1 && moved_issues.size == 1
347 345 redirect_to :controller => 'issues', :action => 'show', :id => moved_issues.first
348 346 else
349 347 redirect_to :controller => 'issues', :action => 'index', :project_id => (@target_project || @project)
350 348 end
351 349 else
352 350 redirect_to :controller => 'issues', :action => 'index', :project_id => @project
353 351 end
354 352 return
355 353 end
356 354 render :layout => false if request.xhr?
357 355 end
358 356
359 357 def destroy
360 358 @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
361 359 if @hours > 0
362 360 case params[:todo]
363 361 when 'destroy'
364 362 # nothing to do
365 363 when 'nullify'
366 364 TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues])
367 365 when 'reassign'
368 366 reassign_to = @project.issues.find_by_id(params[:reassign_to_id])
369 367 if reassign_to.nil?
370 368 flash.now[:error] = l(:error_issue_not_found_in_project)
371 369 return
372 370 else
373 371 TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues])
374 372 end
375 373 else
376 374 unless params[:format] == 'xml'
377 375 # display the destroy form if it's a user request
378 376 return
379 377 end
380 378 end
381 379 end
382 380 @issues.each(&:destroy)
383 381 respond_to do |format|
384 382 format.html { redirect_to :action => 'index', :project_id => @project }
385 383 format.xml { head :ok }
386 384 end
387 385 end
388 386
389 387 def gantt
390 388 @gantt = Redmine::Helpers::Gantt.new(params)
391 389 retrieve_query
392 390 if @query.valid?
393 391 events = []
394 392 # Issues that have start and due dates
395 393 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
396 394 :order => "start_date, due_date",
397 395 :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
398 396 )
399 397 # Issues that don't have a due date but that are assigned to a version with a date
400 398 events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version],
401 399 :order => "start_date, effective_date",
402 400 :conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
403 401 )
404 402 # Versions
405 403 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to])
406 404
407 405 @gantt.events = events
408 406 end
409 407
410 408 basename = (@project ? "#{@project.identifier}-" : '') + 'gantt'
411 409
412 410 respond_to do |format|
413 411 format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
414 412 format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image')
415 413 format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") }
416 414 end
417 415 end
418 416
419 417 def calendar
420 418 if params[:year] and params[:year].to_i > 1900
421 419 @year = params[:year].to_i
422 420 if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13
423 421 @month = params[:month].to_i
424 422 end
425 423 end
426 424 @year ||= Date.today.year
427 425 @month ||= Date.today.month
428 426
429 427 @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
430 428 retrieve_query
431 429 if @query.valid?
432 430 events = []
433 431 events += @query.issues(:include => [:tracker, :assigned_to, :priority],
434 432 :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
435 433 )
436 434 events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt])
437 435
438 436 @calendar.events = events
439 437 end
440 438
441 439 render :layout => false if request.xhr?
442 440 end
443 441
444 442 def context_menu
445 443 @issues = Issue.find_all_by_id(params[:ids], :include => :project)
446 444 if (@issues.size == 1)
447 445 @issue = @issues.first
448 446 @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
449 447 end
450 448 projects = @issues.collect(&:project).compact.uniq
451 449 @project = projects.first if projects.size == 1
452 450
453 451 @can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
454 452 :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
455 453 :update => (@project && (User.current.allowed_to?(:edit_issues, @project) || (User.current.allowed_to?(:change_status, @project) && @allowed_statuses && !@allowed_statuses.empty?))),
456 454 :move => (@project && User.current.allowed_to?(:move_issues, @project)),
457 455 :copy => (@issue && @project.trackers.include?(@issue.tracker) && User.current.allowed_to?(:add_issues, @project)),
458 456 :delete => (@project && User.current.allowed_to?(:delete_issues, @project))
459 457 }
460 458 if @project
461 459 @assignables = @project.assignable_users
462 460 @assignables << @issue.assigned_to if @issue && @issue.assigned_to && !@assignables.include?(@issue.assigned_to)
463 461 @trackers = @project.trackers
464 462 end
465 463
466 464 @priorities = IssuePriority.all.reverse
467 465 @statuses = IssueStatus.find(:all, :order => 'position')
468 466 @back = params[:back_url] || request.env['HTTP_REFERER']
469 467
470 468 render :layout => false
471 469 end
472 470
473 471 def update_form
474 472 if params[:id].blank?
475 473 @issue = Issue.new
476 474 @issue.project = @project
477 475 else
478 476 @issue = @project.issues.visible.find(params[:id])
479 477 end
480 478 @issue.attributes = params[:issue]
481 479 @allowed_statuses = ([@issue.status] + @issue.status.find_new_statuses_allowed_to(User.current.roles_for_project(@project), @issue.tracker)).uniq
482 480 @priorities = IssuePriority.all
483 481
484 482 render :partial => 'attributes'
485 483 end
486 484
487 485 def preview
488 486 @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
489 487 @attachements = @issue.attachments if @issue
490 488 @text = params[:notes] || (params[:issue] ? params[:issue][:description] : nil)
491 489 render :partial => 'common/preview'
492 490 end
493 491
494 492 private
495 493 def find_issue
496 494 @issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
497 495 @project = @issue.project
498 496 rescue ActiveRecord::RecordNotFound
499 497 render_404
500 498 end
501 499
502 500 # Filter for bulk operations
503 501 def find_issues
504 502 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
505 503 raise ActiveRecord::RecordNotFound if @issues.empty?
506 504 projects = @issues.collect(&:project).compact.uniq
507 505 if projects.size == 1
508 506 @project = projects.first
509 507 else
510 508 # TODO: let users bulk edit/move/destroy issues from different projects
511 509 render_error 'Can not bulk edit/move/destroy issues from different projects'
512 510 return false
513 511 end
514 512 rescue ActiveRecord::RecordNotFound
515 513 render_404
516 514 end
517 515
518 516 def find_project
519 517 project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
520 518 @project = Project.find(project_id)
521 519 rescue ActiveRecord::RecordNotFound
522 520 render_404
523 521 end
524 522
525 523 def find_optional_project
526 524 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
527 525 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
528 526 allowed ? true : deny_access
529 527 rescue ActiveRecord::RecordNotFound
530 528 render_404
531 529 end
532 530
533 531 # Retrieve query from session or build a new query
534 532 def retrieve_query
535 533 if !params[:query_id].blank?
536 534 cond = "project_id IS NULL"
537 535 cond << " OR project_id = #{@project.id}" if @project
538 536 @query = Query.find(params[:query_id], :conditions => cond)
539 537 @query.project = @project
540 538 session[:query] = {:id => @query.id, :project_id => @query.project_id}
541 539 sort_clear
542 540 else
543 541 if api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (@project ? @project.id : nil)
544 542 # Give it a name, required to be valid
545 543 @query = Query.new(:name => "_")
546 544 @query.project = @project
547 545 if params[:fields] and params[:fields].is_a? Array
548 546 params[:fields].each do |field|
549 547 @query.add_filter(field, params[:operators][field], params[:values][field])
550 548 end
551 549 else
552 550 @query.available_filters.keys.each do |field|
553 551 @query.add_short_filter(field, params[field]) if params[field]
554 552 end
555 553 end
556 554 @query.group_by = params[:group_by]
557 555 @query.column_names = params[:query] && params[:query][:column_names]
558 556 session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
559 557 else
560 558 @query = Query.find_by_id(session[:query][:id]) if session[:query][:id]
561 559 @query ||= Query.new(:name => "_", :project => @project, :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
562 560 @query.project = @project
563 561 end
564 562 end
565 563 end
566 564
567 565 # Rescues an invalid query statement. Just in case...
568 566 def query_statement_invalid(exception)
569 567 logger.error "Query::StatementInvalid: #{exception.message}" if logger
570 568 session.delete(:query)
571 569 sort_clear
572 570 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
573 571 end
574 572 end
General Comments 0
You need to be logged in to leave comments. Login now