Project

General

Profile

Defect #26023 » 26023.patch

Felix Schäfer, 2017-05-23 13:13

View differences:

app/models/issue_category.rb
29 29
  safe_attributes 'name', 'assigned_to_id'
30 30

  
31 31
  scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)}
32
  scope :visible, lambda {|*args|
33
    joins(:project).
34
    where(Project.allowed_to_condition(args.first || User.current, :view_issues))
35
  }
32 36

  
33 37
  alias :destroy_without_reassign :destroy
34 38

  
app/models/issue_query.rb
124 124

  
125 125
    add_available_filter "category_id",
126 126
      :type => :list_optional,
127
      :values => lambda { project.issue_categories.collect{|s| [s.name, s.id.to_s] } } if project
127
      :values => lambda { issue_category_values }
128 128

  
129 129
    add_available_filter "subject", :type => :text
130 130
    add_available_filter "description", :type => :text
app/models/project.rb
323 323
    @users = nil
324 324
    @shared_versions = nil
325 325
    @rolled_up_versions = nil
326
    @rolled_up_issue_categories = nil
326 327
    @rolled_up_trackers = nil
327 328
    @rolled_up_custom_fields = nil
328 329
    @all_issue_custom_fields = nil
......
471 472
        where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
472 473
  end
473 474

  
475
  def rolled_up_issue_categories
476
    @rolled_up_issue_categories ||=
477
      IssueCategory.
478
        joins(:project).
479
        where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED)
480
  end
481

  
474 482
  # Returns a scope of the Versions used by the project
475 483
  def shared_versions
476 484
    if new_record?
app/models/query.rb
551 551
    Version.sort_by_status(versions).collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")] }
552 552
  end
553 553

  
554
  def issue_category_values
555
    categories = []
556
    if project
557
      categories = project.rolled_up_issue_categories.to_a
558
    else
559
      categories = IssueCategory.visible.to_a
560
    end
561
    categories.collect {|c| [c.name, c.id.to_s] }
562
  end
563

  
554 564
  # Returns a scope of issue custom fields that are available as columns or filters
555 565
  def issue_custom_fields
556 566
    if project
(1-1/5)