diff options
author | Azul <azul@leap.se> | 2012-12-13 17:16:05 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-12-13 17:16:05 +0100 |
commit | 32db6e2ee3ae449f2fe0f947f9ac4aafde340a9d (patch) | |
tree | 1f9abefddc5f3cfb49a96f87e184a78feb8fb506 /users/app/controllers/email_aliases_controller.rb | |
parent | 1a26988cb7ff30061473f4a781166b184b3037ce (diff) | |
parent | feee17e3a9970ac04f5a789255fbf4c3e8e89eb8 (diff) |
Merge branch 'feature/email-aliases-model'
Diffstat (limited to 'users/app/controllers/email_aliases_controller.rb')
-rw-r--r-- | users/app/controllers/email_aliases_controller.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/users/app/controllers/email_aliases_controller.rb b/users/app/controllers/email_aliases_controller.rb new file mode 100644 index 0000000..751df85 --- /dev/null +++ b/users/app/controllers/email_aliases_controller.rb @@ -0,0 +1,39 @@ +class EmailAliasesController < ApplicationController + + before_filter :fetch_user + + 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 + redirect_to edit_user_path(@user, :anchor => :email) + end + + protected + + def fetch_user + @user = User.find_by_param(params[:user_id]) + access_denied unless admin? or (@user == current_user) + end +end |