Merge pull request #14 from warpc/group_members_change

Changed adding members to group.
This commit is contained in:
santaux 2011-12-13 02:16:37 -08:00
commit 24766d2383
6 changed files with 62 additions and 5 deletions

View File

@ -67,10 +67,27 @@ class MembersController < ApplicationController
def destroy def destroy
end 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 protected
def find_users def find_users
@users = User.all @users = parent.members #User.all
end end
end end

View File

@ -4,6 +4,7 @@ class UsersController < ApplicationController
before_filter :find_user, :only => [:show, :edit, :update, :destroy] before_filter :find_user, :only => [:show, :edit, :update, :destroy]
load_and_authorize_resource load_and_authorize_resource
autocomplete :user, :uname
def index def index
@users = User.paginate(:page => params[:user_page]) @users = User.paginate(:page => params[:user_page])

View File

@ -22,7 +22,7 @@
= link_to user.name, user_path(user) = link_to user.name, user_path(user)
%td %td
- Relation::ROLES.each do |role| - 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 }") = label_tag "#{ role }[#{user.id}]", t("layout.members.roles.#{ role }")
%td %td
= user.uname = user.uname
@ -33,3 +33,15 @@
%span.text_button_padding= t("layout.or") %span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), group_path(parent), :class => "text_button_padding link_button" = 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")

View File

@ -227,6 +227,8 @@ ru:
back_to_group: Вернуться к группе back_to_group: Вернуться к группе
edit: Редактировать список edit: Редактировать список
roles: Роли roles: Роли
add_member: Добавить участника
input_username: Псевдоним пользователя
groups: groups:
list: Список list: Список
@ -334,6 +336,9 @@ ru:
members: members:
successfully_changed: Список участников успешно изменен successfully_changed: Список участников успешно изменен
error_in_changing: Ошибка изменения списка участников error_in_changing: Ошибка изменения списка участников
successfully_added: Участник успешно добавлен
error_in_adding: Ошибка при добавлении участника
already_added: Пользователь уже добавлен
auto_build_list: auto_build_list:
success: Сборка проекта автоматизорована! success: Сборка проекта автоматизорована!

View File

@ -8,6 +8,9 @@ Rosa::Application.routes.draw do
resources :users do resources :users do
resources :groups, :only => [:new, :create, :index] resources :groups, :only => [:new, :create, :index]
collection do
get :autocomplete_user_uname
end
end end
resources :event_logs, :only => :index 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/' => 'build_lists#all', :as => :all_build_lists
match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel
resources :auto_build_lists, :only => [:index, :create, :destroy] resources :auto_build_lists, :only => [:index, :create, :destroy]
resources :personal_repositories, :only => [:show] do resources :personal_repositories, :only => [:show] do
@ -108,9 +111,10 @@ Rosa::Application.routes.draw do
end end
resources :groups do resources :groups do
resources :members, :only => [:index, :edit, :update] do resources :members, :only => [:index, :edit, :update, :add] do
collection do collection do
get :edit get :edit
post :add
post :update post :update
end end
member do member do

View File

@ -1,5 +1,23 @@
require 'spec_helper' require 'spec_helper'
describe MembersController do 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 end