From 8ddbaa6184e4dbcc6ef7e81cf555cc18d3822dce Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 19 Jul 2013 11:09:25 +0200 Subject: 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. --- users/app/models/user.rb | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'users/app/models/user.rb') 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) -- cgit v1.2.3