diff --git a/app/models/profile.rb b/app/models/profile.rb index c6805c2..4f412dc 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -145,6 +145,14 @@ class Profile < ActiveRecord::Base scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } scope :enabled, :conditions => { :enabled => true } + scope :visible_for_person, lambda { |person| + joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'') + .where( + ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR + (profiles.public_profile = ?) )', Profile.name, person.id, true] + ) + } + # Subclasses must override this method scope :more_popular diff --git a/lib/api/v1/communities.rb b/lib/api/v1/communities.rb index 9cefe98..c18f10d 100644 --- a/lib/api/v1/communities.rb +++ b/lib/api/v1/communities.rb @@ -17,7 +17,7 @@ module API # GET /communities?reference_id=10&limit=10&oldest get do communities = select_filtered_collection_of(environment, 'communities', params) - communities = communities.visible + communities = communities.visible_for_person(current_person) present communities, :with => Entities::Community end diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index 9ac17cf..771d604 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -7,7 +7,7 @@ class CommunitiesTest < ActiveSupport::TestCase end should 'list all communities' do - community1 = fast_create(Community) + community1 = fast_create(Community, :public_profile => true) community2 = fast_create(Community) get "/api/v1/communities?#{params.to_query}" json = JSON.parse(last_response.body) -- libgit2 0.21.2