made the checking for already connected more explicit. also, the check itself had a bug when we were calling self.to_id on a request, rather than self.to.id
This commit is contained in:
parent
2c22941e2f
commit
e0efaa6317
2 changed files with 15 additions and 5 deletions
|
|
@ -13,5 +13,4 @@ module RequestsHelper
|
||||||
link_to t('new_requests', :count => @request_count), aspects_manage_path
|
link_to t('new_requests', :count => @request_count), aspects_manage_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ class Request
|
||||||
key :sent, Boolean, :default => false
|
key :sent, Boolean, :default => false
|
||||||
|
|
||||||
validates_presence_of :from, :to
|
validates_presence_of :from, :to
|
||||||
validate :not_already_connected, :if => :sent
|
validate :not_already_connected_if_sent
|
||||||
|
validate :not_already_connected_if_not_sent
|
||||||
validate :no_pending_request, :if => :sent
|
validate :no_pending_request, :if => :sent
|
||||||
|
|
||||||
#before_validation :clean_link
|
#before_validation :clean_link
|
||||||
|
|
@ -91,9 +92,19 @@ class Request
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_already_connected
|
def not_already_connected_if_sent
|
||||||
if Contact.first(:user_id => self.from.owner_id, :person_id => self.to_id)
|
if self.sent
|
||||||
|
if Contact.first(:user_id => self.from.owner_id, :person_id => self.to.id)
|
||||||
errors[:base] << 'You have already connected to this person!'
|
errors[:base] << 'You have already connected to this person!'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def not_already_connected_if_not_sent
|
||||||
|
unless self.sent
|
||||||
|
if Contact.first(:user_id => self.to.owner_id, :person_id => self.from.id)
|
||||||
|
errors[:base] << 'You have already connected to this person!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue