]> source.dussan.org Git - redmine.git/commitdiff
Deprecates Project#member_principals.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 18 Jun 2015 19:12:17 +0000 (19:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 18 Jun 2015 19:12:17 +0000 (19:12 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14332 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/members_controller.rb
app/models/member.rb
app/models/project.rb
app/views/projects/settings/_members.html.erb
test/unit/principal_test.rb

index 5e5bee8223bc258317497ca6f7d45aeb423bdac0..0f1f53f8e1dfb1e693ce5dcfa85c6d693dee1a9e 100644 (file)
@@ -24,15 +24,13 @@ class MembersController < ApplicationController
   accept_api_auth :index, :show, :create, :update, :destroy
 
   def index
+    scope = @project.memberships.active
     @offset, @limit = api_offset_and_limit
-    @member_count = @project.member_principals.count
+    @member_count = scope.count
     @member_pages = Paginator.new @member_count, @limit, params['page']
     @offset ||= @member_pages.offset
-    @members =  @project.member_principals.
-                    order("#{Member.table_name}.id").
-                    limit(@limit).
-                    offset(@offset).
-                    to_a
+    @members =  scope.order(:id).limit(@limit).offset(@offset).to_a
+
     respond_to do |format|
       format.html { head 406 }
       format.api
index c2a36b7803d1621a29eadd1f0ffb29ab81615a86..5dd04cc716dc5a060514e7dcb39fe67d81987d0d 100644 (file)
@@ -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
index 05a5fa2e779a817269a685da6eec8a36618f84d9..7c4ac351663b1e23bff234101aff3e0ba43ee728 100644 (file)
@@ -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)
index c9a91e3b1b4e25050d6bf64ca8f7f5ac47408fab..31415f80e1d2e3d8bd986082717a51870e49aa24 100644 (file)
@@ -1,5 +1,5 @@
 <% roles = Role.find_all_givable
-   members = @project.member_principals.includes(:member_roles, :roles, :principal).to_a.sort %>
+   members = @project.memberships.active.includes(:member_roles, :roles, :principal).to_a.sort %>
 
 <p><%= link_to l(:label_member_new), new_project_membership_path(@project), :remote => true, :class => "icon icon-add" %></p>
 
index fd8b4009ff29c169f816bb543fd65d232410ada9..b05f8950ba9c810b5a97f7b71bbc974259df214d 100644 (file)
@@ -48,7 +48,7 @@ class PrincipalTest < ActiveSupport::TestCase
     Role.non_member.update! :users_visibility => 'members_of_visible_projects'
     user = User.generate!
 
-    expected = Project.visible(user).map(&:member_principals).flatten.map(&:principal).uniq << user
+    expected = Project.visible(user).map {|p| p.memberships.active}.flatten.map(&:principal).uniq << user
     assert_equal expected.map(&:id).sort, Principal.visible(user).pluck(:id).sort
   end