Commit fd4c6709aebde68bd136ea69535a08e2952736fa

Authored by Antonio Terceiro
2 parents f53bed06 78f01eb3

Merge branch 'stable'

app/controllers/public/profile_controller.rb
... ... @@ -2,6 +2,7 @@ class ProfileController < PublicController
2 2  
3 3 needs_profile
4 4 before_filter :check_access_to_profile
  5 + before_filter :store_before_join, :only => [:join]
5 6 before_filter :login_required, :only => [:join, :refuse_join, :leave]
6 7  
7 8 helper TagsHelper
... ... @@ -61,7 +62,7 @@ class ProfileController < PublicController
61 62 if @wizard
62 63 redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true
63 64 else
64   - redirect_back_or_default profile.url
  65 + redirect_to_before_join
65 66 end
66 67 else
67 68 store_location(request.referer)
... ... @@ -110,6 +111,20 @@ class ProfileController < PublicController
110 111 end
111 112 end
112 113  
  114 + def store_before_join
  115 + session[:before_join] = request.referer unless logged_in?
  116 + end
  117 +
  118 + def redirect_to_before_join
  119 + back = session[:before_join]
  120 + if back
  121 + session[:before_join] = nil
  122 + redirect_to back
  123 + else
  124 + redirect_back_or_default profile.url
  125 + end
  126 + end
  127 +
113 128 def per_page
114 129 Noosfero::Constants::PROFILE_PER_PAGE
115 130 end
... ...
app/helpers/application_helper.rb
... ... @@ -852,6 +852,7 @@ module ApplicationHelper
852 852  
853 853 def ask_to_join?
854 854 return if !environment.enabled?(:join_community_popup)
  855 + return if params[:action] == 'join'
855 856 return unless profile && profile.kind_of?(Community)
856 857 if (session[:no_asking] && session[:no_asking].include?(profile.id))
857 858 return false
... ...
app/models/article.rb
... ... @@ -26,6 +26,8 @@ class Article < ActiveRecord::Base
26 26 article.published_at = article.created_at if article.published_at.nil?
27 27 end
28 28  
  29 + xss_terminate :only => [ :name ]
  30 +
29 31 def self.human_attribute_name(attrib)
30 32 case attrib.to_sym
31 33 when :name
... ...
app/models/event.rb
... ... @@ -6,7 +6,7 @@ class Event < Article
6 6 settings_items :link, :type => :string
7 7 settings_items :address, :type => :string
8 8  
9   - xss_terminate :only => [ :description ], :with => 'white_list'
  9 + xss_terminate :only => [ :description, :link, :address ], :with => 'white_list'
10 10  
11 11 validates_presence_of :title, :start_date
12 12  
... ...
app/models/people_block.rb
... ... @@ -28,4 +28,8 @@ class PeopleBlock < ProfileListBlock
28 28 end
29 29 end
30 30  
  31 + def profile_count
  32 + owner.people.count(:conditions => {:public_profile => true})
  33 + end
  34 +
31 35 end
... ...
app/models/profile.rb
... ... @@ -270,6 +270,7 @@ class Profile < ActiveRecord::Base
270 270 end
271 271  
272 272 xss_terminate :only => [ :name, :nickname, :address, :contact_phone ]
  273 + xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list'
273 274  
274 275 # returns the contact email for this profile.
275 276 #
... ...
app/models/profile_list_block.rb
... ... @@ -89,8 +89,8 @@ class ProfileListBlock < Block
89 89 title.gsub('{#}', profile_count.to_s)
90 90 end
91 91  
92   - def profile_count #defined in children
93   - 0
  92 + def profile_count
  93 + owner.profiles.count(:conditions => {:public_profile => true})
94 94 end
95 95  
96 96 end
... ...
test/functional/profile_controller_test.rb
... ... @@ -634,4 +634,27 @@ class ProfileControllerTest < Test::Unit::TestCase
634 634 assert_redirected_to "/profile/#{community.identifier}/to_go"
635 635 end
636 636  
  637 + should 'store location before login when request join via get not logged' do
  638 + community = Community.create!(:name => 'my test community')
  639 +
  640 + @request.expects(:referer).returns("/profile/#{community.identifier}")
  641 +
  642 + get :join, :profile => community.identifier
  643 +
  644 + assert_equal "/profile/#{community.identifier}", @request.session[:before_join]
  645 + end
  646 +
  647 + should 'redirect to location before login after join community' do
  648 + community = Community.create!(:name => 'my test community')
  649 +
  650 + @request.session[:before_join] = "/profile/#{community.identifier}/to_go"
  651 + login_as(profile.identifier)
  652 +
  653 + post :join, :profile => community.identifier, :confirmation => '1'
  654 +
  655 + assert_redirected_to "/profile/#{community.identifier}/to_go"
  656 +
  657 + assert_nil @request.session[:before_join]
  658 + end
  659 +
