Commit 143be35beccbae314571210248e39936f5b4470c
1 parent
fad353e4
Exists in
master
and in
22 other branches
StoaPlugin invitation checking for user usp_id instead of profile
Showing
3 changed files
with
41 additions
and
2 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin.rb
| ... | ... | @@ -107,14 +107,14 @@ class StoaPlugin < Noosfero::Plugin |
| 107 | 107 | def invite_controller_filters |
| 108 | 108 | [{ :type => 'before_filter', |
| 109 | 109 | :method_name => 'check_usp_id_existence', |
| 110 | - :block => lambda {render_access_denied if profile.usp_id.blank?} }] | |
| 110 | + :block => lambda {render_access_denied if !user || user.usp_id.blank?} }] | |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | 113 | def control_panel_buttons |
| 114 | 114 | { :title => _('Invite friends'), |
| 115 | 115 | :icon => 'invite-friends', |
| 116 | 116 | :url => {:controller => 'invite', |
| 117 | - :action => 'select_address_book'} } if !context.profile.usp_id.blank? | |
| 117 | + :action => 'select_address_book'} } if context.send(:user) && context.send(:user).usp_id.present? | |
| 118 | 118 | end |
| 119 | 119 | |
| 120 | 120 | def remove_invite_friends_button | ... | ... |
plugins/stoa/test/functional/invite_controller_test.rb
| ... | ... | @@ -36,5 +36,17 @@ class InviteControllerTest < ActionController::TestCase |
| 36 | 36 | assert_response 200 |
| 37 | 37 | end |
| 38 | 38 | |
| 39 | + should 'alow invitation even in organizations' do | |
| 40 | + person_with_usp_id = User.create!(:login => 'user-with', :email => 'user-with@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:usp_id => 12345678}).person | |
| 41 | + organization = fast_create(Organization) | |
| 42 | + organization.add_admin(person_with_usp_id) | |
| 43 | + | |
| 44 | + login_as(person_with_usp_id.identifier) | |
| 45 | + get :select_address_book, :profile => organization.identifier | |
| 46 | + assert_response 200 | |
| 47 | + get :select_friends, :profile => organization.identifier, :contact_list => ContactList.create.id | |
| 48 | + assert_response 200 | |
| 49 | + end | |
| 50 | + | |
| 39 | 51 | end |
| 40 | 52 | ... | ... |
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
| 2 | + | |
| 3 | +class StoaPluginTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @plugin = StoaPlugin.new | |
| 7 | + end | |
| 8 | + | |
| 9 | + attr_reader :plugin | |
| 10 | + | |
| 11 | + should 'display invite control panel button only to users with usp_id' do | |
| 12 | + person_with_usp_id = fast_create(Person, :usp_id => 99999999) | |
| 13 | + person_without_usp_id = fast_create(Person) | |
| 14 | + context = mock() | |
| 15 | + StoaPlugin.any_instance.stubs(:context).returns(context) | |
| 16 | + | |
| 17 | + context.stubs(:user).returns(nil) | |
| 18 | + assert_nil plugin.control_panel_buttons | |
| 19 | + | |
| 20 | + context.stubs(:user).returns(person_without_usp_id) | |
| 21 | + assert_nil plugin.control_panel_buttons | |
| 22 | + | |
| 23 | + context.stubs(:user).returns(person_with_usp_id) | |
| 24 | + assert_not_nil plugin.control_panel_buttons | |
| 25 | + end | |
| 26 | +end | |
| 27 | + | ... | ... |