From 0e9c41a286b49b5ce52abcf0e014668d0167bbae Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 7 Jul 2014 10:05:37 +0200 Subject: store expiry with cert fingerprints We used to store the creation date but this way it's easier to query for non expired certs --- app/models/identity.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/identity.rb') diff --git a/app/models/identity.rb b/app/models/identity.rb index eb67b1b..1d69437 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -146,9 +146,9 @@ class Identity < CouchRest::Model::Base end def register_cert(cert) - today = DateTime.now.to_date.to_s + expiry = cert.expiry.to_data.to_s write_attribute 'cert_fingerprints', - cert_fingerprints.merge(cert.fingerprint => today) + cert_fingerprints.merge(cert.fingerprint => expiry) end # for LoginFormatValidation -- cgit v1.2.3 From cc1666d9832415058bf0b22bb5912e432261af4f Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 7 Jul 2014 10:12:53 +0200 Subject: Identity view cert_fingerprints_by_expiry Also move complex identity views into js designs. Includes test. Here's how you would query it from outside rails: ``` $ curl 'localhost:5984/identities/_design/Identity/_view/cert_fingerprints_by_expiry?startkey="2014-07-05"' {"total_rows":4,"offset":1,"rows":[ {"id":"6c9091d4f13eaeaa6062c9d0528fd34d","key":"2014-07-05","value":"fingerprint"}, {"id":"6f3aa93828b4f6978d551f2623b9d103","key":"2014-07-05","value":"fingerprint"}, {"id":"b6cafacfa65042679691cd5065fb19e3","key":"2014-07-07","value":"fp"} ]} ``` Note that the expiry will be used as the key. So you should use the current data (or yesterday) as the startkey to get all fingerprints that have not expired yet. The fingerprint itself is in the value. No need to include docs. --- app/models/identity.rb | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'app/models/identity.rb') diff --git a/app/models/identity.rb b/app/models/identity.rb index 1d69437..9dc9c7a 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -18,32 +18,11 @@ class Identity < CouchRest::Model::Base validate :destination_email design do + own_path = Pathname.new(File.dirname(__FILE__)) + load_views(own_path.join('..', 'designs', 'identity'), nil) view :by_user_id view :by_address_and_destination view :by_address - view :pgp_key_by_email, - map: <<-EOJS - function(doc) { - if (doc.type != 'Identity') { - return; - } - if (typeof doc.keys === "object") { - 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 def self.address_starts_with(query) @@ -146,7 +125,7 @@ class Identity < CouchRest::Model::Base end def register_cert(cert) - expiry = cert.expiry.to_data.to_s + expiry = cert.expiry.to_date.to_s write_attribute 'cert_fingerprints', cert_fingerprints.merge(cert.fingerprint => expiry) end -- cgit v1.2.3