637 660 end
... ...
test/functional/role_controller_test.rb
... ... @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase
82 82 assert_not_nil assigns(:role)
83 83 end
84 84 end
  85 +
  86 + should 'not crash when editing role with no permissions' do
  87 + role = Role.create!(:name => 'test_role', :environment => Environment.default)
  88 +
  89 + assert_nothing_raised do
  90 + get :edit, :id => role.id
  91 + end
  92 + end
85 93 end
... ...
test/unit/application_helper_test.rb
... ... @@ -350,6 +350,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
350 350 end
351 351  
352 352 should 'not ask_to_join unless profile defined' do
  353 + stubs(:params).returns({})
  354 +
353 355 e = Environment.default
354 356 e.stubs(:enabled?).with(:join_community_popup).returns(true)
355 357 stubs(:environment).returns(e)
... ... @@ -359,6 +361,7 @@ class ApplicationHelperTest < Test::Unit::TestCase
359 361 end
360 362  
361 363 should 'not ask_to_join unless profile is community' do
  364 + stubs(:params).returns({})
362 365 e = Environment.default
363 366 e.stubs(:enabled?).with(:join_community_popup).returns(true)
364 367 stubs(:environment).returns(e)
... ... @@ -368,7 +371,22 @@ class ApplicationHelperTest < Test::Unit::TestCase
368 371 assert ! ask_to_join?
369 372 end
370 373  
  374 + should 'not ask_to_join if action join' do
  375 + expects(:params).returns({:action => 'join'})
  376 +
  377 + e = Environment.default
  378 + e.stubs(:enabled?).with(:join_community_popup).returns(true)
  379 + stubs(:environment).returns(e)
  380 +
  381 + c = Community.create(:name => 'test_comm', :identifier => 'test_comm')
  382 + stubs(:profile).returns(c)
  383 + stubs(:logged_in?).returns(false)
  384 + assert ! ask_to_join?
  385 + end
  386 +
371 387 should 'ask_to_join if its not logged and in a community' do
  388 + stubs(:params).returns({})
  389 +
372 390 e = Environment.default
373 391 e.stubs(:enabled?).with(:join_community_popup).returns(true)
374 392 stubs(:environment).returns(e)
... ... @@ -380,6 +398,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
380 398 end
381 399  
382 400 should 'ask_to_join if user say so' do
  401 + stubs(:params).returns({})
  402 +
383 403 e = Environment.default
384 404 e.stubs(:enabled?).with(:join_community_popup).returns(true)
385 405 stubs(:environment).returns(e)
... ... @@ -395,6 +415,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
395 415 end
396 416  
397 417 should 'not ask_to_join if user say no' do
  418 + stubs(:params).returns({})
  419 +
398 420 e = Environment.default
399 421 e.stubs(:enabled?).with(:join_community_popup).returns(true)
400 422 stubs(:environment).returns(e)
... ... @@ -409,6 +431,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
409 431 end
410 432  
411 433 should 'not ask_to_join if environment say no even if its not logged and in a community' do
  434 + stubs(:params).returns({})
  435 +
412 436 e = Environment.default
413 437 e.stubs(:enabled?).with(:join_community_popup).returns(false)
414 438 stubs(:environment).returns(e)
... ... @@ -419,6 +443,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
419 443 end
420 444  
421 445 should 'not ask_to_join if environment say no even if user say so' do
  446 + stubs(:params).returns({})
  447 +
422 448 e = Environment.default
423 449 e.stubs(:enabled?).with(:join_community_popup).returns(false)
424 450 stubs(:environment).returns(e)
... ... @@ -433,6 +459,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
433 459 end
434 460  
435 461 should 'not ask_to_join if its recorded in the session' do
  462 + stubs(:params).returns({})
  463 +
436 464 e = Environment.default
437 465 e.stubs(:enabled?).with(:join_community_popup).returns(true)
438 466 stubs(:environment).returns(e)
... ... @@ -446,6 +474,8 @@ class ApplicationHelperTest < Test::Unit::TestCase
446 474 end
447 475  
448 476 should 'not ask_to_join if its recorded in the session even for authenticated users' do
  477 + stubs(:params).returns({})
  478 +
