diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb
index 94a11e9..d0ddacc 100644
--- a/app/controllers/public/invite_controller.rb
+++ b/app/controllers/public/invite_controller.rb
@@ -11,7 +11,7 @@ class InviteController < PublicController
labels = Profile::SEARCHABLE_FIELDS.except(:nickname).merge(User::SEARCHABLE_FIELDS).map { |name,info| info[:label].downcase }
last = labels.pop
label = labels.join(', ')
- @search_friend_fields = "#{label} #{_('or')} #{last}"
+ @search_fields = "#{label} #{_('or')} #{last}"
if request.post?
contact_list = ContactList.create
@@ -78,8 +78,12 @@ class InviteController < PublicController
end
end
- def search_friend
- render :text => find_by_contents(:people, environment, environment.people.not_members_of(profile), params['q'], {:page => 1}, {:joins => :user})[:results].map {|person| {:id => person.id, :name => person.name} }.to_json
+ def search
+ scope = profile.invite_friends_only ? user.friends : environment.people
+ scope = scope.not_members_of(profile) if profile.organization?
+ scope = scope.not_friends_of(profile) if profile.person?
+ results = find_by_contents(:people, environment, scope, params['q'], {:page => 1}, {:joins => :user})[:results]
+ render :text => prepare_to_token_input(results).to_json
end
protected
diff --git a/app/views/friends/index.html.erb b/app/views/friends/index.html.erb
index 312fb0e..10b5f69 100644
--- a/app/views/friends/index.html.erb
+++ b/app/views/friends/index.html.erb
@@ -16,7 +16,7 @@
<%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
<%= button(:search, _('Find people'), :controller => 'search', :action => 'assets', :asset => 'people') %>
<% unless @plugins.dispatch(:remove_invite_friends_button).include?(true) %>
- <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'invite_friends') %>
+ <%= button(:search, _('Invite people'), :controller => 'invite', :action => 'invite_friends') %>
<% end %>
<% end %>
diff --git a/app/views/invite/invite_friends.html.erb b/app/views/invite/invite_friends.html.erb
index 0ae4a6b..3e6b5fd 100644
--- a/app/views/invite/invite_friends.html.erb
+++ b/app/views/invite/invite_friends.html.erb
@@ -1,30 +1,42 @@
<% if profile.person? %>
-
<%= _('Invite your friends') %>
+ <%= _('Ask for friendship') %>
+ <% description = _('You can search for user profiles and ask them to become your friends.') %>
<% else %>
<%= _('Invite your friends to join %s') % profile.name %>
+ <% description = _('You can search for user profiles and invite them to join this group.') %>
<% end %>
-<% if profile.community? %>
- <%= _('Invite registered users') %>
- <%= _('You can search for user profiles and invite them to join this community.') %>
+
+ <%= _("Choose person by:") %>
+
+
+
+ <%= labelled_radio_button _("Name"), :invite_friend_by, 1, true, :id => "invite_friend_by_name", :class => "invite_friend_by" %>
+ <%= labelled_radio_button _("Email"), :invite_friend_by, 2, false, :id => "invite_friend_by_email", :class => "invite_friend_by" %>
+
+
+
+
<%= description %>
<%= form_tag :action => 'invite_registered_friend' do %>
- <% search_action = url_for(:action => 'search_friend') %>
- <%= token_input_field_tag(:q, 'search-friends', search_action,
- { :hint_text => _('Type in your friend\'s %{search_fields}') % {:search_fields => @search_friend_fields},
- :focus => false }) %>
+ <% search_action = url_for(:action => 'search') %>
+ <%= token_input_field_tag(
+ :q, 'search-people', search_action,
+ { :hint_text => _('Type in the person\'s %{search_fields}') % {:search_fields => @search_fields},
+ :focus => false }) %>
<% button_bar do %>
<%= submit_button('save', _('Invite'))%>
<%= button('cancel', _('Cancel'), profile.url)%>
<% end %>
<% end %>
+
-
+
<%= _('Invite people from my e-mail contacts') %>
<% header = 'h3' %>
-<% end %>
-
<%= render :partial => 'invite/select_address_book', :locals => {:header => header} %>
+
+<%= javascript_include_tag 'invite' %>
diff --git a/app/views/profile/friends.html.erb b/app/views/profile/friends.html.erb
index b09826f..7a43ee0 100644
--- a/app/views/profile/friends.html.erb
+++ b/app/views/profile/friends.html.erb
@@ -18,7 +18,7 @@
<%= button :back, _('Go back'), { :controller => 'profile' } %>
<% if user == profile %>
<%= button :edit, _('Manage my friends'), :controller => 'friends', :action => 'index', :profile => profile.identifier %>
- <%= button(:search, _('Invite people from my e-mail contacts'), :controller => 'invite', :action => 'invite_friends') %>
+ <%= button(:search, _('Invite people'), :controller => 'invite', :action => 'invite_friends') %>
<% end %>
<% end %>
diff --git a/features/invitation.feature b/features/invitation.feature
index a1d3dc2..4877e82 100644
--- a/features/invitation.feature
+++ b/features/invitation.feature
@@ -17,25 +17,22 @@ Feature: invitation
Scenario: see link to invite friends
When I am on /profile/josesilva/friends
- Then I should see "Invite people from my e-mail contacts" link
+ Then I should see "Invite people" link
Scenario: see link to invite friends in myprofile
When I am on /myprofile/josesilva/friends
- Then I should see "Invite people from my e-mail contacts" link
+ Then I should see "Invite people" link
Scenario: go to invitation screen when follow link to invite friends
Given I am on /myprofile/josesilva/friends
- When I follow "Invite people from my e-mail contacts"
+ When I follow "Invite people"
Then I am on /profile/josesilva/invite/friends
- Scenario: see title when invite friends
- When I am on /profile/josesilva/invite/friends
- Then I should see "Invite your friends"
-
@selenium
Scenario: back to friends after invite friends
Given I am on /myprofile/josesilva/friends
- And I follow "Invite people from my e-mail contacts"
+ And I follow "Invite people"
+ And I choose "Email"
And I press "Next"
And I fill in "manual_import_addresses" with "misfits@devil.doll"
And I follow "Personalize invitation mail"
@@ -77,7 +74,8 @@ Feature: invitation
@selenium
Scenario: back to members after invite friends to join a community
Given I am on 26 Bsslines's members management
- And I follow "Invite your friends to join 26 Bsslines"
+ And I follow "Invite people"
+ And I choose "Email"
And I press "Next"
And I fill in "manual_import_addresses" with "misfits@devil.doll"
And I follow "Personalize invitation mail"
@@ -88,7 +86,8 @@ Feature: invitation
@selenium
Scenario: noosfero user receives a task when a user invites to join a community
Given I am on 26 Bsslines's members management
- And I follow "Invite your friends to join 26 Bsslines"
+ And I follow "Invite people"
+ And I choose "Email"
And I press "Next"
And I fill in "manual_import_addresses" with "santos@invalid.br"
And I follow "Personalize invitation mail"
@@ -133,7 +132,8 @@ Feature: invitation
Scenario: noosfero user receives a task when a user invites to be friend
Given I am on josesilva's control panel
And I follow "Manage friends"
- And I follow "Invite people from my e-mail contacts"
+ And I follow "Invite people"
+ And I choose "Email"
And I press "Next"
And I fill in "manual_import_addresses" with "santos@invalid.br"
And I follow "Personalize invitation mail"
diff --git a/features/step_definitions/invitation_steps.rb b/features/step_definitions/invitation_steps.rb
index 91bebc9..11d8b31 100644
--- a/features/step_definitions/invitation_steps.rb
+++ b/features/step_definitions/invitation_steps.rb
@@ -2,6 +2,7 @@ Given /^I invite email "(.+)" to join community "(.+)"$/ do |email, community|
identifier = Community.find_by_name(community).identifier
visit("/myprofile/#{identifier}/profile_members")
first(:link, "Invite your friends to join #{community}").click
+ choose("Email")
click_button('Next')
fill_in('manual_import_addresses', :with => "#{email}")
click_link('Personalize invitation mail')
@@ -11,7 +12,8 @@ end
Given /^I invite email "(.+)" to be my friend$/ do |email|
click_link('Manage friends')
- click_link('Invite people from my e-mail contacts')
+ click_link('Invite people')
+ choose("Email")
click_button('Next')
fill_in('manual_import_addresses', :with => "#{email}")
click_link('Personalize invitation mail')
diff --git a/public/javascripts/invite.js b/public/javascripts/invite.js
new file mode 100644
index 0000000..a112c52
--- /dev/null
+++ b/public/javascripts/invite.js
@@ -0,0 +1,52 @@
+(function($){
+ 'use strict';
+
+ function toggle_invitation_method() {
+ if (+(this.value) === 1) {
+ $('.invite_by_email').hide();
+ $('.invite_by_name').show();
+ } else {
+ $('.invite_by_name').hide();
+ $('.invite_by_email').show();
+ }
+ }
+
+ function manage_members_moderation() {
+ var checked = $('#profile_data_allow_members_to_invite').is(':checked');
+
+ if (checked) {
+ $('.invite_friends_only').show();
+ } else {
+ $('.invite_friends_only').hide();
+ }
+ }
+
+ function hide_invite_friend_login_password() {
+ $('#invite-friends-login-password').hide();
+ }
+
+ function show_invite_friend_login_password() {
+ if (this.value === 'hotmail') {
+ $('#hotmail_username_tip').show();
+ } else {
+ $('#hotmail_username_tip').hide();
+ }
+
+ $('#invite-friends-login-password').show();
+ $('#login').focus();
+ }
+
+ $(document).ready(function() {
+ $('.invite_by_email').hide();
+ manage_members_moderation();
+
+ // Event triggers
+ $('.invite_friend_by').click(toggle_invitation_method);
+
+ $("#import_from_manual").click(hide_invite_friend_login_password);
+
+ $('.invite_by_this_email').click(show_invite_friend_login_password);
+
+ $('#profile_data_allow_members_to_invite').click(manage_members_moderation);
+ });
+})(jQuery);
diff --git a/test/functional/invite_controller_test.rb b/test/functional/invite_controller_test.rb
index 49653fa..dfc1571 100644
--- a/test/functional/invite_controller_test.rb
+++ b/test/functional/invite_controller_test.rb
@@ -101,7 +101,6 @@ class InviteControllerTest < ActionController::TestCase
should 'display invitation page' do
get :invite_friends, :profile => profile.identifier
assert_response :success
- assert_tag :tag => 'h1', :content => 'Invite your friends'
end
should 'get mail template to invite members' do
@@ -243,18 +242,18 @@ class InviteControllerTest < ActionController::TestCase
friend1.save
friend2.save
- get :search_friend, :profile => profile.identifier, :q => 'me@'
+ get :search, :profile => profile.identifier, :q => 'me@'
assert_equal 'text/html', @response.content_type
assert_equal [{"id" => friend2.id, "name" => friend2.name}].to_json, @response.body
- get :search_friend, :profile => profile.identifier, :q => 'cri'
+ get :search, :profile => profile.identifier, :q => 'cri'
assert_equal [{"id" => friend1.id, "name" => friend1.name}].to_json, @response.body
- get :search_friend, :profile => profile.identifier, :q => 'will'
+ get :search, :profile => profile.identifier, :q => 'will'
- assert_equal [{"id" => friend1.id, "name" => friend1.name}, {"id" => friend2.id, "name" => friend2.name}].to_json, @response.body
+ assert_equivalent [{"id" => friend1.id, "name" => friend1.name}, {"id" => friend2.id, "name" => friend2.name}], json_response
end
should 'not include members in search friends profiles' do
@@ -266,11 +265,25 @@ class InviteControllerTest < ActionController::TestCase
community.add_member(friend2)
- get :search_friend, :profile => community.identifier, :q => 'will'
+ get :search, :profile => community.identifier, :q => 'will'
assert_equivalent [{"name" => friend1.name, "id" => friend1.id}], json_response
end
+ should 'not include friends in search for people to request friendship' do
+ friend1 = create_user('willy').person
+ friend2 = create_user('william').person
+
+ profile.add_friend friend1
+ friend1.add_friend profile
+ profile.add_friend friend2
+ friend2.add_friend profile
+
+ get :search, :profile => profile.identifier, :q => 'will'
+
+ assert_empty json_response
+ end
+
should 'invite registered users through profile id' do
friend1 = create_user('testuser1').person
friend2 = create_user('testuser2').person
--
libgit2 0.21.2