Commit 78f01eb33a76bd3670c807ef1adb8de5cb7281af

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 76ed1894

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
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
... ... @@ -55,7 +56,7 @@ class ProfileController < PublicController
55 56 if @wizard
56 57 redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true
57 58 else
58   - redirect_back_or_default profile.url
  59 + redirect_to_before_join
59 60 end
60 61 else
61 62 store_location(request.referer)
... ... @@ -104,6 +105,20 @@ class ProfileController < PublicController
104 105 end
105 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 122 def per_page
108 123 Noosfero::Constants::PROFILE_PER_PAGE
109 124 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
... ...
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/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)
... ...