Commit a6aca8e122e9b8af60d5262591a9b41ccd2a3de4
Exists in
staging
and in
42 other branches
Merge branch 'block_permission' into 'master'
Block permission Add privacy of block only to members in a community Add privacy of block only to friends in person. The privacies were added in the block edition. See merge request !418
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 |