449 479 e = Environment.default
450 480 e.stubs(:enabled?).with(:join_community_popup).returns(true)
451 481 stubs(:environment).returns(e)
... ...
test/unit/people_block_test.rb
... ... @@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase
24 24 end
25 25  
26 26 should 'list people' do
27   - owner = mock
28   - owner.expects(:id).returns(99)
29   - Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => 99, :public_profile => true}, :limit => 6, :order => 'random()').returns([])
  27 + owner = Environment.create!(:name => 'test environment')
  28 + Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => owner.id, :public_profile => true}, :limit => 6, :order => 'random()').returns([])
30 29 block = PeopleBlock.new
31 30 block.expects(:owner).returns(owner).at_least_once
32 31 block.content
... ... @@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase
41 40 instance_eval(&block.footer)
42 41 end
43 42  
  43 + should 'count number of public people' do
  44 + env = Environment.create!(:name => 'test environment')
  45 + private_p = create_user('private', {:environment => env}, {:public_profile => false})
  46 + public_p = create_user('public', {:environment => env}, {:public_profile => true})
  47 +
  48 + env.boxes.first.blocks << block = PeopleBlock.new
  49 + assert_equal 1, block.profile_count
  50 + end
  51 +
44 52 end
... ...
test/unit/profile_list_block_test.rb
... ... @@ -24,7 +24,7 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
24 24 person2 = create_user('testperson2').person
25 25 person3 = create_user('testperson3').person
26 26  
27   - owner = create_user('mytestuser').person
  27 + owner = Environment.create!(:name => 'test env')
28 28 block = ProfileListBlock.new
29 29 owner.boxes.first.blocks << block
30 30 block.save!
... ... @@ -68,12 +68,36 @@ class ProfileListBlockTest &lt; Test::Unit::TestCase
68 68 end
69 69  
70 70 should 'provide view_title' do
71   - p = ProfileListBlock.new(:title => 'Title from block')
72   - assert_equal 'Title from block', p.view_title
  71 + env = Environment.create!(:name => 'test env')
  72 + block = ProfileListBlock.new(:title => 'Title from block')
  73 + env.boxes.first.blocks << block
  74 + block.save!
  75 + assert_equal 'Title from block', block.view_title
73 76 end
74 77  
75 78 should 'provide view title with variables' do
76   - p = ProfileListBlock.new(:title => '{#} members')
77   - assert_equal '0 members', p.view_title
  79 + env = Environment.create!(:name => 'test env')
  80 + block = ProfileListBlock.new(:title => '{#} members')
  81 + env.boxes.first.blocks << block
  82 + block.save!
  83 + assert_equal '0 members', block.view_title
  84 + end
  85 +
  86 + should 'count number of public profiles' do
  87 + env = Environment.create!(:name => 'test env')
  88 + block = ProfileListBlock.new
  89 + env.boxes.first.blocks << block
  90 + block.save!
  91 +
  92 + priv_p = create_user('private', {:environment => env}, {:public_profile => false})
  93 + pub_p = create_user('public', {:environment => env}, {:public_profile => true})
  94 +
  95 + priv_c = Community.create!(:name => 'com 1', :public_profile => false, :environment => env)
  96 + pub_c = Community.create!(:name => 'com 2', :public_profile => true , :environment => env)
  97 +
  98 + priv_e = Enterprise.create!(:name => 'ent 1', :identifier => 'ent1', :public_profile => false , :environment => env)
  99 + pub_e = Enterprise.create!(:name => 'ent 2', :identifier => 'ent2', :public_profile => true , :environment => env)
  100 +
  101 + assert_equal 3, block.profile_count
78 102 end
79 103 end
... ...
vendor/plugins/access_control/lib/role.rb
... ... @@ -32,7 +32,12 @@ class Role &lt; ActiveRecord::Base
32 32 end
33 33  
34 34 def kind
35   - perms.keys.detect{|k| perms[k].keys.include?(permissions[0]) }
  35 + env_perms = perms['Environment'].keys
  36 + if permissions.any?{ |perm| env_perms.include?(perm) }
  37 + 'Environment'
  38 + else
  39 + 'Profile'
  40 + end
36 41 end
37 42  
38 43 def name
... ...