Commit 7afb8e5a75667f08932e8c27178229ac40ccad4f

Authored by Moises Machado
Committed by Antonio Terceiro
1 parent 622183ea

ActionItem959: fixed the "join this group?" popup

it doesn't show if the user already asked to join but was not approved yet
  it stores the "not now" option in the session and is limited to 10 communities
  the "no and don't ask again" button now only show to logged on users
  changed the css to centralize the buttons to box
  changed the css to not break the buttons in half
app/controllers/public/profile_controller.rb
@@ -62,6 +62,13 @@ class ProfileController < PublicController @@ -62,6 +62,13 @@ class ProfileController < PublicController
62 redirect_to profile.url 62 redirect_to profile.url
63 end 63 end
64 64
  65 + def refuse_for_now
  66 + session[:no_asking] ||= []
  67 + session[:no_asking].shift if session[:no_asking].size >= 10
  68 + session[:no_asking] << profile.id
  69 + render :text => '', :layout => false
  70 + end
  71 +
65 protected 72 protected
66 73
67 def check_access_to_profile 74 def check_access_to_profile
app/helpers/application_helper.rb
@@ -245,6 +245,12 @@ module ApplicationHelper @@ -245,6 +245,12 @@ module ApplicationHelper
245 link_to_function(content_tag('span', label), js_code, html_options, &block) 245 link_to_function(content_tag('span', label), js_code, html_options, &block)
246 end 246 end
247 247
  248 + def button_to_remote(type, label, options, html_options = {})
  249 + html_options[:class] = "button with-text" unless html_options[:class]
  250 + html_options[:class] << " icon-#{type}"
  251 + link_to_remote(label, options, html_options)
  252 + end
  253 +
248 def button_to_remote_without_text(type, label, options, html_options = {}) 254 def button_to_remote_without_text(type, label, options, html_options = {})
249 html_options[:class] = "" unless html_options[:class] 255 html_options[:class] = "" unless html_options[:class]
250 html_options[:class] << " button icon-#{type}" 256 html_options[:class] << " button icon-#{type}"
@@ -771,7 +777,10 @@ module ApplicationHelper @@ -771,7 +777,10 @@ module ApplicationHelper
771 def ask_to_join? 777 def ask_to_join?
772 return if environment.enabled?(:disable_join_community_popup) 778 return if environment.enabled?(:disable_join_community_popup)
773 return unless profile && profile.kind_of?(Community) 779 return unless profile && profile.kind_of?(Community)
774 - return true unless logged_in? 780 + unless logged_in?
  781 + return !session[:no_asking].include?(profile.id) if session[:no_asking]
  782 + return true
  783 + end
775 user.ask_to_join?(profile) 784 user.ask_to_join?(profile)
776 end 785 end
777 786
app/models/person.rb
@@ -229,6 +229,7 @@ class Person &lt; Profile @@ -229,6 +229,7 @@ class Person &lt; Profile
229 229
230 def ask_to_join?(community) 230 def ask_to_join?(community)
231 return false if memberships.include?(community) 231 return false if memberships.include?(community)
  232 + return false if AddMember.find(:first, :conditions => {:requestor_id => self.id, :target_id => community.id})
232 !refused_communities.include?(community) 233 !refused_communities.include?(community)
233 end 234 end
234 235
app/views/shared/join_community_popup.rhtml
@@ -7,8 +7,8 @@ @@ -7,8 +7,8 @@
7 <% else %> 7 <% else %>
8 <%= button(:ok, _('Yes'), :controller => 'profile', :action => 'join', :profile => profile.identifier) %> 8 <%= button(:ok, _('Yes'), :controller => 'profile', :action => 'join', :profile => profile.identifier) %>
9 <% end %> 9 <% end %>
10 - <%= button_to_function(:cancel, _('Not now'), "$('join-community-popup').hide()") %>  
11 - <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) %> 10 + <%= button_to_remote(:cancel, _('Not now'), :url => {:controller => 'profile', :action => 'refuse_for_now', :profile => profile.identifier}, :loaded => '$("join-community-popup").hide()') %>
  11 + <%= button(:cancel, _('No and don\'t ask again'), :controller => 'profile', :action => 'refuse_join', :profile => profile.identifier) if logged_in? %>
