diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 2a4fbdf3e..e139e2234 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -67,10 +67,27 @@ class MembersController < ApplicationController def destroy end + def add + if params['user_id'] and !params['user_id'].empty? + @user = User.find_by_uname(params['user_id']) + unless parent.objects.exists? :object_id => @user.id, :object_type => 'User' + relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => 'reader') + if relation.save + flash[:notice] = t("flash.members.successfully_added") + else + flash[:error] = t("flash.members.error_in_adding") + end + else + flash[:error] = t("flash.members.already_added") + end + end + redirect_to edit_group_members_path(parent) + end + protected def find_users - @users = User.all + @users = parent.members #User.all end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bd2d52e4b..8a33c413a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,7 @@ class UsersController < ApplicationController before_filter :find_user, :only => [:show, :edit, :update, :destroy] load_and_authorize_resource + autocomplete :user, :uname def index @users = User.paginate(:page => params[:user_page]) diff --git a/app/views/members/edit.html.haml b/app/views/members/edit.html.haml index 8ea7bfaa6..719ccb8ad 100644 --- a/app/views/members/edit.html.haml +++ b/app/views/members/edit.html.haml @@ -22,7 +22,7 @@ = link_to user.name, user_path(user) %td - Relation::ROLES.each do |role| - = check_box_tag "#{ role }[#{user.id}]", '1', ((parent.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"} + = check_box_tag "#{ role }[#{user.id}]", '1', ((parent.objects.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"} = label_tag "#{ role }[#{user.id}]", t("layout.members.roles.#{ role }") %td = user.uname @@ -33,3 +33,15 @@ %span.text_button_padding= t("layout.or") = link_to t("layout.cancel"), group_path(parent), :class => "text_button_padding link_button" + = form_tag add_group_members_path(parent) do + = javascript_include_tag 'autocomplete-rails.js' + .group + %h2.title= t("layout.members.add_member") + = label_tag "", t("layout.members.input_username") + = autocomplete_field_tag 'user_id', params[:user_id], autocomplete_user_uname_users_path + %br + .group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.add")) + = t("layout.add") + diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 75f3b9335..a22921e1f 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -227,6 +227,8 @@ ru: back_to_group: Вернуться к группе edit: Редактировать список roles: Роли + add_member: Добавить участника + input_username: Псевдоним пользователя groups: list: Список @@ -334,6 +336,9 @@ ru: members: successfully_changed: Список участников успешно изменен error_in_changing: Ошибка изменения списка участников + successfully_added: Участник успешно добавлен + error_in_adding: Ошибка при добавлении участника + already_added: Пользователь уже добавлен auto_build_list: success: Сборка проекта автоматизорована! diff --git a/config/routes.rb b/config/routes.rb index d6d9ed2b6..48b068631 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,9 @@ Rosa::Application.routes.draw do resources :users do resources :groups, :only => [:new, :create, :index] + collection do + get :autocomplete_user_uname + end end resources :event_logs, :only => :index @@ -25,7 +28,7 @@ Rosa::Application.routes.draw do match 'build_lists/' => 'build_lists#all', :as => :all_build_lists match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel - + resources :auto_build_lists, :only => [:index, :create, :destroy] resources :personal_repositories, :only => [:show] do @@ -108,9 +111,10 @@ Rosa::Application.routes.draw do end resources :groups do - resources :members, :only => [:index, :edit, :update] do + resources :members, :only => [:index, :edit, :update, :add] do collection do - get :edit + get :edit + post :add post :update end member do diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 3b886638e..086c07702 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -1,5 +1,23 @@ require 'spec_helper' describe MembersController do + before(:each) do + @group = Factory(:group) + @user = @group.owner + @another_user = Factory(:user) + @add_params = {:group_id => @group.id, :user_id => @another_user.uname} + end + context 'for owner user' do + it 'should add member to group' do + post :add, @add_params + response.should redirect_to(:edit) + Relation.by_target(@group).by_object(@another_user).count.should eql(1) + end + + it 'should add reader member to group' do + post :add, @add_params + Relation.by_target(@group).by_object(@another_user).role.should eql('reader') + end + end end