diff --git a/app/models/organization.rb b/app/models/organization.rb index 18be960..afaf658 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -16,7 +16,7 @@ class Organization < Profile # visible. # 4) The user is not a member of the organization but the organization is # visible, public and enabled. - scope :visible_for_person, lambda { |person| + def self.visible_for_person(person) joins('LEFT JOIN "role_assignments" ON ("role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\') OR ( "role_assignments"."resource_id" = "profiles"."environment_id" AND @@ -31,7 +31,7 @@ class Organization < Profile 'profile_admin', 'environment_administrator', Profile.name, person.id, Profile.name, person.id, true, true, true] ).uniq - } + end settings_items :closed, :type => :boolean, :default => false def closed? diff --git a/test/unit/api/communities_test.rb b/test/unit/api/communities_test.rb index 1bdd9b0..a65ae8b 100644 --- a/test/unit/api/communities_test.rb +++ b/test/unit/api/communities_test.rb @@ -7,6 +7,15 @@ class CommunitiesTest < ActiveSupport::TestCase login_api end + should 'list only communities' do + community = fast_create(Community) + enterprise = fast_create(Enterprise) # should not list this enterprise + get "/api/v1/communities?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_not_includes json['communities'].map {|c| c['id']}, enterprise.id + assert_includes json['communities'].map {|c| c['id']}, community.id + end + should 'list all communities' do community1 = fast_create(Community, :public_profile => true) community2 = fast_create(Community) diff --git a/test/unit/api/enterprises_test.rb b/test/unit/api/enterprises_test.rb index f90c968..3774d0a 100644 --- a/test/unit/api/enterprises_test.rb +++ b/test/unit/api/enterprises_test.rb @@ -7,6 +7,15 @@ class EnterprisesTest < ActiveSupport::TestCase login_api end + should 'list only enterprises' do + community = fast_create(Community) # should not list this community + enterprise = fast_create(Enterprise, :public_profile => true) + get "/api/v1/enterprises?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id + assert_not_includes json['enterprises'].map {|c| c['id']}, community.id + end + should 'list all enterprises' do enterprise1 = fast_create(Enterprise, :public_profile => true) enterprise2 = fast_create(Enterprise) -- libgit2 0.21.2