diff --git a/app/models/profile.rb b/app/models/profile.rb index e0c6516..b5540c4 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,7 +3,7 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base - 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 + 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 # use for internationalizable human type names in search facets # reimplement on subclasses @@ -119,9 +119,9 @@ class Profile < ActiveRecord::Base Profile.column_names.map{|n| [Profile.table_name, n].join('.')}.join(',') end - scope :visible, :conditions => { :visible => true } + scope :visible, :conditions => { :visible => true, :secret => false } scope :disabled, :conditions => { :visible => false } - scope :public, :conditions => { :visible => true, :public_profile => true } + scope :public, :conditions => { :visible => true, :public_profile => true, :secret => false } scope :enabled, :conditions => { :enabled => true } # Subclasses must override this method diff --git a/app/views/profile_editor/edit.html.erb b/app/views/profile_editor/edit.html.erb index 735145f..f93fd62 100644 --- a/app/views/profile_editor/edit.html.erb +++ b/app/views/profile_editor/edit.html.erb @@ -34,10 +34,13 @@ <% else %>
- <%= labelled_radio_button _('Public — show content of this group to all internet users'), 'profile_data[public_profile]', true, @profile.public_profile? %> + <%= 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" %>
- <%= labelled_radio_button _('Private — show content of this group only to members'), 'profile_data[public_profile]', false, !@profile.public_profile? %> + <%= 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" %> +
+
+ <%= labelled_radio_button _('Private — show content of this group only to members'), 'profile_data[public_profile]', false, !@profile.public_profile?, :class => "private-community-button" %>
<% end %> @@ -85,4 +88,6 @@ <% end %> <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> + +<%= javascript_include_tag 'profile_editor' %> diff --git a/db/migrate/20150223180806_add_secret_to_profile.rb b/db/migrate/20150223180806_add_secret_to_profile.rb new file mode 100644 index 0000000..a642526 --- /dev/null +++ b/db/migrate/20150223180806_add_secret_to_profile.rb @@ -0,0 +1,5 @@ +class AddSecretToProfile < ActiveRecord::Migration + def change + add_column :profiles, :secret, :boolean, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4779cfa..d1c4279 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150122165042) do +ActiveRecord::Schema.define(:version => 20150223180806) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -535,6 +535,7 @@ ActiveRecord::Schema.define(:version => 20150122165042) do t.integer "welcome_page_id" t.boolean "allow_members_to_invite", :default => true t.boolean "invite_friends_only", :default => false + t.boolean "secret", :default => false end add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" diff --git a/features/secret_community.feature b/features/secret_community.feature new file mode 100644 index 0000000..24d887c --- /dev/null +++ b/features/secret_community.feature @@ -0,0 +1,60 @@ +Feature: Use a secret community + As a community administrator + I want to manage the community privacy + + Background: + Given the following users + | login | name | + | jose | Jose Wilker | + | maria | Maria Carminha | + And the following community + | identifier | name | + | mycommunity | My Community | + And "Jose Wilker" is admin of "My Community" + And I am logged in as "jose" + And I go to mycommunity's control panel + And I follow "Community Info and settings" + And I check "Secret" + And I press "Save" + And I follow "Logout" + + @selenium + Scenario: Hide privacity options when secret is checked + Given I am logged in as "jose" + And I go to mycommunity's control panel + And I follow "Community Info and settings" + Then I should not see "Public — show content of this group to all internet users" + And I should not see "Private — show content of this group only to members" + And I uncheck "Secret" + Then I should see "Public — show content of this group to all internet users" + Then I should see "Private — show content of this group only to members" + + @selenium + Scenario: Non members shouldn't see secret communit's content + Given I am logged in as "maria" + And I go to mycommunity's homepage + And I should see "Access denied" + And I follow "Communities" + Then I should not see "My Community" + + Scenario: A member should see the secret community's content + Given I am logged in as "maria" + And "Maria Carminha" is a member of "My Community" + And I go to maria's control panel + And I follow "Manage my groups" + And I follow "My Community" + Then I should see "My Community" + + @selenium + Scenario: public article on a secret profile should not be displayed + Given I am logged in as "jose" + And I go to mycommunity's control panel + And I follow "Manage Content" + And I follow "New content" + And I follow "Text article with visual editor" + And I fill in "Title" with "My public article" + And I choose "Public" + And I press "Save and continue" + When I am logged in as "maria" + And I go to /mycommunity/my-public-article + Then I should not see "My public article" diff --git a/public/javascripts/profile_editor.js b/public/javascripts/profile_editor.js new file mode 100644 index 0000000..18727ac --- /dev/null +++ b/public/javascripts/profile_editor.js @@ -0,0 +1,26 @@ +(function($){ + 'use strict'; + + function show_or_hide_privacy_radio_buttons(hide_options) { + var public_community = $(".public-community-button").parent(); + var private_community = $(".private-community-button").parent(); + if (hide_options) { + $(".private-community-button").selected(); + public_community.hide(); + private_community.hide(); + + } else { + public_community.show(); + private_community.show(); + } + } + + $(document).ready(function(){ + var profile_secret = $(".profile-secret-box"); + show_or_hide_privacy_radio_buttons(profile_secret.is(":checked")); + profile_secret.change(function(){ + show_or_hide_privacy_radio_buttons(this.checked); + }); + + }); +})(jQuery); diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 1b9665a..1a0f915 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -443,6 +443,24 @@ class ProfileTest < ActiveSupport::TestCase assert_not_includes result, p2 end + should 'be able to find the public profiles but not secret ones' do + p1 = create(Profile, :public_profile => true) + p2 = create(Profile, :public_profile => true, :secret => true) + + result = Profile.public + assert_includes result, p1 + assert_not_includes result, p2 + end + + should 'be able to find visible profiles but not secret ones' do + p1 = create(Profile, :visible => true) + p2 = create(Profile, :visible => true, :secret => true) + + result = Profile.visible + assert_includes result, p1 + assert_not_includes result, p2 + end + should 'have public content by default' do assert_equal true, Profile.new.public_content end @@ -485,7 +503,7 @@ class ProfileTest < ActiveSupport::TestCase should 'categorize in the entire category hierarchy' do c1 = fast_create(Category) c2 = fast_create(Category, :parent_id => c1.id) - c3 = fast_create(Category, :parent_id => c2.id) + c3 = fast_create(Category, :parent_id => c2.id) profile = create_user('testuser').person profile.add_category(c3) @@ -1006,7 +1024,7 @@ class ProfileTest < ActiveSupport::TestCase should 'copy header when applying template' do template = fast_create(Profile) - template[:custom_header] = '{name}' + template[:custom_header] = '{name}' template.save! p = create(Profile, :name => 'test prof') @@ -1260,7 +1278,7 @@ class ProfileTest < ActiveSupport::TestCase task2 = Task.create!(:requestor => person, :target => another) person.stubs(:is_admin?).with(other).returns(true) - Environment.find(:all).select{|i| i != other }.each do |env| + Environment.find(:all).select{|i| i != other }.each do |env| person.stubs(:is_admin?).with(env).returns(false) end @@ -1729,7 +1747,7 @@ class ProfileTest < ActiveSupport::TestCase assert profile.is_on_homepage?("/#{profile.identifier}/#{homepage.slug}", homepage) end - + should 'find profiles with image' do env = fast_create(Environment) 2.times do |n| -- libgit2 0.21.2