[close #11] Changed adding members to group.
This commit is contained in:
parent
5e3711505c
commit
168e110169
2
Gemfile
2
Gemfile
|
@ -2,8 +2,10 @@ source 'http://rubygems.org'
|
|||
|
||||
gem 'rails', '3.0.11' #, :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
group :production do
|
||||
gem 'pg', '~> 0.11.0'
|
||||
gem 'silent-postgres', '~> 0.1.1'
|
||||
end
|
||||
|
||||
gem 'devise', '~> 1.5.2'
|
||||
gem 'omniauth', '~> 1.0.1'
|
||||
|
|
|
@ -67,10 +67,23 @@ 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'])
|
||||
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
|
||||
end
|
||||
redirect_to edit_group_members_path(parent)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_users
|
||||
@users = User.all
|
||||
@users = parent.members #User.all
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -227,6 +227,8 @@ ru:
|
|||
back_to_group: Вернуться к группе
|
||||
edit: Редактировать список
|
||||
roles: Роли
|
||||
add_member: Добавить участника
|
||||
input_username: Псевдоним пользователя
|
||||
|
||||
groups:
|
||||
list: Список
|
||||
|
@ -331,6 +333,8 @@ ru:
|
|||
members:
|
||||
successfully_changed: Список участников успешно изменен
|
||||
error_in_changing: Ошибка изменения списка участников
|
||||
successfully_added: Участник успешно добавлен
|
||||
error_in_adding: Ошибка при добавлении участника
|
||||
|
||||
auto_build_list:
|
||||
success: Сборка проекта автоматизорована!
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
post :add
|
||||
post :update
|
||||
end
|
||||
member do
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue