diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/member.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index c2a36b780..5dd04cc71 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -29,6 +29,8 @@ class Member < ActiveRecord::Base before_destroy :set_issue_category_nil + scope :active, lambda { joins(:principal).where(:users => {:status => Principal::STATUS_ACTIVE})} + alias :base_reload :reload def reload(*args) @managed_roles = nil diff --git a/app/models/project.rb b/app/models/project.rb index 05a5fa2e7..7c4ac3516 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -29,14 +29,10 @@ class Project < ActiveRecord::Base # Specific overridden Activities has_many :time_entry_activities + has_many :memberships, :class_name => 'Member', :inverse_of => :project + # Memberships of active users only has_many :members, - lambda { joins(:principal, :roles). - where("#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}") } - has_many :memberships, :class_name => 'Member' - has_many :member_principals, - lambda { joins(:principal). - where("#{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}")}, - :class_name => 'Member' + lambda { joins(:principal).where(:users => {:type => 'User', :status => Principal::STATUS_ACTIVE}) } has_many :enabled_modules, :dependent => :delete_all has_and_belongs_to_many :trackers, lambda {order(:position)} has_many :issues, :dependent => :destroy @@ -216,8 +212,9 @@ class Project < ActiveRecord::Base end def override_roles(role) - @override_members ||= member_principals. - where("#{Principal.table_name}.type IN (?)", ['GroupAnonymous', 'GroupNonMember']).to_a + @override_members ||= memberships. + joins(:principal). + where(:users => {:type => ['GroupAnonymous', 'GroupNonMember']}).to_a group_class = role.anonymous? ? GroupAnonymous : GroupNonMember member = @override_members.detect {|m| m.principal.is_a? group_class} @@ -739,6 +736,11 @@ class Project < ActiveRecord::Base end end + def member_principals + ActiveSupport::Deprecation.warn "Project#member_principals is deprecated and will be removed in Redmine 4.0. Use #memberships.active instead." + memberships.active + end + # Returns a new unsaved Project instance with attributes copied from +project+ def self.copy_from(project) project = project.is_a?(Project) ? project : Project.find(project) |