From 21a32fba6c0900ba0262eae1b8401d8b650f60f5 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 13 Nov 2012 20:29:45 +0600 Subject: [PATCH 1/2] 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}' успешно обновлен From 9c0ae239270ebb0ec487f37a28d4371716f131d4 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 13 Nov 2012 20:29:59 +0600 Subject: [PATCH 2/2] small refactoring --- app/controllers/groups/members_controller.rb | 4 ++-- app/views/groups/members/index.html.haml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/groups/members_controller.rb b/app/controllers/groups/members_controller.rb index 786c9bc3a..77d97ddc4 100644 --- a/app/controllers/groups/members_controller.rb +++ b/app/controllers/groups/members_controller.rb @@ -38,9 +38,9 @@ class Groups::MembersController < Groups::BaseController end def add - @user = User.find_by_uname(params[:user_id]) + @user = User.find_by_uname(params[:user_uname]) if !@user - flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:user_id]) + flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:user_uname]) elsif parent.add_member(@user, params[:role]) flash[:notice] = t("flash.members.successfully_added") else diff --git a/app/views/groups/members/index.html.haml b/app/views/groups/members/index.html.haml index 25b05239d..2ce755b65 100644 --- a/app/views/groups/members/index.html.haml +++ b/app/views/groups/members/index.html.haml @@ -25,7 +25,7 @@ .hr.top = form_tag add_group_members_path(parent) do - .admin-search= autocomplete_field_tag 'user_id', params[:user_id], autocomplete_user_uname_autocompletes_path#, :id_element => '#member_id_field' + .admin-search= autocomplete_field_tag 'user_uname', params[:user_uname], autocomplete_user_uname_autocompletes_path .admin-role .lineForm= select_tag 'role', options_for_collaborators_roles_select .both