summaryrefslogtreecommitdiff
path: root/users/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-07-19 11:09:25 +0200
committerAzul <azul@leap.se>2013-07-24 10:55:51 +0200
commit8ddbaa6184e4dbcc6ef7e81cf555cc18d3822dce (patch)
tree2fd33652e8cf96b645d58a83822258c5673f2045 /users/app/models
parentb6242bbefc1e9fe193bbf3479e8fa822829c6d1a (diff)
support deprecated API to set users main identity pgp key
We'll want to get rid of the #public_key and #public_key= functions but they are still used from the users controller. We'll probably have an identity controller instead at some point.
Diffstat (limited to 'users/app/models')
-rw-r--r--users/app/models/user.rb44
1 files changed, 39 insertions, 5 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index fb7f0aa..546d571 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -6,8 +6,6 @@ class User < CouchRest::Model::Base
property :password_verifier, String, :accessible => true
property :password_salt, String, :accessible => true
- property :public_key, :accessible => true
-
property :enabled, TrueClass, :default => true
validates :login, :password_salt, :password_verifier,
@@ -49,14 +47,50 @@ class User < CouchRest::Model::Base
view :by_created_at
end # end of design
+ # We proxy access to the pgp_key. So we need to make sure
+ # the updated identity actually gets saved.
+ def save(*args)
+ super
+ identity.user_id ||= self.id
+ identity.save if identity.changed?
+ end
+
+ # So far this only works for creating a new user.
+ # TODO: Create an alias for the old login when changing the login
+ def login=(value)
+ write_attribute 'login', value
+ @identity = build_identity
+ end
+
+ # DEPRECATED
+ #
+ # Please access identity.keys[:pgp] directly
+ def public_key=(value)
+ identity.keys[:pgp] = value
+ end
+
+ # DEPRECATED
+ #
+ # Please access identity.keys[:pgp] directly
+ def public_key
+ identity.keys[:pgp]
+ end
+
class << self
alias_method :find_by_param, :find
end
+ # this is the main identity. login@domain.tld
+ # aliases and forwards are represented in other identities.
+ def identity
+ @identity ||=
+ Identity.find_by_address_and_destination([email_address, email_address])
+ end
+
def create_identity(attribs = {}, &block)
- identity = build_identity(attribs, &block)
- identity.save
- identity
+ new_identity = build_identity(attribs, &block)
+ new_identity.save
+ new_identity
end
def build_identity(attribs = {}, &block)