diff --git a/app/models/person.rb b/app/models/person.rb index 5d3da0e..b15f1da 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -5,7 +5,11 @@ class Person < Profile acts_as_accessor acts_as_having_hotspots - named_scope :members_of, lambda { |resource| { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ['role_assignments.resource_type = ? AND role_assignments.resource_id = ?', resource.class.base_class.name, resource.id ] } } + named_scope :members_of, lambda { |resources| + resources = [resources] if !resources.kind_of?(Array) + conditions = resources.map {|resource| "role_assignments.resource_type = '#{resource.class.base_class.name}' AND role_assignments.resource_id = #{resource.id || -1}"}.join(' OR ') + { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => [conditions] } + } def has_permission_with_plugins?(permission, profile) permissions = [has_permission_without_plugins?(permission, profile)] diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index b2923d9..1597587 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1151,6 +1151,18 @@ class PersonTest < ActiveSupport::TestCase assert_equal [person], Person.members_of(community) end + should 'be able to pass array to members_of' do + person1 = fast_create(Person) + community = fast_create(Community) + community.add_member(person1) + person2 = fast_create(Person) + enterprise = fast_create(Enterprise) + enterprise.add_member(person2) + + assert_includes Person.members_of([community, enterprise]), person1 + assert_includes Person.members_of([community, enterprise]), person2 + end + should 'find more active people' do Person.destroy_all p1 = fast_create(Person) -- libgit2 0.21.2