Commit 55f802bd3a7840f20eab1f8be550a7fac97b961e
Exists in
master
and in
21 other branches
Merge branch 'api' of gitlab.com:noosfero/noosfero into api
Showing
2 changed files
with
22 additions
and
2 deletions
Show diff stats
app/models/person.rb
@@ -40,9 +40,14 @@ roles] } | @@ -40,9 +40,14 @@ roles] } | ||
40 | } | 40 | } |
41 | 41 | ||
42 | scope :visible_for_person, lambda { |person| | 42 | scope :visible_for_person, lambda { |person| |
43 | - joins('LEFT JOIN "friendships" ON "friendships"."friend_id" = "profiles"."id"') | 43 | + joins('LEFT JOIN "role_assignments" ON |
44 | + "role_assignments"."resource_id" = "profiles"."environment_id" AND | ||
45 | + "role_assignments"."resource_type" = \'Environment\'') | ||
46 | + .joins('LEFT JOIN "roles" ON "role_assignments"."role_id" = "roles"."id"') | ||
47 | + .joins('LEFT JOIN "friendships" ON "friendships"."friend_id" = "profiles"."id"') | ||
44 | .where( | 48 | .where( |
45 | - ['( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?)', person.id, true, true] | 49 | + ['( roles.key = ? AND role_assignments.accessor_type = ? AND role_assignments.accessor_id = ? ) OR ( |
50 | + ( ( friendships.person_id = ? ) OR (profiles.public_profile = ?)) AND (profiles.visible = ?) )', 'environment_administrator', Profile.name, person.id, person.id, true, true] | ||
46 | ).uniq | 51 | ).uniq |
47 | } | 52 | } |
48 | 53 |
test/unit/person_test.rb
@@ -1663,6 +1663,9 @@ class PersonTest < ActiveSupport::TestCase | @@ -1663,6 +1663,9 @@ class PersonTest < ActiveSupport::TestCase | ||
1663 | 1663 | ||
1664 | should 'fetch people there are visible for a user' do | 1664 | should 'fetch people there are visible for a user' do |
1665 | person = create_user('some-person').person | 1665 | person = create_user('some-person').person |
1666 | + admin = create_user('some-admin').person | ||
1667 | + Environment.default.add_admin(admin) | ||
1668 | + | ||
1666 | p1 = fast_create(Person, :public_profile => true , :visible => true ) | 1669 | p1 = fast_create(Person, :public_profile => true , :visible => true ) |
1667 | p1.add_friend(person) | 1670 | p1.add_friend(person) |
1668 | p2 = fast_create(Person, :public_profile => true , :visible => true ) | 1671 | p2 = fast_create(Person, :public_profile => true , :visible => true ) |
@@ -1674,13 +1677,25 @@ class PersonTest < ActiveSupport::TestCase | @@ -1674,13 +1677,25 @@ class PersonTest < ActiveSupport::TestCase | ||
1674 | p6 = fast_create(Person, :public_profile => false, :visible => false) | 1677 | p6 = fast_create(Person, :public_profile => false, :visible => false) |
1675 | 1678 | ||
1676 | people = Person.visible_for_person(person) | 1679 | people = Person.visible_for_person(person) |
1680 | + people_for_admin = Person.visible_for_person(admin) | ||
1677 | 1681 | ||
1678 | assert_includes people, p1 | 1682 | assert_includes people, p1 |
1683 | + assert_includes people_for_admin, p1 | ||
1684 | + | ||
1679 | assert_includes people, p2 | 1685 | assert_includes people, p2 |
1686 | + assert_includes people_for_admin, p2 | ||
1687 | + | ||
1680 | assert_not_includes people, p3 | 1688 | assert_not_includes people, p3 |
1689 | + assert_includes people_for_admin, p3 | ||
1690 | + | ||
1681 | assert_includes people, p4 | 1691 | assert_includes people, p4 |
1692 | + assert_includes people_for_admin, p4 | ||
1693 | + | ||
1682 | assert_not_includes people, p5 | 1694 | assert_not_includes people, p5 |
1695 | + assert_includes people_for_admin, p5 | ||
1696 | + | ||
1683 | assert_not_includes people, p6 | 1697 | assert_not_includes people, p6 |
1698 | + assert_includes people_for_admin, p6 | ||
1684 | end | 1699 | end |
1685 | 1700 | ||
1686 | should 'vote in a comment with value greater than 1' do | 1701 | should 'vote in a comment with value greater than 1' do |