summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--users/app/controllers/email_aliases_controller.rb25
-rw-r--r--users/app/models/email.rb8
-rw-r--r--users/app/models/user.rb4
-rw-r--r--users/app/views/emails/_email.html.haml3
-rw-r--r--users/config/locales/en.yml1
-rw-r--r--users/config/routes.rb2
6 files changed, 19 insertions, 24 deletions
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
diff --git a/users/config/locales/en.yml b/users/config/locales/en.yml
index d068e70..3c71e7e 100644
--- a/users/config/locales/en.yml
+++ b/users/config/locales/en.yml
@@ -15,6 +15,7 @@ en:
add_email_alias: "Add email alias"
user_updated_successfully: "Settings have been updated successfully."
user_created_successfully: "Successfully created your account."
+ email_alias_destroyed_successfully: "Successfully removed the alias '%{alias}'."
activemodel:
models:
diff --git a/users/config/routes.rb b/users/config/routes.rb
index 3c5fb73..8985502 100644
--- a/users/config/routes.rb
+++ b/users/config/routes.rb
@@ -11,7 +11,7 @@ Rails.application.routes.draw do
get "signup" => "users#new", :as => "signup"
resources :users do
- resources :email_aliases
+ resources :email_aliases, :only => [:destroy], :id => /.*/
end
end