Commit 41af608f407597509b041efc3caef6604a26e386
Committed by
Gabriela Navarro
1 parent
a6151343
Exists in
master
and in
29 other branches
Add privacy of block only to members in organizations and only to friends in person.
Signed-off-by: Álvaro Fernando <alvarofernandoms@gmail.com> Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Hebert Douglas <hebertdougl@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
2 changed files
with
48 additions
and
1 deletions
Show diff stats
app/models/block.rb
| @@ -64,7 +64,7 @@ class Block < ActiveRecord::Base | @@ -64,7 +64,7 @@ class Block < ActiveRecord::Base | ||
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | def display_to_user?(user) | 66 | def display_to_user?(user) |
| 67 | - display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged') | 67 | + display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged') || (user && display_user == 'followers' && user.follows?(owner)) |
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | def display_always(context) | 70 | def display_always(context) |
| @@ -224,6 +224,7 @@ class Block < ActiveRecord::Base | @@ -224,6 +224,7 @@ class Block < ActiveRecord::Base | ||
| 224 | 'all' => _('All users'), | 224 | 'all' => _('All users'), |
| 225 | 'logged' => _('Logged'), | 225 | 'logged' => _('Logged'), |
| 226 | 'not_logged' => _('Not logged'), | 226 | 'not_logged' => _('Not logged'), |
| 227 | + 'followers' => owner.organization? ? _('Members') : _('Friends') | ||
| 227 | } | 228 | } |
| 228 | end | 229 | end |
| 229 | 230 |
test/unit/block_test.rb
| @@ -284,4 +284,50 @@ class BlockTest < ActiveSupport::TestCase | @@ -284,4 +284,50 @@ class BlockTest < ActiveSupport::TestCase | ||
| 284 | assert_equal block.cache_key('en'), block.cache_key('en', person) | 284 | assert_equal block.cache_key('en'), block.cache_key('en', person) |
| 285 | end | 285 | end |
| 286 | 286 | ||
| 287 | + should 'display block to members of community for display_user = members' do | ||
| 288 | + community = fast_create(Community) | ||
| 289 | + user = create_user('testinguser') | ||
| 290 | + community.add_member(user.person) | ||
| 291 | + | ||
| 292 | + box = fast_create(Box, :owner_id => community.id, :owner_type => 'Community') | ||
| 293 | + block = create(Block, :box_id => box.id) | ||
| 294 | + block.display_user = 'followers' | ||
| 295 | + block.save! | ||
| 296 | + assert block.display_to_user?(user.person) | ||
| 297 | + end | ||
| 298 | + | ||
| 299 | + should 'do not display block to non members of community for display_user = members' do | ||
| 300 | + community = fast_create(Community) | ||
| 301 | + user = create_user('testinguser') | ||
| 302 | + | ||
| 303 | + box = fast_create(Box, :owner_id => community.id, :owner_type => 'Community') | ||
| 304 | + block = create(Block, :box_id => box.id) | ||
| 305 | + block.display_user = 'followers' | ||
| 306 | + block.save! | ||
| 307 | + assert !block.display_to_user?(user.person) | ||
| 308 | + end | ||
| 309 | + | ||
| 310 | + should 'display block to friends of person for display_user = friends' do | ||
| 311 | + person = create_user('person_one').person | ||
| 312 | + person_friend = create_user('person_friend').person | ||
| 313 | + | ||
| 314 | + person.add_friend(person_friend) | ||
| 315 | + | ||
| 316 | + box = fast_create(Box, :owner_id => person.id, :owner_type => 'Person') | ||
| 317 | + block = create(Block, :box_id => box.id) | ||
| 318 | + block.display_user = 'followers' | ||
| 319 | + block.save! | ||
| 320 | + assert block.display_to_user?(person_friend) | ||
| 321 | + end | ||
| 322 | + | ||
| 323 | + should 'do not display block to non friends of person for display_user = friends' do | ||
| 324 | + person = create_user('person_one').person | ||
| 325 | + person_friend = create_user('person_friend').person | ||
| 326 | + | ||
| 327 | + box = fast_create(Box, :owner_id => person.id, :owner_type => 'Person') | ||
| 328 | + block = create(Block, :box_id => box.id) | ||
| 329 | + block.display_user = 'followers' | ||
| 330 | + block.save! | ||
| 331 | + assert !block.display_to_user?(person_friend) | ||
| 332 | + end | ||
| 287 | end | 333 | end |