From 21a32fba6c0900ba0262eae1b8401d8b650f60f5 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 13 Nov 2012 20:29:45 +0600 Subject: [PATCH] show expected message after add member error --- app/controllers/groups/members_controller.rb | 14 +++++++------- app/controllers/platforms/platforms_controller.rb | 13 +++++++------ config/locales/en.yml | 1 + config/locales/ru.yml | 1 + 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/groups/members_controller.rb b/app/controllers/groups/members_controller.rb index e6d95a95c..786c9bc3a 100644 --- a/app/controllers/groups/members_controller.rb +++ b/app/controllers/groups/members_controller.rb @@ -38,13 +38,13 @@ class Groups::MembersController < Groups::BaseController end def add - if params['user_id'].present? - @user = User.find_by_uname(params['user_id']) - if parent.add_member(@user, params[:role]) - flash[:notice] = t("flash.members.successfully_added") - else - flash[:error] = t("flash.members.error_in_adding") - end + @user = User.find_by_uname(params[:user_id]) + if !@user + flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:user_id]) + elsif parent.add_member(@user, params[:role]) + flash[:notice] = t("flash.members.successfully_added") + else + flash[:error] = t("flash.members.error_in_adding") end redirect_to group_members_path(parent) end diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index cd2de9147..43319bb55 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -96,12 +96,13 @@ class Platforms::PlatformsController < Platforms::BaseController end def add_member - if member = User.where(:id => params[:member_id]).first - if @platform.add_member(member) - flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname) - else - flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname) - end + member = User.where(:id => params[:member_id]).first + if !member + flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:member_id]) + elsif @platform.add_member(member) + flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname) + else + flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname) end redirect_to members_platform_url(@platform) end diff --git a/config/locales/en.yml b/config/locales/en.yml index ce2f6a1be..da2c83dc8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -148,6 +148,7 @@ en: group_already_added: Group already added successfully_added: Member %s successfully added error_in_adding: Member %s adding error + wrong_user: User with nickname '%{uname}' not found! blob: successfully_updated: File '%{name}' successfully updated diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 927c12501..482fa06b5 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -148,6 +148,7 @@ ru: group_already_added: Группа уже добавлена successfully_added: Участник %s успешно добавлен error_in_adding: Ошибка при добавлении участника %s + wrong_user: Пользователь с ником '%{uname}' не найден. blob: successfully_updated: Файл '%{name}' успешно обновлен