Commit 8a9f60878a3001c10986556b22ef2a2e8ab43b76
Committed by
Antonio Terceiro
1 parent
cfd92ee4
Exists in
master
and in
29 other branches
ActionItem1162: not want be a friend of myself
Showing
3 changed files
with
24 additions
and
0 deletions
Show diff stats
app/models/invite_friend.rb
... | ... | @@ -22,6 +22,14 @@ class InviteFriend < Task |
22 | 22 | TaskMailer.deliver_invitation_notification(task) unless task.friend |
23 | 23 | end |
24 | 24 | |
25 | + def validate | |
26 | + super | |
27 | + friendemail = friend ? friend.user.email : friend_email | |
28 | + if person && friendemail && person.user.email == friendemail | |
29 | + self.errors.add_to_base(_("You can't invite youself")) | |
30 | + end | |
31 | + end | |
32 | + | |
25 | 33 | def perform |
26 | 34 | requestor.add_friend(target, group_for_person) |
27 | 35 | target.add_friend(requestor, group_for_friend) | ... | ... |
test/functional/friends_controller_test.rb
... | ... | @@ -151,4 +151,10 @@ class FriendsControllerTest < Test::Unit::TestCase |
151 | 151 | end |
152 | 152 | end |
153 | 153 | |
154 | + should 'not invite yourself' do | |
155 | + assert_no_difference InviteFriend, :count do | |
156 | + post :invite, :manual_import_addresses => "#{profile.name} <#{profile.user.email}>", :import_from => "manual", :message => "click: <url>", :confirmation => 1, :wizard => true | |
157 | + end | |
158 | + end | |
159 | + | |
154 | 160 | end | ... | ... |
test/unit/invite_friend_test.rb
... | ... | @@ -137,4 +137,14 @@ class InviteFriendTest < ActiveSupport::TestCase |
137 | 137 | assert_equal :manage_friends, t.permission |
138 | 138 | end |
139 | 139 | |
140 | + should 'not invite yourself' do | |
141 | + p = create_user('testuser1').person | |
142 | + | |
143 | + task1 = InviteFriend.new(:person => p, :friend => p, :message => 'click here: <url>') | |
144 | + assert !task1.save | |
145 | + | |
146 | + task2 = InviteFriend.new(:person => p, :friend_name => 'Myself', :friend_email => p.user.email, :message => 'click here: <url>') | |
147 | + assert !task2.save | |
148 | + end | |
149 | + | |
140 | 150 | end | ... | ... |