From b90ce01890907d1c7f46f46bafcef416570a4c4b Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Dec 2012 17:48:39 +0100 Subject: enabled destroying email aliases - no ajax yet. --- users/app/controllers/email_aliases_controller.rb | 25 +++-------------------- users/app/models/email.rb | 8 ++++++++ users/app/models/user.rb | 4 ++++ users/app/views/emails/_email.html.haml | 3 ++- 4 files changed, 17 insertions(+), 23 deletions(-) (limited to 'users/app') diff --git a/users/app/controllers/email_aliases_controller.rb b/users/app/controllers/email_aliases_controller.rb index 751df85..3b0d5ac 100644 --- a/users/app/controllers/email_aliases_controller.rb +++ b/users/app/controllers/email_aliases_controller.rb @@ -4,29 +4,10 @@ class EmailAliasesController < ApplicationController respond_to :html - # get a list of email aliases for the given user? - def index - @aliases = @user.email_aliases - respond_with @aliases - end - - def create - @alias = @user.add_email_alias(params[:email_alias]) - flash[:notice] = t(:email_alias_created_successfully) unless @alias.errors - respond_with @alias, :location => edit_user_path(@user, :anchor => :email) - end - - def update - @alias = @user.get_email_alias(params[:id]) - @alias.set_email(params[:email_alias]) - flash[:notice] = t(:email_alias_updated_successfully) unless @alias.errors - respond_with @alias, :location => edit_user_path(@user, :anchor => :email) - end - def destroy - @alias = @user.get_email_alias(params[:id]) - flash[:notice] = t(:email_alias_destroyed_successfully) - @alias.destroy + @alias = @user.email_aliases.delete(params[:id]) + @user.save + flash[:notice] = t(:email_alias_destroyed_successfully, :alias => @alias) redirect_to edit_user_path(@user, :anchor => :email) end diff --git a/users/app/models/email.rb b/users/app/models/email.rb index 4b01838..0745fda 100644 --- a/users/app/models/email.rb +++ b/users/app/models/email.rb @@ -14,4 +14,12 @@ class Email def to_s email end + + def ==(other) + other.is_a?(String) ? self.email == other : super + end + + def to_param + email + end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 10f358d..d66b0e9 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -45,6 +45,7 @@ class User < CouchRest::Model::Base view :by_login view :by_created_at view :by_email + view :by_email_alias, :map => <<-EOJS function(doc) { @@ -56,6 +57,7 @@ class User < CouchRest::Model::Base }); } EOJS + view :by_email_or_alias, :map => <<-EOJS function(doc) { @@ -70,6 +72,7 @@ class User < CouchRest::Model::Base }); } EOJS + end class << self @@ -127,6 +130,7 @@ class User < CouchRest::Model::Base end end + ## # Validation Functions ## diff --git a/users/app/views/emails/_email.html.haml b/users/app/views/emails/_email.html.haml index f182ed9..f5eb2d0 100644 --- a/users/app/views/emails/_email.html.haml +++ b/users/app/views/emails/_email.html.haml @@ -1,4 +1,5 @@ %li.pull-right %code= email - %i.icon-remove + = link_to(user_email_alias_path(@user, email), :method => :delete) do + %i.icon-remove .clearfix -- cgit v1.2.3