Commit 78f01eb33a76bd3670c807ef1adb8de5cb7281af
Committed by
Antonio Terceiro
1 parent
76ed1894
Exists in
master
and in
29 other branches
ActionItem1247: enhancements on join popup
* when a not logged user asks to join a community,
should redirect to page where the user was after login
* should not show join_community_popup when in action join
Showing
4 changed files
with
70 additions
and
1 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 |
| @@ -55,7 +56,7 @@ class ProfileController < PublicController | @@ -55,7 +56,7 @@ class ProfileController < PublicController | ||
| 55 | if @wizard | 56 | if @wizard |
| 56 | redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true | 57 | redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true |
| 57 | else | 58 | else |
| 58 | - redirect_back_or_default profile.url | 59 | + redirect_to_before_join |
| 59 | end | 60 | end |
| 60 | else | 61 | else |
| 61 | store_location(request.referer) | 62 | store_location(request.referer) |
| @@ -104,6 +105,20 @@ class ProfileController < PublicController | @@ -104,6 +105,20 @@ class ProfileController < PublicController | ||
| 104 | end | 105 | end |
| 105 | end | 106 | end |
| 106 | 107 | ||
| 108 | + def store_before_join | ||
| 109 | + session[:before_join] = request.referer unless logged_in? | ||
| 110 | + end | ||
| 111 | + | ||
| 112 | + def redirect_to_before_join | ||
| 113 | + back = session[:before_join] | ||
| 114 | + if back | ||
| 115 | + session[:before_join] = nil | ||
| 116 | + redirect_to back | ||
| 117 | + else | ||
| 118 | + redirect_back_or_default profile.url | ||
| 119 | + end | ||
| 120 | + end | ||
| 121 | + | ||
| 107 | def per_page | 122 | def per_page |
| 108 | Noosfero::Constants::PROFILE_PER_PAGE | 123 | Noosfero::Constants::PROFILE_PER_PAGE |
| 109 | end | 124 | 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 |
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/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) |