Commit 7f93cfa3bf15cd347a5d5ca0d126a5941344c9fc

Authored by AntonioTerceiro
1 parent c3c68ac2

ActionItem295: switching profile visualization as public/private (still

missing user interface)


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1801 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/profile_controller.rb
1 class ProfileController < ApplicationController 1 class ProfileController < ApplicationController
  2 +
2 needs_profile 3 needs_profile
  4 + before_filter :check_public_profile
3 5
4 helper TagsHelper 6 helper TagsHelper
5 7
@@ -31,4 +33,13 @@ class ProfileController &lt; ApplicationController @@ -31,4 +33,13 @@ class ProfileController &lt; ApplicationController
31 def favorite_enterprises 33 def favorite_enterprises
32 @favorite_enterprises = profile.favorite_enterprises 34 @favorite_enterprises = profile.favorite_enterprises
33 end 35 end
  36 +
  37 + protected
  38 +
  39 + def check_public_profile
  40 + if !profile.public_profile
  41 + render :action => 'private_profile', :status => 403, :layout => false
  42 + end
  43 + end
  44 +
34 end 45 end
app/models/profile.rb
@@ -35,6 +35,8 @@ class Profile &lt; ActiveRecord::Base @@ -35,6 +35,8 @@ class Profile &lt; ActiveRecord::Base
35 35
36 acts_as_having_settings :field => :data 36 acts_as_having_settings :field => :data
37 37
  38 + settings_items :public_profile, :public_content, :type => :boolean, :default => true
  39 +
38 acts_as_mappable :default_units => :kms 40 acts_as_mappable :default_units => :kms
39 41
40 # Valid identifiers must match this format. 42 # Valid identifiers must match this format.
app/views/profile/private_profile.rhtml 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +<html>
  2 + <!-- FIXME: should use a proper layout for this kind of message -->
  3 + <body>
  4 + <%= _("This profile is not public.") %>
  5 + </body>
  6 +</html>
test/functional/content_viewer_controller_test.rb
@@ -229,4 +229,31 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase @@ -229,4 +229,31 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
229 assert_tag :tag => 'div', :attributes => { :class => 'article-tags' }, :descendant => { :content => /This article's tags:/ } 229 assert_tag :tag => 'div', :attributes => { :class => 'article-tags' }, :descendant => { :content => /This article's tags:/ }
230 end 230 end
231 231
  232 + should 'not display articles from private content' do
  233 + profile.articles.create!(:name => 'test')
  234 + profile.update_attributes!(:public_content => false)
  235 +
  236 + get :view_page, :profile => profile.identifier, :page => [ 'test' ]
  237 + assert_response 403
  238 + end
  239 +
  240 + #should 'display articles to its owner' do
  241 + #profile.articles.create!(:name => 'test')
  242 + #profile.update_attributes!(:public_content => false)
  243 +
  244 + #login_as(@profile.identifier)
  245 + #get :view_page, :profile => profile.identifier, :page => [ 'test' ]
  246 + #assert_response 200
  247 + #end
  248 +
  249 + #should 'display articles to profile members' do
  250 + #c = Community.create!(:name => 'my community')
  251 + #c.update_attributes!(:public_content => false)
  252 + #c.add_member(@profile)
  253 +
  254 + #login_as(@profile.identifier)
  255 + #get :view_page, :profile => profile.identifier, :page => [ 'test' ]
  256 + #assert_response 200
  257 + #end
  258 +
232 end 259 end
test/functional/profile_controller_test.rb
@@ -187,4 +187,10 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -187,4 +187,10 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
187 assert_no_tag :tag => 'a', :content => 'Leave this community' 187 assert_no_tag :tag => 'a', :content => 'Leave this community'
188 end 188 end
189 189
  190 + should 'not display private profile' do
  191 + @profile.update_attributes!(:public_profile => false)
  192 + get :index, :profile => @profile.identifier
  193 + assert_response 403
  194 + end
  195 +
190 end 196 end
test/functional/profile_editor_controller_test.rb
@@ -192,6 +192,23 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -192,6 +192,23 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
192 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' } 192 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[info][contact_person]', :value => 'my contact' }
193 end 193 end
194 194
  195 + should 'display profile publication option in edit profile screen' do
  196 + profile = Profile['ze']
  197 + get :edit, :profile => 'ze'
  198 + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' }
  199 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'profile_data[public_profile]', :value => false }
  200 + end
  201 +
  202 + should 'save profile publication option set to true' do
  203 + post :edit, :profile => 'ze', :profile_data => { :public_profile => 'true' }
  204 + assert_equal true, Profile['ze'].public_profile
  205 + end
  206 +
  207 + should 'save profile publication option set to false' do
  208 + post :edit, :profile => 'ze', :profile_data => { :public_profile => 'false' }
  209 + assert_equal false, Profile['ze'].public_profile
  210 + end
  211 +
195 should 'show error messages for' 212 should 'show error messages for'
196 213
197 end 214 end
test/unit/profile_test.rb
@@ -467,6 +467,26 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -467,6 +467,26 @@ class ProfileTest &lt; Test::Unit::TestCase
467 assert_not_includes c.members, p 467 assert_not_includes c.members, p
468 end 468 end
469 469
  470 + should 'have a public profile by default' do
  471 + assert_equal true, Profile.new.public_profile
  472 + end
  473 +
  474 + should 'be able to turn profile private' do
  475 + p = Profile.new
  476 + p.public_profile = false
  477 + assert_equal false, p.public_profile
  478 + end
  479 +
  480 + should 'have public content by default' do
  481 + assert_equal true, Profile.new.public_content
  482 + end
  483 +
  484 + should 'be able to turn content private' do
  485 + p = Profile.new
  486 + p.public_content = false
  487 + assert_equal false, p.public_content
  488 + end
  489 +
470 private 490 private
471 491
472 def assert_invalid_identifier(id) 492 def assert_invalid_identifier(id)