From 4dffda05477f74c90197948bb6f13bedc8b2a19f Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 9 Dec 2012 10:52:23 +0100 Subject: first steps towards email aliases * unit tests draft * controller draft --- users/app/controllers/email_alias_controller.rb | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 users/app/controllers/email_alias_controller.rb (limited to 'users/app/controllers') diff --git a/users/app/controllers/email_alias_controller.rb b/users/app/controllers/email_alias_controller.rb new file mode 100644 index 0000000..979c8ad --- /dev/null +++ b/users/app/controllers/email_alias_controller.rb @@ -0,0 +1,36 @@ +class EmailAliasesController < ApplicationController + + before_filter :fetch_user + + # 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 + 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 + end + + def destroy + @alias = @user.get_email_alias(params[:id]) + flash[:notice] = t(:email_alias_destroyed_successfully) + @alias.destroy + end + + protected + + def fetch_user + @user = User.find_by_param(params[:user_id]) + access_denied unless admin? or (@user == current_user) + end +end -- cgit v1.2.3 From 9d99d340cfd3c55f21d38c1ba9f3f4574e40c46c Mon Sep 17 00:00:00 2001 From: Azul Date: Sun, 9 Dec 2012 13:19:54 +0100 Subject: basic form added to user settings, simple model created --- users/app/controllers/email_alias_controller.rb | 36 --------------------- users/app/controllers/email_aliases_controller.rb | 39 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 36 deletions(-) delete mode 100644 users/app/controllers/email_alias_controller.rb create mode 100644 users/app/controllers/email_aliases_controller.rb (limited to 'users/app/controllers') diff --git a/users/app/controllers/email_alias_controller.rb b/users/app/controllers/email_alias_controller.rb deleted file mode 100644 index 979c8ad..0000000 --- a/users/app/controllers/email_alias_controller.rb +++ /dev/null @@ -1,36 +0,0 @@ -class EmailAliasesController < ApplicationController - - before_filter :fetch_user - - # 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 - 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 - end - - def destroy - @alias = @user.get_email_alias(params[:id]) - flash[:notice] = t(:email_alias_destroyed_successfully) - @alias.destroy - end - - protected - - def fetch_user - @user = User.find_by_param(params[:user_id]) - access_denied unless admin? or (@user == current_user) - end -end 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 -- cgit v1.2.3 From e4c7f2fb8fa2833037508f1b88f802944855fd77 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Dec 2012 10:38:48 +0100 Subject: actually allow adding email aliases --- users/app/controllers/users_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'users/app/controllers') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 4921a4a..5055f4e 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -30,7 +30,8 @@ class UsersController < ApplicationController end def update - if @user.update_attributes(params[:user]) + @user.attributes = params[:user] + if @user.changed? and @user.save flash[:notice] = t(:user_updated_successfully) end respond_with @user, :location => edit_user_path(@user) -- cgit v1.2.3 From d9fa19106998bc6ac484494334dcf150bb6aa5d5 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Dec 2012 20:16:26 +0100 Subject: email format validations --- users/app/controllers/users_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'users/app/controllers') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 5055f4e..811e8e5 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -33,6 +33,8 @@ class UsersController < ApplicationController @user.attributes = params[:user] if @user.changed? and @user.save flash[:notice] = t(:user_updated_successfully) + else + flash[:error] = @user.errors.full_messages end respond_with @user, :location => edit_user_path(@user) end -- cgit v1.2.3