@@ -0,0 +1,4 | |||
|
1 | Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>'); | |
|
2 | <% @users.each do |user| %> | |
|
3 | new Effect.Highlight('user-<%= user.id %>'); | |
|
4 | <% end %> |
@@ -0,0 +1,1 | |||
|
1 | Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>'); |
@@ -0,0 +1,6 | |||
|
1 | <% if @membership.valid? %> | |
|
2 | Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>'); | |
|
3 | new Effect.Highlight('member-<%= @membership.id %>'); | |
|
4 | <% else %> | |
|
5 | alert('<%= escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) %>'); | |
|
6 | <% end %> |
@@ -0,0 +1,1 | |||
|
1 | Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>'); |
@@ -1,158 +1,140 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class GroupsController < ApplicationController |
|
19 | 19 | layout 'admin' |
|
20 | 20 | |
|
21 | 21 | before_filter :require_admin |
|
22 | 22 | before_filter :find_group, :except => [:index, :new, :create] |
|
23 | 23 | accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user |
|
24 | 24 | |
|
25 | 25 | helper :custom_fields |
|
26 | 26 | |
|
27 | 27 | def index |
|
28 | 28 | @groups = Group.sorted.all |
|
29 | 29 | |
|
30 | 30 | respond_to do |format| |
|
31 | 31 | format.html |
|
32 | 32 | format.api |
|
33 | 33 | end |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def show |
|
37 | 37 | respond_to do |format| |
|
38 | 38 | format.html |
|
39 | 39 | format.api |
|
40 | 40 | end |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def new |
|
44 | 44 | @group = Group.new |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def create |
|
48 | 48 | @group = Group.new |
|
49 | 49 | @group.safe_attributes = params[:group] |
|
50 | 50 | |
|
51 | 51 | respond_to do |format| |
|
52 | 52 | if @group.save |
|
53 | 53 | format.html { |
|
54 | 54 | flash[:notice] = l(:notice_successful_create) |
|
55 | 55 | redirect_to(params[:continue] ? new_group_path : groups_path) |
|
56 | 56 | } |
|
57 | 57 | format.api { render :action => 'show', :status => :created, :location => group_url(@group) } |
|
58 | 58 | else |
|
59 | 59 | format.html { render :action => "new" } |
|
60 | 60 | format.api { render_validation_errors(@group) } |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def edit |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | def update |
|
69 | 69 | @group.safe_attributes = params[:group] |
|
70 | 70 | |
|
71 | 71 | respond_to do |format| |
|
72 | 72 | if @group.save |
|
73 | 73 | flash[:notice] = l(:notice_successful_update) |
|
74 | 74 | format.html { redirect_to(groups_path) } |
|
75 | 75 | format.api { render_api_ok } |
|
76 | 76 | else |
|
77 | 77 | format.html { render :action => "edit" } |
|
78 | 78 | format.api { render_validation_errors(@group) } |
|
79 | 79 | end |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def destroy |
|
84 | 84 | @group.destroy |
|
85 | 85 | |
|
86 | 86 | respond_to do |format| |
|
87 | 87 | format.html { redirect_to(groups_url) } |
|
88 | 88 | format.api { render_api_ok } |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def add_users |
|
93 | users = User.find_all_by_id(params[:user_id] || params[:user_ids]) | |
|
94 | @group.users << users if request.post? | |
|
93 | @users = User.find_all_by_id(params[:user_id] || params[:user_ids]) | |
|
94 | @group.users << @users if request.post? | |
|
95 | 95 | respond_to do |format| |
|
96 | 96 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
97 |
format.js |
|
|
98 | render(:update) {|page| | |
|
99 | page.replace_html "tab-content-users", :partial => 'groups/users' | |
|
100 | users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } | |
|
101 | } | |
|
102 | } | |
|
97 | format.js | |
|
103 | 98 | format.api { render_api_ok } |
|
104 | 99 | end |
|
105 | 100 | end |
|
106 | 101 | |
|
107 | 102 | def remove_user |
|
108 | 103 | @group.users.delete(User.find(params[:user_id])) if request.delete? |
|
109 | 104 | respond_to do |format| |
|
110 | 105 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } |
|
111 | format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } | |
|
106 | format.js | |
|
112 | 107 | format.api { render_api_ok } |
|
113 | 108 | end |
|
114 | 109 | end |
|
115 | 110 | |
|
116 | 111 | def autocomplete_for_user |
|
117 | 112 | @users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100) |
|
118 | 113 | render :layout => false |
|
119 | 114 | end |
|
120 | 115 | |
|
121 | 116 | def edit_membership |
|
122 | 117 | @membership = Member.edit_membership(params[:membership_id], params[:membership], @group) |
|
123 | 118 | @membership.save if request.post? |
|
124 | 119 | respond_to do |format| |
|
125 | if @membership.valid? | |
|
126 | 120 |
|
|
127 |
|
|
|
128 | render(:update) {|page| | |
|
129 | page.replace_html "tab-content-memberships", :partial => 'groups/memberships' | |
|
130 | page.visual_effect(:highlight, "member-#{@membership.id}") | |
|
131 | } | |
|
132 | } | |
|
133 | else | |
|
134 | format.js { | |
|
135 | render(:update) {|page| | |
|
136 | page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) | |
|
137 | } | |
|
138 | } | |
|
139 | end | |
|
121 | format.js | |
|
140 | 122 | end |
|
141 | 123 | end |
|
142 | 124 | |
|
143 | 125 | def destroy_membership |
|
144 | 126 | Member.find(params[:membership_id]).destroy if request.post? |
|
145 | 127 | respond_to do |format| |
|
146 | 128 | format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } |
|
147 | format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } | |
|
129 | format.js | |
|
148 | 130 | end |
|
149 | 131 | end |
|
150 | 132 | |
|
151 | 133 | private |
|
152 | 134 | |
|
153 | 135 | def find_group |
|
154 | 136 | @group = Group.find(params[:id]) |
|
155 | 137 | rescue ActiveRecord::RecordNotFound |
|
156 | 138 | render_404 |
|
157 | 139 | end |
|
158 | 140 | end |
@@ -1,180 +1,202 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class GroupsControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :projects, :users, :members, :member_roles, :groups_users |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | @request.session[:user_id] = 1 |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_index |
|
28 | 28 | get :index |
|
29 | 29 | assert_response :success |
|
30 | 30 | assert_template 'index' |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_show |
|
34 | 34 | get :show, :id => 10 |
|
35 | 35 | assert_response :success |
|
36 | 36 | assert_template 'show' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def test_show_invalid_should_return_404 |
|
40 | 40 | get :show, :id => 99 |
|
41 | 41 | assert_response 404 |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def test_new |
|
45 | 45 | get :new |
|
46 | 46 | assert_response :success |
|
47 | 47 | assert_template 'new' |
|
48 | 48 | assert_select 'input[name=?]', 'group[name]' |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def test_create |
|
52 | 52 | assert_difference 'Group.count' do |
|
53 | 53 | post :create, :group => {:name => 'New group'} |
|
54 | 54 | end |
|
55 | 55 | assert_redirected_to '/groups' |
|
56 | 56 | group = Group.first(:order => 'id DESC') |
|
57 | 57 | assert_equal 'New group', group.name |
|
58 | 58 | assert_equal [], group.users |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_create_and_continue |
|
62 | 62 | assert_difference 'Group.count' do |
|
63 | 63 | post :create, :group => {:name => 'New group'}, :continue => 'Create and continue' |
|
64 | 64 | end |
|
65 | 65 | assert_redirected_to '/groups/new' |
|
66 | 66 | group = Group.first(:order => 'id DESC') |
|
67 | 67 | assert_equal 'New group', group.name |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | def test_create_with_failure |
|
71 | 71 | assert_no_difference 'Group.count' do |
|
72 | 72 | post :create, :group => {:name => ''} |
|
73 | 73 | end |
|
74 | 74 | assert_response :success |
|
75 | 75 | assert_template 'new' |
|
76 | 76 | end |
|
77 | 77 | |
|
78 | 78 | def test_edit |
|
79 | 79 | get :edit, :id => 10 |
|
80 | 80 | assert_response :success |
|
81 | 81 | assert_template 'edit' |
|
82 | 82 | assert_tag 'div', :attributes => {:id => 'tab-content-users'} |
|
83 | 83 | assert_tag 'div', :attributes => {:id => 'tab-content-memberships'} |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def test_update |
|
87 | 87 | new_name = 'New name' |
|
88 | 88 | put :update, :id => 10, :group => {:name => new_name} |
|
89 | 89 | assert_redirected_to '/groups' |
|
90 | 90 | group = Group.find(10) |
|
91 | 91 | assert_equal new_name, group.name |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def test_update_with_failure |
|
95 | 95 | put :update, :id => 10, :group => {:name => ''} |
|
96 | 96 | assert_response :success |
|
97 | 97 | assert_template 'edit' |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def test_destroy |
|
101 | 101 | assert_difference 'Group.count', -1 do |
|
102 | 102 | post :destroy, :id => 10 |
|
103 | 103 | end |
|
104 | 104 | assert_redirected_to '/groups' |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | def test_add_users |
|
108 | 108 | assert_difference 'Group.find(10).users.count', 2 do |
|
109 | 109 | post :add_users, :id => 10, :user_ids => ['2', '3'] |
|
110 | 110 | end |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def test_xhr_add_users |
|
114 | 114 | assert_difference 'Group.find(10).users.count', 2 do |
|
115 | 115 | xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] |
|
116 | assert_response :success | |
|
117 | assert_template 'add_users' | |
|
118 | assert_equal 'text/javascript', response.content_type | |
|
116 | 119 | end |
|
117 | assert_select_rjs :replace_html, 'tab-content-users' | |
|
120 | assert_match /John Smith/, response.body | |
|
118 | 121 | end |
|
119 | 122 | |
|
120 | 123 | def test_remove_user |
|
121 | 124 | assert_difference 'Group.find(10).users.count', -1 do |
|
122 | 125 | delete :remove_user, :id => 10, :user_id => '8' |
|
123 | 126 | end |
|
124 | 127 | end |
|
125 | 128 | |
|
126 | 129 | def test_xhr_remove_user |
|
127 | 130 | assert_difference 'Group.find(10).users.count', -1 do |
|
128 | 131 | xhr :delete, :remove_user, :id => 10, :user_id => '8' |
|
132 | assert_response :success | |
|
133 | assert_template 'remove_user' | |
|
134 | assert_equal 'text/javascript', response.content_type | |
|
129 | 135 | end |
|
130 | assert_select_rjs :replace_html, 'tab-content-users' | |
|
131 | 136 | end |
|
132 | 137 | |
|
133 | 138 | def test_new_membership |
|
134 | 139 | assert_difference 'Group.find(10).members.count' do |
|
135 | 140 | post :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
136 | 141 | end |
|
137 | 142 | end |
|
138 | 143 | |
|
139 | 144 | def test_xhr_new_membership |
|
140 | 145 | assert_difference 'Group.find(10).members.count' do |
|
141 | 146 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} |
|
147 | assert_response :success | |
|
148 | assert_template 'edit_membership' | |
|
149 | assert_equal 'text/javascript', response.content_type | |
|
142 | 150 | end |
|
143 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
|
151 | assert_match /OnlineStore/, response.body | |
|
144 | 152 | end |
|
145 | 153 | |
|
146 | 154 | def test_xhr_new_membership_with_failure |
|
147 | 155 | assert_no_difference 'Group.find(10).members.count' do |
|
148 | 156 | xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} |
|
157 | assert_response :success | |
|
158 | assert_template 'edit_membership' | |
|
159 | assert_equal 'text/javascript', response.content_type | |
|
149 | 160 | end |
|
150 |
assert |
|
|
161 | assert_match /alert/, response.body, "Alert message not sent" | |
|
151 | 162 | end |
|
152 | 163 | |
|
153 | 164 | def test_edit_membership |
|
154 | 165 | assert_no_difference 'Group.find(10).members.count' do |
|
155 | 166 | post :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} |
|
156 | 167 | end |
|
157 | 168 | end |
|
158 | 169 | |
|
170 | def test_xhr_edit_membership | |
|
171 | assert_no_difference 'Group.find(10).members.count' do | |
|
172 | xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']} | |
|
173 | assert_response :success | |
|
174 | assert_template 'edit_membership' | |
|
175 | assert_equal 'text/javascript', response.content_type | |
|
176 | end | |
|
177 | end | |
|
178 | ||
|
159 | 179 | def test_destroy_membership |
|
160 | 180 | assert_difference 'Group.find(10).members.count', -1 do |
|
161 | 181 | post :destroy_membership, :id => 10, :membership_id => 6 |
|
162 | 182 | end |
|
163 | 183 | end |
|
164 | 184 | |
|
165 | 185 | def test_xhr_destroy_membership |
|
166 | 186 | assert_difference 'Group.find(10).members.count', -1 do |
|
167 | 187 | xhr :post, :destroy_membership, :id => 10, :membership_id => 6 |
|
188 | assert_response :success | |
|
189 | assert_template 'destroy_membership' | |
|
190 | assert_equal 'text/javascript', response.content_type | |
|
168 | 191 | end |
|
169 | assert_select_rjs :replace_html, 'tab-content-memberships' | |
|
170 | 192 | end |
|
171 | 193 | |
|
172 | 194 | def test_autocomplete_for_user |
|
173 | 195 | get :autocomplete_for_user, :id => 10, :q => 'mis' |
|
174 | 196 | assert_response :success |
|
175 | 197 | users = assigns(:users) |
|
176 | 198 | assert_not_nil users |
|
177 | 199 | assert users.any? |
|
178 | 200 | assert !users.include?(Group.find(10).users.first) |
|
179 | 201 | end |
|
180 | 202 | end |
General Comments 0
You need to be logged in to leave comments.
Login now