Commit 497160239c025f98c5f855a8c9f3d5b45c5c4937
Committed by
Arthur Esposte
1 parent
cf00ed96
Exists in
master
and in
22 other branches
Add Secret type to communities' privacy options
- created 'secret' attribute for profiles - redefined scope for secret communities Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Álvaro Fernando <alvarofernandoms@gmail.com> Signed-off-by: Dylan Guedes <djmgguedes@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Filipe Ribeiro <firibeiro77@live.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
7 changed files
with
126 additions
and
11 deletions
Show diff stats
app/models/profile.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :email_suggestions, :allow_members_to_invite, :invite_friends_only | 6 | + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret |
7 | 7 | ||
8 | # use for internationalizable human type names in search facets | 8 | # use for internationalizable human type names in search facets |
9 | # reimplement on subclasses | 9 | # reimplement on subclasses |
@@ -119,9 +119,9 @@ class Profile < ActiveRecord::Base | @@ -119,9 +119,9 @@ class Profile < ActiveRecord::Base | ||
119 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') | 119 | Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') |
120 | end | 120 | end |
121 | 121 | ||
122 | - scope :visible, :conditions => { :visible => true } | 122 | + scope :visible, :conditions => { :visible => true, :secret => false } |
123 | scope :disabled, :conditions => { :visible => false } | 123 | scope :disabled, :conditions => { :visible => false } |
124 | - scope :public, :conditions => { :visible => true, :public_profile => true } | 124 | + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } |
125 | scope :enabled, :conditions => { :enabled => true } | 125 | scope :enabled, :conditions => { :enabled => true } |
126 | 126 | ||
127 | # Subclasses must override this method | 127 | # Subclasses must override this method |
app/views/profile_editor/edit.html.erb
@@ -34,10 +34,13 @@ | @@ -34,10 +34,13 @@ | ||
34 | </div> | 34 | </div> |
35 | <% else %> | 35 | <% else %> |
36 | <div> | 36 | <div> |
37 | - <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> | 37 | + <%= labelled_check_box _("Secret — hide the community and all its contents for non members and other people can't join this community unless they are invited to."), 'profile_data[secret]', true, profile.secret, :class => "profile-secret-box" %> |
38 | </div> | 38 | </div> |
39 | <div> | 39 | <div> |
40 | - <%= labelled_radio_button _('Private — show content of this group only to members'), 'profile_data[public_profile]', false, !@profile.public_profile? %> | 40 | + <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile?, :class => "public-community-button" %> |
41 | + </div> | ||
42 | + <div> | ||
43 | + <%= labelled_radio_button _('Private — show content of this group only to members'), 'profile_data[public_profile]', false, !@profile.public_profile?, :class => "private-community-button" %> | ||
41 | </div> | 44 | </div> |
42 | <% end %> | 45 | <% end %> |
43 | 46 | ||
@@ -85,4 +88,6 @@ | @@ -85,4 +88,6 @@ | ||
85 | <% end %> | 88 | <% end %> |
86 | <% end %> | 89 | <% end %> |
87 | <% end %> | 90 | <% end %> |
88 | -<% end %> | ||
89 | \ No newline at end of file | 91 | \ No newline at end of file |
92 | +<% end %> | ||
93 | + | ||
94 | +<%= javascript_include_tag 'profile_editor' %> |
db/schema.rb
@@ -11,7 +11,7 @@ | @@ -11,7 +11,7 @@ | ||
11 | # | 11 | # |
12 | # It's strongly recommended to check this file into your version control system. | 12 | # It's strongly recommended to check this file into your version control system. |
13 | 13 | ||
14 | -ActiveRecord::Schema.define(:version => 20150122165042) do | 14 | +ActiveRecord::Schema.define(:version => 20150223180806) do |
15 | 15 | ||
16 | create_table "abuse_reports", :force => true do |t| | 16 | create_table "abuse_reports", :force => true do |t| |
17 | t.integer "reporter_id" | 17 | t.integer "reporter_id" |
@@ -535,6 +535,7 @@ ActiveRecord::Schema.define(:version => 20150122165042) do | @@ -535,6 +535,7 @@ ActiveRecord::Schema.define(:version => 20150122165042) do | ||
535 | t.integer "welcome_page_id" | 535 | t.integer "welcome_page_id" |
536 | t.boolean "allow_members_to_invite", :default => true | 536 | t.boolean "allow_members_to_invite", :default => true |
537 | t.boolean "invite_friends_only", :default => false | 537 | t.boolean "invite_friends_only", :default => false |
538 | + t.boolean "secret", :default => false | ||
538 | end | 539 | end |
539 | 540 | ||
540 | add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" | 541 | add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" |
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +Feature: Use a secret community | ||
2 | + As a community administrator | ||
3 | + I want to manage the community privacy | ||
4 | + | ||
5 | + Background: | ||
6 | + Given the following users | ||
7 | + | login | name | | ||
8 | + | jose | Jose Wilker | | ||
9 | + | maria | Maria Carminha | | ||
10 | + And the following community | ||
11 | + | identifier | name | | ||
12 | + | mycommunity | My Community | | ||
13 | + And "Jose Wilker" is admin of "My Community" | ||
14 | + And I am logged in as "jose" | ||
15 | + And I go to mycommunity's control panel | ||
16 | + And I follow "Community Info and settings" | ||
17 | + And I check "Secret" | ||
18 | + And I press "Save" | ||
19 | + And I follow "Logout" | ||
20 | + | ||
21 | + @selenium | ||
22 | + Scenario: Hide privacity options when secret is checked | ||
23 | + Given I am logged in as "jose" | ||
24 | + And I go to mycommunity's control panel | ||
25 | + And I follow "Community Info and settings" | ||
26 | + Then I should not see "Public — show content of this group to all internet users" | ||
27 | + And I should not see "Private — show content of this group only to members" | ||
28 | + And I uncheck "Secret" | ||
29 | + Then I should see "Public — show content of this group to all internet users" | ||
30 | + Then I should see "Private — show content of this group only to members" | ||
31 | + | ||
32 | + @selenium | ||
33 | + Scenario: Non members shouldn't see secret communit's content | ||
34 | + Given I am logged in as "maria" | ||
35 | + And I go to mycommunity's homepage | ||
36 | + And I should see "Access denied" | ||
37 | + And I follow "Communities" | ||
38 | + Then I should not see "My Community" | ||
39 | + | ||
40 | + Scenario: A member should see the secret community's content | ||
41 | + Given I am logged in as "maria" | ||
42 | + And "Maria Carminha" is a member of "My Community" | ||
43 | + And I go to maria's control panel | ||
44 | + And I follow "Manage my groups" | ||
45 | + And I follow "My Community" | ||
46 | + Then I should see "My Community" | ||
47 | + | ||
48 | + @selenium | ||
49 | + Scenario: public article on a secret profile should not be displayed | ||
50 | + Given I am logged in as "jose" | ||
51 | + And I go to mycommunity's control panel | ||
52 | + And I follow "Manage Content" | ||
53 | + And I follow "New content" | ||
54 | + And I follow "Text article with visual editor" | ||
55 | + And I fill in "Title" with "My public article" | ||
56 | + And I choose "Public" | ||
57 | + And I press "Save and continue" | ||
58 | + When I am logged in as "maria" | ||
59 | + And I go to /mycommunity/my-public-article | ||
60 | + Then I should not see "My public article" |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +(function($){ | ||
2 | + 'use strict'; | ||
3 | + | ||
4 | + function show_or_hide_privacy_radio_buttons(hide_options) { | ||
5 | + var public_community = $(".public-community-button").parent(); | ||
6 | + var private_community = $(".private-community-button").parent(); | ||
7 | + if (hide_options) { | ||
8 | + $(".private-community-button").selected(); | ||
9 | + public_community.hide(); | ||
10 | + private_community.hide(); | ||
11 | + | ||
12 | + } else { | ||
13 | + public_community.show(); | ||
14 | + private_community.show(); | ||
15 | + } | ||
16 | + } | ||
17 | + | ||
18 | + $(document).ready(function(){ | ||
19 | + var profile_secret = $(".profile-secret-box"); | ||
20 | + show_or_hide_privacy_radio_buttons(profile_secret.is(":checked")); | ||
21 | + profile_secret.change(function(){ | ||
22 | + show_or_hide_privacy_radio_buttons(this.checked); | ||
23 | + }); | ||
24 | + | ||
25 | + }); | ||
26 | +})(jQuery); |
test/unit/profile_test.rb
@@ -443,6 +443,24 @@ class ProfileTest < ActiveSupport::TestCase | @@ -443,6 +443,24 @@ class ProfileTest < ActiveSupport::TestCase | ||
443 | assert_not_includes result, p2 | 443 | assert_not_includes result, p2 |
444 | end | 444 | end |
445 | 445 | ||
446 | + should 'be able to find the public profiles but not secret ones' do | ||
447 | + p1 = create(Profile, :public_profile => true) | ||
448 | + p2 = create(Profile, :public_profile => true, :secret => true) | ||
449 | + | ||
450 | + result = Profile.public | ||
451 | + assert_includes result, p1 | ||
452 | + assert_not_includes result, p2 | ||
453 | + end | ||
454 | + | ||
455 | + should 'be able to find visible profiles but not secret ones' do | ||
456 | + p1 = create(Profile, :visible => true) | ||
457 | + p2 = create(Profile, :visible => true, :secret => true) | ||
458 | + | ||
459 | + result = Profile.visible | ||
460 | + assert_includes result, p1 | ||
461 | + assert_not_includes result, p2 | ||
462 | + end | ||
463 | + | ||
446 | should 'have public content by default' do | 464 | should 'have public content by default' do |
447 | assert_equal true, Profile.new.public_content | 465 | assert_equal true, Profile.new.public_content |
448 | end | 466 | end |
@@ -485,7 +503,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -485,7 +503,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
485 | should 'categorize in the entire category hierarchy' do | 503 | should 'categorize in the entire category hierarchy' do |
486 | c1 = fast_create(Category) | 504 | c1 = fast_create(Category) |
487 | c2 = fast_create(Category, :parent_id => c1.id) | 505 | c2 = fast_create(Category, :parent_id => c1.id) |
488 | - c3 = fast_create(Category, :parent_id => c2.id) | 506 | + c3 = fast_create(Category, :parent_id => c2.id) |
489 | 507 | ||
490 | profile = create_user('testuser').person | 508 | profile = create_user('testuser').person |
491 | profile.add_category(c3) | 509 | profile.add_category(c3) |
@@ -1006,7 +1024,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1006,7 +1024,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1006 | 1024 | ||
1007 | should 'copy header when applying template' do | 1025 | should 'copy header when applying template' do |
1008 | template = fast_create(Profile) | 1026 | template = fast_create(Profile) |
1009 | - template[:custom_header] = '{name}' | 1027 | + template[:custom_header] = '{name}' |
1010 | template.save! | 1028 | template.save! |
1011 | 1029 | ||
1012 | p = create(Profile, :name => 'test prof') | 1030 | p = create(Profile, :name => 'test prof') |
@@ -1260,7 +1278,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1260,7 +1278,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1260 | task2 = Task.create!(:requestor => person, :target => another) | 1278 | task2 = Task.create!(:requestor => person, :target => another) |
1261 | 1279 | ||
1262 | person.stubs(:is_admin?).with(other).returns(true) | 1280 | person.stubs(:is_admin?).with(other).returns(true) |
1263 | - Environment.find(:all).select{|i| i != other }.each do |env| | 1281 | + Environment.find(:all).select{|i| i != other }.each do |env| |
1264 | person.stubs(:is_admin?).with(env).returns(false) | 1282 | person.stubs(:is_admin?).with(env).returns(false) |
1265 | end | 1283 | end |
1266 | 1284 | ||
@@ -1729,7 +1747,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1729,7 +1747,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1729 | assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage) | 1747 | assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage) |
1730 | end | 1748 | end |
1731 | 1749 | ||
1732 | - | 1750 | + |
1733 | should 'find profiles with image' do | 1751 | should 'find profiles with image' do |
1734 | env = fast_create(Environment) | 1752 | env = fast_create(Environment) |
1735 | 2.times do |n| | 1753 | 2.times do |n| |