summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-11-05 12:12:13 +0100
committerAzul <azul@leap.se>2013-11-05 12:15:08 +0100
commit99ecdbf71632970d4c83f99beea325e5d213e4c6 (patch)
tree6e57e8d24fe1c5a07e90c9e9203ff13580848077 /users/app/models
parentb4ca13257341792f5e6496264c421af1888bcdb8 (diff)
disabled identities to block handles after a user was deleted
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/identity.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index c24af73..40ce4ae 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -53,6 +53,7 @@ class Identity < CouchRest::Model::Base
def self.disable_all_for(user)
Identity.by_user_id.key(user.id).each do |identity|
identity.disable
+ identity.save
end
end
@@ -63,11 +64,14 @@ class Identity < CouchRest::Model::Base
}
end
- #
- # about to change towards actually disabling the identity instead of
- # destroying it.
- #
- alias_method :disable, :destroy
+ def enabled?
+ self.destination && self.user_id
+ end
+
+ def disable
+ self.destination = nil
+ self.user_id = nil
+ end
def keys
read_attribute('keys') || HashWithIndifferentAccess.new
@@ -105,7 +109,8 @@ class Identity < CouchRest::Model::Base
end
def destination_email
- return if destination.valid? #this ensures it is Email
+ return if destination.nil? # this identity is disabled
+ return if destination.valid? # this ensures it is Email
self.errors.add(:destination, destination.errors.messages[:email].first) #assumes only one error #TODO
end