12 <% end %> 12 <% end %>
13 </div> 13 </div>
14 <%= draggable_element('join-community-popup') %> 14 <%= draggable_element('join-community-popup') %>
public/stylesheets/common.css
@@ -423,15 +423,12 @@ div.pending-tasks { @@ -423,15 +423,12 @@ div.pending-tasks {
423 #join-community-popup { 423 #join-community-popup {
424 z-index: 150; 424 z-index: 150;
425 position: absolute; 425 position: absolute;
426 - width: 350px; 426 + width: 405px;
427 height: 180; 427 height: 180;
428 right: 50px; 428 right: 50px;
429 top: 50px; 429 top: 50px;
430 background: white; 430 background: white;
431 border: 2px solid black; 431 border: 2px solid black;
432 -}  
433 -  
434 -#join-community-popup {  
435 text-align: center; 432 text-align: center;
436 cursor: move; 433 cursor: move;
437 } 434 }
@@ -439,6 +436,10 @@ div.pending-tasks { @@ -439,6 +436,10 @@ div.pending-tasks {
439 margin: 1em; 436 margin: 1em;
440 } 437 }
441 438
  439 +#join-community-popup .button-bar .button {
  440 + float: none;
  441 +}
  442 +
442 #content #not-found, 443 #content #not-found,
443 #content #access-denied { 444 #content #access-denied {
444 padding: 20px; 445 padding: 20px;
test/functional/profile_controller_test.rb
@@ -483,4 +483,20 @@ class ProfileControllerTest &lt; Test::Unit::TestCase @@ -483,4 +483,20 @@ class ProfileControllerTest &lt; Test::Unit::TestCase
483 assert_includes p.refused_communities, community 483 assert_includes p.refused_communities, community
484 end 484 end
485 485
  486 + should 'register in session join refusal' do
  487 + community = Community.create!(:name => 'my test community')
  488 + get :refuse_for_now, :profile => community.identifier
  489 +
  490 + assert_not_nil session[:no_asking]
  491 + assert_includes session[:no_asking], community.id
  492 + end
  493 +
  494 + should 'record only 10 communities in session' do
  495 + @request.session[:no_asking] = (1..10).to_a
  496 + community = Community.create!(:name => 'my test community')
  497 + get :refuse_for_now, :profile => community.identifier
  498 +
  499 + assert_equal ((2..10).to_a + [community.id]), @request.session[:no_asking]
  500 + end
  501 +
486 end 502 end
test/unit/application_helper_test.rb
@@ -420,6 +420,18 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase @@ -420,6 +420,18 @@ class ApplicationHelperTest &lt; Test::Unit::TestCase
420 assert !ask_to_join? 420 assert !ask_to_join?
421 end 421 end
422 422
  423 + should 'not ask_to_join if its recorded in the session' do
  424 + e = Environment.default
  425 + e.stubs(:enabled?).with(:disable_join_community_popup).returns(false)
  426 + stubs(:environment).returns(e)
  427 +
  428 + c = Community.create(:name => 'test_comm', :identifier => 'test_comm')
  429 + stubs(:profile).returns(c)
  430 + stubs(:logged_in?).returns(false)
  431 + stubs(:session).returns({:no_asking => [c.id]})
  432 +
  433 + assert !ask_to_join?
  434 + end
423 435
424 protected 436 protected
425 437
test/unit/person_test.rb
@@ -526,4 +526,12 @@ class PersonTest &lt; Test::Unit::TestCase @@ -526,4 +526,12 @@ class PersonTest &lt; Test::Unit::TestCase
526 assert !p.ask_to_join?(c) 526 assert !p.ask_to_join?(c)
527 end 527 end
528 528
  529 + should 'not ask to join if already asked' do
  530 + p = create_user('test_user').person
  531 + c = Community.create!(:name => 'Test community', :identifier => 'test_community')
  532 + AddMember.create!(:person => p, :organization => c)
  533 +
  534 + assert !p.ask_to_join?(c)
  535 + end
  536 +
529 end 537 end