Commit fd4c6709aebde68bd136ea69535a08e2952736fa
Exists in
master
and in
22 other branches
Merge branch 'stable'
Showing
13 changed files
with
134 additions
and
13 deletions
Show diff stats
app/controllers/public/profile_controller.rb
| @@ -2,6 +2,7 @@ class ProfileController < PublicController | @@ -2,6 +2,7 @@ class ProfileController < PublicController | ||
| 2 | 2 | ||
| 3 | needs_profile | 3 | needs_profile |
| 4 | before_filter :check_access_to_profile | 4 | before_filter :check_access_to_profile |
| 5 | + before_filter :store_before_join, :only => [:join] | ||
| 5 | before_filter :login_required, :only => [:join, :refuse_join, :leave] | 6 | before_filter :login_required, :only => [:join, :refuse_join, :leave] |
| 6 | 7 | ||
| 7 | helper TagsHelper | 8 | helper TagsHelper |
| @@ -61,7 +62,7 @@ class ProfileController < PublicController | @@ -61,7 +62,7 @@ class ProfileController < PublicController | ||
| 61 | if @wizard | 62 | if @wizard |
| 62 | redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true | 63 | redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true |
| 63 | else | 64 | else |
| 64 | - redirect_back_or_default profile.url | 65 | + redirect_to_before_join |
| 65 | end | 66 | end |
| 66 | else | 67 | else |
| 67 | store_location(request.referer) | 68 | store_location(request.referer) |
| @@ -110,6 +111,20 @@ class ProfileController < PublicController | @@ -110,6 +111,20 @@ class ProfileController < PublicController | ||
| 110 | end | 111 | end |
| 111 | end | 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 | def per_page | 128 | def per_page |
| 114 | Noosfero::Constants::PROFILE_PER_PAGE | 129 | Noosfero::Constants::PROFILE_PER_PAGE |
| 115 | end | 130 | end |
app/helpers/application_helper.rb
| @@ -852,6 +852,7 @@ module ApplicationHelper | @@ -852,6 +852,7 @@ module ApplicationHelper | ||
| 852 | 852 | ||
| 853 | def ask_to_join? | 853 | def ask_to_join? |
| 854 | return if !environment.enabled?(:join_community_popup) | 854 | return if !environment.enabled?(:join_community_popup) |
| 855 | + return if params[:action] == 'join' | ||
| 855 | return unless profile && profile.kind_of?(Community) | 856 | return unless profile && profile.kind_of?(Community) |
| 856 | if (session[:no_asking] && session[:no_asking].include?(profile.id)) | 857 | if (session[:no_asking] && session[:no_asking].include?(profile.id)) |
| 857 | return false | 858 | return false |
app/models/article.rb
| @@ -26,6 +26,8 @@ class Article < ActiveRecord::Base | @@ -26,6 +26,8 @@ class Article < ActiveRecord::Base | ||
| 26 | article.published_at = article.created_at if article.published_at.nil? | 26 | article.published_at = article.created_at if article.published_at.nil? |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | + xss_terminate :only => [ :name ] | ||
| 30 | + | ||
| 29 | def self.human_attribute_name(attrib) | 31 | def self.human_attribute_name(attrib) |
| 30 | case attrib.to_sym | 32 | case attrib.to_sym |
| 31 | when :name | 33 | when :name |
app/models/event.rb
| @@ -6,7 +6,7 @@ class Event < Article | @@ -6,7 +6,7 @@ class Event < Article | ||
| 6 | settings_items :link, :type => :string | 6 | settings_items :link, :type => :string |
| 7 | settings_items :address, :type => :string | 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 | validates_presence_of :title, :start_date | 11 | validates_presence_of :title, :start_date |
| 12 | 12 |
app/models/people_block.rb
app/models/profile.rb
| @@ -270,6 +270,7 @@ class Profile < ActiveRecord::Base | @@ -270,6 +270,7 @@ class Profile < ActiveRecord::Base | ||
| 270 | end | 270 | end |
| 271 | 271 | ||
| 272 | xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] | 272 | xss_terminate :only => [ :name, :nickname, :address, :contact_phone ] |
| 273 | + xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list' | ||
| 273 | 274 | ||
| 274 | # returns the contact email for this profile. | 275 | # returns the contact email for this profile. |
| 275 | # | 276 | # |
app/models/profile_list_block.rb
| @@ -89,8 +89,8 @@ class ProfileListBlock < Block | @@ -89,8 +89,8 @@ class ProfileListBlock < Block | ||
| 89 | title.gsub('{#}', profile_count.to_s) | 89 | title.gsub('{#}', profile_count.to_s) |
| 90 | end | 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 | end | 94 | end |
| 95 | 95 | ||
| 96 | end | 96 | end |
test/functional/profile_controller_test.rb
| @@ -634,4 +634,27 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -634,4 +634,27 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 634 | assert_redirected_to "/profile/#{community.identifier}/to_go" | 634 | assert_redirected_to "/profile/#{community.identifier}/to_go" |
| 635 | end | 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 | end | 660 | end |
test/functional/role_controller_test.rb
| @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase | @@ -82,4 +82,12 @@ class RoleControllerTest < Test::Unit::TestCase | ||
| 82 | assert_not_nil assigns(:role) | 82 | assert_not_nil assigns(:role) |
| 83 | end | 83 | end |
| 84 | end | 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 | end | 93 | end |
test/unit/application_helper_test.rb
| @@ -350,6 +350,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -350,6 +350,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 350 | end | 350 | end |
| 351 | 351 | ||
| 352 | should 'not ask_to_join unless profile defined' do | 352 | should 'not ask_to_join unless profile defined' do |
| 353 | + stubs(:params).returns({}) | ||
| 354 | + | ||
| 353 | e = Environment.default | 355 | e = Environment.default |
| 354 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 356 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 355 | stubs(:environment).returns(e) | 357 | stubs(:environment).returns(e) |
| @@ -359,6 +361,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -359,6 +361,7 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 359 | end | 361 | end |
| 360 | 362 | ||
| 361 | should 'not ask_to_join unless profile is community' do | 363 | should 'not ask_to_join unless profile is community' do |
| 364 | + stubs(:params).returns({}) | ||
| 362 | e = Environment.default | 365 | e = Environment.default |
| 363 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 366 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 364 | stubs(:environment).returns(e) | 367 | stubs(:environment).returns(e) |
| @@ -368,7 +371,22 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -368,7 +371,22 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 368 | assert ! ask_to_join? | 371 | assert ! ask_to_join? |
| 369 | end | 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 | should 'ask_to_join if its not logged and in a community' do | 387 | should 'ask_to_join if its not logged and in a community' do |
| 388 | + stubs(:params).returns({}) | ||
| 389 | + | ||
| 372 | e = Environment.default | 390 | e = Environment.default |
| 373 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 391 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 374 | stubs(:environment).returns(e) | 392 | stubs(:environment).returns(e) |
| @@ -380,6 +398,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -380,6 +398,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 380 | end | 398 | end |
| 381 | 399 | ||
| 382 | should 'ask_to_join if user say so' do | 400 | should 'ask_to_join if user say so' do |
| 401 | + stubs(:params).returns({}) | ||
| 402 | + | ||
| 383 | e = Environment.default | 403 | e = Environment.default |
| 384 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 404 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 385 | stubs(:environment).returns(e) | 405 | stubs(:environment).returns(e) |
| @@ -395,6 +415,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -395,6 +415,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 395 | end | 415 | end |
| 396 | 416 | ||
| 397 | should 'not ask_to_join if user say no' do | 417 | should 'not ask_to_join if user say no' do |
| 418 | + stubs(:params).returns({}) | ||
| 419 | + | ||
| 398 | e = Environment.default | 420 | e = Environment.default |
| 399 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 421 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 400 | stubs(:environment).returns(e) | 422 | stubs(:environment).returns(e) |
| @@ -409,6 +431,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -409,6 +431,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 409 | end | 431 | end |
| 410 | 432 | ||
| 411 | should 'not ask_to_join if environment say no even if its not logged and in a community' do | 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 | e = Environment.default | 436 | e = Environment.default |
| 413 | e.stubs(:enabled?).with(:join_community_popup).returns(false) | 437 | e.stubs(:enabled?).with(:join_community_popup).returns(false) |
| 414 | stubs(:environment).returns(e) | 438 | stubs(:environment).returns(e) |
| @@ -419,6 +443,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -419,6 +443,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 419 | end | 443 | end |
| 420 | 444 | ||
| 421 | should 'not ask_to_join if environment say no even if user say so' do | 445 | should 'not ask_to_join if environment say no even if user say so' do |
| 446 | + stubs(:params).returns({}) | ||
| 447 | + | ||
| 422 | e = Environment.default | 448 | e = Environment.default |
| 423 | e.stubs(:enabled?).with(:join_community_popup).returns(false) | 449 | e.stubs(:enabled?).with(:join_community_popup).returns(false) |
| 424 | stubs(:environment).returns(e) | 450 | stubs(:environment).returns(e) |
| @@ -433,6 +459,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -433,6 +459,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 433 | end | 459 | end |
| 434 | 460 | ||
| 435 | should 'not ask_to_join if its recorded in the session' do | 461 | should 'not ask_to_join if its recorded in the session' do |
| 462 | + stubs(:params).returns({}) | ||
| 463 | + | ||
| 436 | e = Environment.default | 464 | e = Environment.default |
| 437 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 465 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 438 | stubs(:environment).returns(e) | 466 | stubs(:environment).returns(e) |
| @@ -446,6 +474,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -446,6 +474,8 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 446 | end | 474 | end |
| 447 | 475 | ||
| 448 | should 'not ask_to_join if its recorded in the session even for authenticated users' do | 476 | should 'not ask_to_join if its recorded in the session even for authenticated users' do |
| 477 | + stubs(:params).returns({}) | ||
| 478 | + | ||
| 449 | e = Environment.default | 479 | e = Environment.default |
| 450 | e.stubs(:enabled?).with(:join_community_popup).returns(true) | 480 | e.stubs(:enabled?).with(:join_community_popup).returns(true) |
| 451 | stubs(:environment).returns(e) | 481 | stubs(:environment).returns(e) |
test/unit/people_block_test.rb
| @@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase | @@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase | ||
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | should 'list people' do | 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 | block = PeopleBlock.new | 29 | block = PeopleBlock.new |
| 31 | block.expects(:owner).returns(owner).at_least_once | 30 | block.expects(:owner).returns(owner).at_least_once |
| 32 | block.content | 31 | block.content |
| @@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase | @@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase | ||
| 41 | instance_eval(&block.footer) | 40 | instance_eval(&block.footer) |
| 42 | end | 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 | end | 52 | end |
test/unit/profile_list_block_test.rb
| @@ -24,7 +24,7 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -24,7 +24,7 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
| 24 | person2 = create_user('testperson2').person | 24 | person2 = create_user('testperson2').person |
| 25 | person3 = create_user('testperson3').person | 25 | person3 = create_user('testperson3').person |
| 26 | 26 | ||
| 27 | - owner = create_user('mytestuser').person | 27 | + owner = Environment.create!(:name => 'test env') |
| 28 | block = ProfileListBlock.new | 28 | block = ProfileListBlock.new |
| 29 | owner.boxes.first.blocks << block | 29 | owner.boxes.first.blocks << block |
| 30 | block.save! | 30 | block.save! |
| @@ -68,12 +68,36 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -68,12 +68,36 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
| 68 | end | 68 | end |
| 69 | 69 | ||
| 70 | should 'provide view_title' do | 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 | end | 76 | end |
| 74 | 77 | ||
| 75 | should 'provide view title with variables' do | 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 | end | 102 | end |
| 79 | end | 103 | end |
vendor/plugins/access_control/lib/role.rb
| @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base | @@ -32,7 +32,12 @@ class Role < ActiveRecord::Base | ||
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | def kind | 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 | end | 41 | end |
| 37 | 42 | ||
| 38 | def name | 43 | def name |