Skip to content

Commit

Permalink
Change is_public logic
Browse files Browse the repository at this point in the history
Previously, Universe privacy was checked first. If it was private, then
any content within it was private. If it was public, only then would
the content's privacy be checked.

Now, both values are checked in an OR comparison. If either the universe
or content privacy is "public," then the content is public.
  • Loading branch information
Cantido committed Sep 22, 2016
1 parent bb9edc1 commit 8706cf9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/has_privacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def private_content?
end

def public_content?
in_private_universe = respond_to?(:universe) && universe.present? && universe.private_content?
privacy == 'public' && !in_private_universe
universe_is_public = respond_to?(:universe) && universe.present? && universe.public_content?
privacy == 'public' || universe_is_public
end
end
end
2 changes: 1 addition & 1 deletion app/views/content/_share.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>

<div class="row">
<p class="col s12">To be shareable, content must be <b>public</b>, and in a <b>public</b> Universe.</p>
<p class="col s12">To be shareable, content must be <b>public</b> <em>or</em> in a <b>public</b> Universe.</p>
</div>

<% if ((shared_content.respond_to? :universe) && shared_content.universe.present?) %>
Expand Down
14 changes: 7 additions & 7 deletions test/models/character_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class CharacterTest < ActiveSupport::TestCase
end

test 'character is public when privacy field contains "public"' do
universe = build(:universe, privacy: 'public')
universe = build(:universe, privacy: 'private')
character = build(:character, privacy: 'public', universe: universe)

assert character.public_content?
refute character.private_content?
end

test 'character is private when privacy field contains "private"' do
universe = build(:universe, privacy: 'public')
universe = build(:universe, privacy: 'private')
character = build(:character, privacy: 'private', universe: universe)

assert character.private_content?
Expand All @@ -31,11 +31,11 @@ class CharacterTest < ActiveSupport::TestCase
refute character.public_content?
end

test 'character is private when universe is private' do
universe = build(:universe, privacy: 'private')
character = build(:character, privacy: 'public', universe: universe)
test 'character is public when universe is public' do
universe = build(:universe, privacy: 'public')
character = build(:character, privacy: 'private', universe: universe)

assert character.private_content?
refute character.public_content?
assert character.public_content?
refute character.private_content?
end
end

0 comments on commit 8706cf9

Please sign in to comment.