noosfero | 2 new commits pushed to repository

Leandro Nunes gitlab at gitlab.com
Thu Jan 22 11:52:54 BRST 2015


Leandro Nunes pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/2006ce6e91b322c1cd6e12f2e86667304ecf35fc">2006ce6e</a> by Victor Costa
Fix creation of tasks to invite registered users

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/358e1f31c396944ed8689f70a493e076f295164a">358e1f31</a> by Leandro Nunes
Merge branch 'fix_task_invitation' into 'master'

Fix invitation tasks

Fix creation of tasks to invite already registered users

See merge request !399

- - - - -


Changes:

=====================================
app/models/invitation.rb
=====================================
--- a/app/models/invitation.rb
+++ b/app/models/invitation.rb
@@ -65,18 +65,16 @@ class Invitation < Task
 
       task_args = if user.nil?
         {:person => person, :friend_name => friend_name, :friend_email => friend_email, :message => message}
-      elsif !user.person.is_a_friend?(person)
+      else
         {:person => person, :target => user.person}
       end
 
-      if !task_args.nil?
-        if profile.person?
-          InviteFriend.create(task_args)
-        elsif profile.community?
-          InviteMember.create(task_args.merge(:community_id => profile.id))
-        else
-          raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s
-        end
+      if profile.person?
+        InviteFriend.create(task_args) if user.nil? || !user.person.is_a_friend?(person)
+      elsif profile.community?
+        InviteMember.create(task_args.merge(:community_id => profile.id)) if user.nil? || !user.person.is_member_of?(profile)
+      else
+        raise NotImplementedError, 'Don\'t know how to invite people to a %s' % profile.class.to_s
       end
     end
   end

=====================================
test/unit/invitation_test.rb
=====================================
--- a/test/unit/invitation_test.rb
+++ b/test/unit/invitation_test.rb
@@ -60,6 +60,19 @@ class InvitationTest < ActiveSupport::TestCase
     end
   end
 
+  should 'not create task if the invited member is already a member of the community' do
+    person = fast_create(Person)
+    person.user = User.new(:email => 'current_user at email.invalid')
+    community = fast_create(Community)
+    user_to_invite = fast_create(User, :email => 'person_to_invite at email.invalid')
+    person_to_invite = fast_create(Person, :user_id => user_to_invite.id)
+    community.add_member(person_to_invite)
+
+    assert_no_difference 'InviteMember.count' do
+      Invitation.invite(person, ['person_to_invite at email.invalid'], 'hello friend <url>', community)
+    end
+  end
+
   should 'not crash if the invited friend is already your friend in the environment' do
     person = create_user('person').person
     invited_friend = create_user('invited_friend').person

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150122/d1da12eb/attachment.html>


More information about the Noosfero-dev mailing list