Commit 33871f095597ec2f0413456f8116e2647e04ff45
1 parent
3bd78a8f
Exists in
staging
and in
4 other branches
adding named scope visible_for_person
Showing
3 changed files
with
10 additions
and
2 deletions
Show diff stats
app/models/profile.rb
@@ -134,6 +134,14 @@ class Profile < ActiveRecord::Base | @@ -134,6 +134,14 @@ class Profile < ActiveRecord::Base | ||
134 | scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } | 134 | scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } |
135 | scope :enabled, :conditions => { :enabled => true } | 135 | scope :enabled, :conditions => { :enabled => true } |
136 | 136 | ||
137 | + scope :visible_for_person, lambda { |person| | ||
138 | + joins('LEFT JOIN "role_assignments" ON "role_assignments"."resource_id" = "profiles"."id" AND "role_assignments"."resource_type" = \'Profile\'') | ||
139 | + .where( | ||
140 | + ['( ( role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR | ||
141 | + (profiles.public_profile = ?) )', Profile.name, person.id, true] | ||
142 | + ) | ||
143 | + } | ||
144 | + | ||
137 | # Subclasses must override this method | 145 | # Subclasses must override this method |
138 | scope :more_popular | 146 | scope :more_popular |
139 | 147 |
lib/api/v1/communities.rb
@@ -17,7 +17,7 @@ module API | @@ -17,7 +17,7 @@ module API | ||
17 | # GET /communities?reference_id=10&limit=10&oldest | 17 | # GET /communities?reference_id=10&limit=10&oldest |
18 | get do | 18 | get do |
19 | communities = select_filtered_collection_of(environment, 'communities', params) | 19 | communities = select_filtered_collection_of(environment, 'communities', params) |
20 | - communities = communities.visible | 20 | + communities = communities.visible_for_person(current_person) |
21 | present communities, :with => Entities::Community | 21 | present communities, :with => Entities::Community |
22 | end | 22 | end |
23 | 23 |
test/unit/api/communities_test.rb
@@ -7,7 +7,7 @@ class CommunitiesTest < ActiveSupport::TestCase | @@ -7,7 +7,7 @@ class CommunitiesTest < ActiveSupport::TestCase | ||
7 | end | 7 | end |
8 | 8 | ||
9 | should 'list all communities' do | 9 | should 'list all communities' do |
10 | - community1 = fast_create(Community) | 10 | + community1 = fast_create(Community, :public_profile => true) |
11 | community2 = fast_create(Community) | 11 | community2 = fast_create(Community) |
12 | get "/api/v1/communities?#{params.to_query}" | 12 | get "/api/v1/communities?#{params.to_query}" |
13 | json = JSON.parse(last_response.body) | 13 | json = JSON.parse(last_response.body) |