summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-11-05 17:03:55 +0100
committerAzul <azul@leap.se>2013-11-05 17:03:55 +0100
commit4a2490cc5eac1803be80fade65bbe9d32fa0bd9b (patch)
tree0d7ef7845fc9be03ac03576d7691f07c827e6669 /users/app
parent99ecdbf71632970d4c83f99beea325e5d213e4c6 (diff)
Identity.destroy_all_disabled will clean up disabled identities
This is mostly for cleaning up after tests so far. But we might expand this to destroy all identities disabled before a certain date.
Diffstat (limited to 'users/app')
-rw-r--r--users/app/models/identity.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index 40ce4ae..97966d0 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -27,6 +27,17 @@ class Identity < CouchRest::Model::Base
emit(doc.address, doc.keys["pgp"]);
}
EOJS
+ view :disabled,
+ map: <<-EOJS
+ function(doc) {
+ if (doc.type != 'Identity') {
+ return;
+ }
+ if (typeof doc.user_id === "undefined") {
+ emit(doc._id, 1);
+ }
+ }
+ EOJS
end
@@ -57,6 +68,12 @@ class Identity < CouchRest::Model::Base
end
end
+ def self.destroy_all_disabled
+ Identity.disabled.each do |identity|
+ identity.destroy
+ end
+ end
+
def self.attributes_from_user(user)
{ user_id: user.id,
address: user.email_address,