summaryrefslogtreecommitdiff
path: root/users/app/models/identity.rb
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/models/identity.rb')
-rw-r--r--users/app/models/identity.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index c9c8b73..4dff93a 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -7,7 +7,29 @@ class Identity < CouchRest::Model::Base
property :address, LocalEmail
property :destination, Email
+ validate :unique_forward
+ validate :alias_available
+
design do
view :by_user_id
+ view :by_address_and_destination
+ view :by_address
+ end
+
+ protected
+
+ def unique_forward
+ same = Identity.find_by_address_and_destination([address, destination])
+ if same && same != self
+ errors.add :base, "This alias already exists"
+ end
end
+
+ def alias_available
+ same = Identity.find_by_address(address)
+ if same && same.user != self.user
+ errors.add :base, "This email has already been taken"
+ end
+ end
+
end