summaryrefslogtreecommitdiff
path: root/users/app/models/identity.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-18 17:17:36 +0200
committerAzul <azul@leap.se>2013-07-24 10:55:51 +0200
commit0acace58c31c96fc1f8836167aeb4f204f72617f (patch)
tree4738cf2fab5f67afdcdae7373914b9bd66cfd95e /users/app/models/identity.rb
parentd96fac2de074bbe3a44d888af5ceaff45b1b9b27 (diff)
allow available and unique forwards only
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