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