From 7f93cfa3bf15cd347a5d5ca0d126a5941344c9fc Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 15 May 2008 20:12:41 +0000 Subject: [PATCH] ActionItem295: switching profile visualization as public/private (still missing user interface) --- app/controllers/public/profile_controller.rb | 11 +++++++++++ app/models/profile.rb | 2 ++ app/views/profile/private_profile.rhtml | 6 ++++++ test/functional/content_viewer_controller_test.rb | 27 +++++++++++++++++++++++++++ test/functional/profile_controller_test.rb | 6 ++++++ test/functional/profile_editor_controller_test.rb | 17 +++++++++++++++++ test/unit/profile_test.rb | 20 ++++++++++++++++++++ 7 files changed, 89 insertions(+), 0 deletions(-) create mode 100644 app/views/profile/private_profile.rhtml diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index a17a4dc..40013d0 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -1,5 +1,7 @@ class ProfileController < ApplicationController + needs_profile + before_filter :check_public_profile helper TagsHelper @@ -31,4 +33,13 @@ class ProfileController < ApplicationController def favorite_enterprises @favorite_enterprises = profile.favorite_enterprises end + + protected + + def check_public_profile + if !profile.public_profile + render :action => 'private_profile', :status => 403, :layout => false + end + end + end diff --git a/app/models/profile.rb b/app/models/profile.rb index c6d023b..aa4228e 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -35,6 +35,8 @@ class Profile < ActiveRecord::Base acts_as_having_settings :field => :data + settings_items :public_profile, :public_content, :type => :boolean, :default => true + acts_as_mappable :default_units => :kms # Valid identifiers must match this format. diff --git a/app/views/profile/private_profile.rhtml b/app/views/profile/private_profile.rhtml new file mode 100644 index 0000000..2b0c2d3 --- /dev/null +++ b/app/views/profile/private_profile.rhtml @@ -0,0 +1,6 @@ + + + + <%= _("This profile is not public.") %> + + diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index ef0cf47..e2c7828 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -229,4 +229,31 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_tag :tag => 'div', :attributes => { :class => 'article-tags' }, :descendant => { :content => /This article's tags:/ } end + should 'not display articles from private content' do + profile.articles.create!(:name => 'test') + profile.update_attributes!(:public_content => false) + + get :view_page, :profile => profile.identifier, :page => [ 'test' ] + assert_response 403 + end + + #should 'display articles to its owner' do + #profile.articles.create!(:name => 'test') + #profile.update_attributes!(:public_content => false) + + #login_as(@profile.identifier) + #get :view_page, :profile => profile.identifier, :page => [ 'test' ] + #assert_response 200 + #end + + #should 'display articles to profile members' do + #c = Community.create!(:name => 'my community') + #c.update_attributes!(:public_content => false) + #c.add_member(@profile) + + #login_as(@profile.identifier) + #get :view_page, :profile => profile.identifier, :page => [ 'test' ] + #assert_response 200 + #end + end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 297bcdb..1c6135c 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -187,4 +187,10 @@ class ProfileControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :content => 'Leave this community' end + should 'not display private profile' do + @profile.update_attributes!(:public_profile => false) + get :index, :profile => @profile.identifier + assert_response 403 + end + end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 94ae0d4..2bae683 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -192,6 +192,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' } end + should 'display profile publication option in edit profile screen' do + profile = Profile['ze'] + get :edit, :profile => 'ze' + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' } + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'profile_data[public_profile]', :value => false } + end + + should 'save profile publication option set to true' do + post :edit, :profile => 'ze', :profile_data => { :public_profile => 'true' } + assert_equal true, Profile['ze'].public_profile + end + + should 'save profile publication option set to false' do + post :edit, :profile => 'ze', :profile_data => { :public_profile => 'false' } + assert_equal false, Profile['ze'].public_profile + end + should 'show error messages for' end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index abc14ce..9ee0c8d 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -467,6 +467,26 @@ class ProfileTest < Test::Unit::TestCase assert_not_includes c.members, p end + should 'have a public profile by default' do + assert_equal true, Profile.new.public_profile + end + + should 'be able to turn profile private' do + p = Profile.new + p.public_profile = false + assert_equal false, p.public_profile + end + + should 'have public content by default' do + assert_equal true, Profile.new.public_content + end + + should 'be able to turn content private' do + p = Profile.new + p.public_content = false + assert_equal false, p.public_content + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2