Project

General

Profile

Feature #11069 » patch_for_locked_users_query.diff

Ksenia Altbregen, 2013-09-10 13:57

View differences:

app/models/principal.rb (revision 1241)
31 31

  
32 32
  # Groups and active users
33 33
  scope :active, lambda { where(:status => STATUS_ACTIVE) }
34
  # Locked users
35
  scope :locked, lambda { where(:status => STATUS_LOCKED) }
34 36

  
35 37
  scope :like, lambda {|q|
36 38
    q = q.to_s
......
60 62
      active.uniq.joins(:members).where("#{Member.table_name}.project_id IN (?)", ids)
61 63
    end
62 64
  }
65
  # Principals that are locked members of a collection of projects
66
  scope :locked_member_of, lambda {|projects|
67
    projects = [projects] unless projects.is_a?(Array)
68
    if projects.empty?
69
      where("1=0")
70
    else
71
      ids = projects.map(&:id)
72
      locked.uniq.joins(:members).where("#{Member.table_name}.project_id IN (?)", ids)
73
    end
74
  }
63 75
  # Principals that are not members of projects
64 76
  scope :not_member_of, lambda {|projects|
65 77
    projects = [projects] unless projects.is_a?(Array)
app/models/issue_query.rb (revision 1241)
70 70
    issue_custom_fields = []
71 71
    
72 72
    if project
73
      principals += project.principals.sort
73
      principals += project.principals
74
      principals += project.locked_principals
75
      principals.sort
74 76
      unless project.leaf?
75 77
        subprojects = project.descendants.visible.all
76 78
        principals += Principal.member_of(subprojects)
79
        principals += Principal.locked_member_of(subprojects)
77 80
      end
78 81
      versions = project.shared_versions.all
79 82
      categories = project.issue_categories.all
......
82 85
    else
83 86
      if all_projects.any?
84 87
        principals += Principal.member_of(all_projects)
88
        principals += Principal.locked_member_of(all_projects)
85 89
      end
86 90
      versions = Version.visible.find_all_by_sharing('system')
87 91
      issue_custom_fields = IssueCustomField.where(:is_filter => true, :is_for_all => true).all
app/models/project.rb (revision 1241)
33 33
  has_many :member_principals, :class_name => 'Member',
34 34
                               :include => :principal,
35 35
                               :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
36
  has_many :locked_member_principals, :class_name => 'Member',
37
                                      :include => :principal,
38
                                      :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_LOCKED})"
36 39
  has_many :users, :through => :members
37 40
  has_many :principals, :through => :member_principals, :source => :principal
41
  has_many :locked_principals, :through => :locked_member_principals, :source => :principal
38 42

  
39 43
  has_many :enabled_modules, :dependent => :delete_all
40 44
  has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
(2-2/2)