##// END OF EJS Templates
Moved new group user to its own action GroupsController#new_users....
Jean-Philippe Lang -
r13220:1508cd7b8bf9
parent child
Show More
@@ -0,0 +1,9
1 <fieldset class="box">
2 <legend><%= label_tag "user_search", l(:label_user_search) %></legend>
3 <p><%= text_field_tag 'user_search', nil %></p>
4 <%= javascript_tag "observeSearchfield('user_search', null, '#{ escape_javascript autocomplete_for_user_group_path(@group) }')" %>
5
6 <div id="users">
7 <%= render_principals_for_new_group_users(@group) %>
8 </div>
9 </fieldset>
@@ -0,0 +1,9
1 <h3 class="title"><%= l(:label_user_new) %></h3>
2
3 <%= form_for(@group, :url => group_users_path(@group), :remote => true, :method => :post) do |f| %>
4 <%= render :partial => 'new_users_form' %>
5 <p class="buttons">
6 <%= submit_tag l(:button_add) %>
7 <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
8 </p>
9 <% end %>
@@ -0,0 +1,6
1 <h2><%= l(:label_user_new) %></h2>
2
3 <%= form_for(@group, :url => group_users_path(@group), :method => :post) do |f| %>
4 <%= render :partial => 'new_users_form' %>
5 <p><%= submit_tag l(:button_add) %></p>
6 <% end %>
@@ -0,0 +1,2
1 $('#ajax-modal').html('<%= escape_javascript(render :partial => 'groups/new_users_modal') %>');
2 showModal('ajax-modal', '700px');
@@ -1,138 +1,141
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 helper :principal_memberships
27 27
28 28 def index
29 29 respond_to do |format|
30 30 format.html {
31 31 @groups = Group.sorted.to_a
32 32 @user_count_by_group_id = user_count_by_group_id
33 33 }
34 34 format.api {
35 35 scope = Group.sorted
36 36 scope = scope.givable unless params[:builtin] == '1'
37 37 @groups = scope.to_a
38 38 }
39 39 end
40 40 end
41 41
42 42 def show
43 43 respond_to do |format|
44 44 format.html
45 45 format.api
46 46 end
47 47 end
48 48
49 49 def new
50 50 @group = Group.new
51 51 end
52 52
53 53 def create
54 54 @group = Group.new
55 55 @group.safe_attributes = params[:group]
56 56
57 57 respond_to do |format|
58 58 if @group.save
59 59 format.html {
60 60 flash[:notice] = l(:notice_successful_create)
61 61 redirect_to(params[:continue] ? new_group_path : groups_path)
62 62 }
63 63 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
64 64 else
65 65 format.html { render :action => "new" }
66 66 format.api { render_validation_errors(@group) }
67 67 end
68 68 end
69 69 end
70 70
71 71 def edit
72 72 end
73 73
74 74 def update
75 75 @group.safe_attributes = params[:group]
76 76
77 77 respond_to do |format|
78 78 if @group.save
79 79 flash[:notice] = l(:notice_successful_update)
80 80 format.html { redirect_to(groups_path) }
81 81 format.api { render_api_ok }
82 82 else
83 83 format.html { render :action => "edit" }
84 84 format.api { render_validation_errors(@group) }
85 85 end
86 86 end
87 87 end
88 88
89 89 def destroy
90 90 @group.destroy
91 91
92 92 respond_to do |format|
93 93 format.html { redirect_to(groups_path) }
94 94 format.api { render_api_ok }
95 95 end
96 96 end
97 97
98 def new_users
99 end
100
98 101 def add_users
99 102 @users = User.where(:id => (params[:user_id] || params[:user_ids])).to_a
100 103 @group.users << @users if request.post?
101 104 respond_to do |format|
102 105 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
103 106 format.js
104 107 format.api { render_api_ok }
105 108 end
106 109 end
107 110
108 111 def remove_user
109 112 @group.users.delete(User.find(params[:user_id])) if request.delete?
110 113 respond_to do |format|
111 114 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
112 115 format.js
113 116 format.api { render_api_ok }
114 117 end
115 118 end
116 119
117 120 def autocomplete_for_user
118 121 respond_to do |format|
119 122 format.js
120 123 end
121 124 end
122 125
123 126 private
124 127
125 128 def find_group
126 129 @group = Group.find(params[:id])
127 130 rescue ActiveRecord::RecordNotFound
128 131 render_404
129 132 end
130 133
131 134 def user_count_by_group_id
132 135 h = User.joins(:groups).group('group_id').count
133 136 h.keys.each do |key|
134 137 h[key.to_i] = h.delete(key)
135 138 end
136 139 h
137 140 end
138 141 end
@@ -1,43 +1,46
1 1 # encoding: utf-8
2 2 #
3 3 # Redmine - project management software
4 4 # Copyright (C) 2006-2014 Jean-Philippe Lang
5 5 #
6 6 # This program is free software; you can redistribute it and/or
7 7 # modify it under the terms of the GNU General Public License
8 8 # as published by the Free Software Foundation; either version 2
9 9 # of the License, or (at your option) any later version.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
17 17 # along with this program; if not, write to the Free Software
18 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 20 module GroupsHelper
21 21 def group_settings_tabs(group)
22 22 tabs = []
23 23 tabs << {:name => 'general', :partial => 'groups/general', :label => :label_general}
24 24 tabs << {:name => 'users', :partial => 'groups/users', :label => :label_user_plural} if group.givable?
25 25 tabs << {:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
26 26 tabs
27 27 end
28 28
29 29 def render_principals_for_new_group_users(group)
30 30 scope = User.active.sorted.not_in_group(group).like(params[:q])
31 31 principal_count = scope.count
32 32 principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
33 33 principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).to_a
34 34
35 s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals')
35 s = content_tag('div',
36 content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals'),
37 :class => 'objects-selection'
38 )
36 39
37 40 links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
38 41 link_to text, autocomplete_for_user_group_path(group, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
39 42 }
40 43
41 44 s + content_tag('p', links, :class => 'pagination')
42 45 end
43 46 end
@@ -1,39 +1,22
1 <div class="splitcontentleft">
1 <p><%= link_to l(:label_user_new), new_group_users_path(@group), :remote => true, :class => "icon icon-add" %></p>
2
2 3 <% if @group.users.any? %>
3 4 <table class="list users">
4 5 <thead><tr>
5 6 <th><%= l(:label_user) %></th>
6 7 <th style="width:15%"></th>
7 8 </tr></thead>
8 9 <tbody>
9 10 <% @group.users.sort.each do |user| %>
10 11 <tr id="user-<%= user.id %>" class="<%= cycle 'odd', 'even' %>">
11 12 <td class="name"><%= link_to_user user %></td>
12 13 <td class="buttons">
13 14 <%= delete_link group_user_path(@group, :user_id => user), :remote => true %>
14 15 </td>
15 16 </tr>
16 17 <% end %>
17 18 </tbody>
18 19 </table>
19 20 <% else %>
20 21 <p class="nodata"><%= l(:label_no_data) %></p>
21 22 <% end %>
22 </div>
23
24 <div class="splitcontentright">
25 <%= form_for(@group, :remote => true, :url => group_users_path(@group),
26 :html => {:method => :post}) do |f| %>
27 <fieldset><legend><%=l(:label_user_new)%></legend>
28
29 <p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
30 <%= javascript_tag "observeSearchfield('user_search', null, '#{ escape_javascript autocomplete_for_user_group_path(@group) }')" %>
31
32 <div id="users">
33 <%= render_principals_for_new_group_users(@group) %>
34 </div>
35
36 <p><%= submit_tag l(:button_add) %></p>
37 </fieldset>
38 <% end %>
39 </div>
@@ -1,4 +1,5
1 hideModal();
1 2 $('#tab-content-users').html('<%= escape_javascript(render :partial => 'groups/users') %>');
2 3 <% @users.each do |user| %>
3 4 $('#user-<%= user.id %>').effect("highlight");
4 5 <% end %>
@@ -1,347 +1,348
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 Rails.application.routes.draw do
19 19 root :to => 'welcome#index', :as => 'home'
20 20
21 21 match 'login', :to => 'account#login', :as => 'signin', :via => [:get, :post]
22 22 match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post]
23 23 match 'account/register', :to => 'account#register', :via => [:get, :post], :as => 'register'
24 24 match 'account/lost_password', :to => 'account#lost_password', :via => [:get, :post], :as => 'lost_password'
25 25 match 'account/activate', :to => 'account#activate', :via => :get
26 26 get 'account/activation_email', :to => 'account#activation_email', :as => 'activation_email'
27 27
28 28 match '/news/preview', :controller => 'previews', :action => 'news', :as => 'preview_news', :via => [:get, :post, :put, :patch]
29 29 match '/issues/preview/new/:project_id', :to => 'previews#issue', :as => 'preview_new_issue', :via => [:get, :post, :put, :patch]
30 30 match '/issues/preview/edit/:id', :to => 'previews#issue', :as => 'preview_edit_issue', :via => [:get, :post, :put, :patch]
31 31 match '/issues/preview', :to => 'previews#issue', :as => 'preview_issue', :via => [:get, :post, :put, :patch]
32 32
33 33 match 'projects/:id/wiki', :to => 'wikis#edit', :via => :post
34 34 match 'projects/:id/wiki/destroy', :to => 'wikis#destroy', :via => [:get, :post]
35 35
36 36 match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post], :as => 'new_board_message'
37 37 get 'boards/:board_id/topics/:id', :to => 'messages#show', :as => 'board_message'
38 38 match 'boards/:board_id/topics/quote/:id', :to => 'messages#quote', :via => [:get, :post]
39 39 get 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
40 40
41 41 post 'boards/:board_id/topics/preview', :to => 'messages#preview', :as => 'preview_board_message'
42 42 post 'boards/:board_id/topics/:id/replies', :to => 'messages#reply'
43 43 post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
44 44 post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy'
45 45
46 46 # Misc issue routes. TODO: move into resources
47 47 match '/issues/auto_complete', :to => 'auto_completes#issues', :via => :get, :as => 'auto_complete_issues'
48 48 match '/issues/context_menu', :to => 'context_menus#issues', :as => 'issues_context_menu', :via => [:get, :post]
49 49 match '/issues/changes', :to => 'journals#index', :as => 'issue_changes', :via => :get
50 50 match '/issues/:id/quoted', :to => 'journals#new', :id => /\d+/, :via => :post, :as => 'quoted_issue'
51 51
52 52 match '/journals/diff/:id', :to => 'journals#diff', :id => /\d+/, :via => :get
53 53 match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
54 54
55 55 get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
56 56 get '/issues/gantt', :to => 'gantts#show'
57 57
58 58 get '/projects/:project_id/issues/calendar', :to => 'calendars#show', :as => 'project_calendar'
59 59 get '/issues/calendar', :to => 'calendars#show'
60 60
61 61 get 'projects/:id/issues/report', :to => 'reports#issue_report', :as => 'project_issues_report'
62 62 get 'projects/:id/issues/report/:detail', :to => 'reports#issue_report_details', :as => 'project_issues_report_details'
63 63
64 64 match 'my/account', :controller => 'my', :action => 'account', :via => [:get, :post]
65 65 match 'my/account/destroy', :controller => 'my', :action => 'destroy', :via => [:get, :post]
66 66 match 'my/page', :controller => 'my', :action => 'page', :via => :get
67 67 match 'my', :controller => 'my', :action => 'index', :via => :get # Redirects to my/page
68 68 match 'my/reset_rss_key', :controller => 'my', :action => 'reset_rss_key', :via => :post
69 69 match 'my/reset_api_key', :controller => 'my', :action => 'reset_api_key', :via => :post
70 70 match 'my/password', :controller => 'my', :action => 'password', :via => [:get, :post]
71 71 match 'my/page_layout', :controller => 'my', :action => 'page_layout', :via => :get
72 72 match 'my/add_block', :controller => 'my', :action => 'add_block', :via => :post
73 73 match 'my/remove_block', :controller => 'my', :action => 'remove_block', :via => :post
74 74 match 'my/order_blocks', :controller => 'my', :action => 'order_blocks', :via => :post
75 75
76 76 resources :users do
77 77 resources :memberships, :controller => 'principal_memberships'
78 78 end
79 79
80 80 post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
81 81 delete 'watchers/watch', :to => 'watchers#unwatch'
82 82 get 'watchers/new', :to => 'watchers#new'
83 83 post 'watchers', :to => 'watchers#create'
84 84 post 'watchers/append', :to => 'watchers#append'
85 85 delete 'watchers', :to => 'watchers#destroy'
86 86 get 'watchers/autocomplete_for_user', :to => 'watchers#autocomplete_for_user'
87 87 # Specific routes for issue watchers API
88 88 post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
89 89 delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue'
90 90
91 91 resources :projects do
92 92 member do
93 93 get 'settings(/:tab)', :action => 'settings', :as => 'settings'
94 94 post 'modules'
95 95 post 'archive'
96 96 post 'unarchive'
97 97 post 'close'
98 98 post 'reopen'
99 99 match 'copy', :via => [:get, :post]
100 100 end
101 101
102 102 shallow do
103 103 resources :memberships, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do
104 104 collection do
105 105 get 'autocomplete'
106 106 end
107 107 end
108 108 end
109 109
110 110 resource :enumerations, :controller => 'project_enumerations', :only => [:update, :destroy]
111 111
112 112 get 'issues/:copy_from/copy', :to => 'issues#new', :as => 'copy_issue'
113 113 resources :issues, :only => [:index, :new, :create]
114 114 # issue form update
115 115 match 'issues/update_form', :controller => 'issues', :action => 'update_form', :via => [:put, :patch, :post], :as => 'issue_form'
116 116
117 117 resources :files, :only => [:index, :new, :create]
118 118
119 119 resources :versions, :except => [:index, :show, :edit, :update, :destroy] do
120 120 collection do
121 121 put 'close_completed'
122 122 end
123 123 end
124 124 get 'versions.:format', :to => 'versions#index'
125 125 get 'roadmap', :to => 'versions#index', :format => false
126 126 get 'versions', :to => 'versions#index'
127 127
128 128 resources :news, :except => [:show, :edit, :update, :destroy]
129 129 resources :time_entries, :controller => 'timelog' do
130 130 get 'report', :on => :collection
131 131 end
132 132 resources :queries, :only => [:new, :create]
133 133 shallow do
134 134 resources :issue_categories
135 135 end
136 136 resources :documents, :except => [:show, :edit, :update, :destroy]
137 137 resources :boards
138 138 shallow do
139 139 resources :repositories, :except => [:index, :show] do
140 140 member do
141 141 match 'committers', :via => [:get, :post]
142 142 end
143 143 end
144 144 end
145 145
146 146 match 'wiki/index', :controller => 'wiki', :action => 'index', :via => :get
147 147 resources :wiki, :except => [:index, :new, :create], :as => 'wiki_page' do
148 148 member do
149 149 get 'rename'
150 150 post 'rename'
151 151 get 'history'
152 152 get 'diff'
153 153 match 'preview', :via => [:post, :put, :patch]
154 154 post 'protect'
155 155 post 'add_attachment'
156 156 end
157 157 collection do
158 158 get 'export'
159 159 get 'date_index'
160 160 end
161 161 end
162 162 match 'wiki', :controller => 'wiki', :action => 'show', :via => :get
163 163 get 'wiki/:id/:version', :to => 'wiki#show', :constraints => {:version => /\d+/}
164 164 delete 'wiki/:id/:version', :to => 'wiki#destroy_version'
165 165 get 'wiki/:id/:version/annotate', :to => 'wiki#annotate'
166 166 get 'wiki/:id/:version/diff', :to => 'wiki#diff'
167 167 end
168 168
169 169 resources :issues do
170 170 collection do
171 171 match 'bulk_edit', :via => [:get, :post]
172 172 post 'bulk_update'
173 173 end
174 174 resources :time_entries, :controller => 'timelog' do
175 175 collection do
176 176 get 'report'
177 177 end
178 178 end
179 179 shallow do
180 180 resources :relations, :controller => 'issue_relations', :only => [:index, :show, :create, :destroy]
181 181 end
182 182 end
183 183 match '/issues', :controller => 'issues', :action => 'destroy', :via => :delete
184 184
185 185 resources :queries, :except => [:show]
186 186
187 187 resources :news, :only => [:index, :show, :edit, :update, :destroy]
188 188 match '/news/:id/comments', :to => 'comments#create', :via => :post
189 189 match '/news/:id/comments/:comment_id', :to => 'comments#destroy', :via => :delete
190 190
191 191 resources :versions, :only => [:show, :edit, :update, :destroy] do
192 192 post 'status_by', :on => :member
193 193 end
194 194
195 195 resources :documents, :only => [:show, :edit, :update, :destroy] do
196 196 post 'add_attachment', :on => :member
197 197 end
198 198
199 199 match '/time_entries/context_menu', :to => 'context_menus#time_entries', :as => :time_entries_context_menu, :via => [:get, :post]
200 200
201 201 resources :time_entries, :controller => 'timelog', :except => :destroy do
202 202 collection do
203 203 get 'report'
204 204 get 'bulk_edit'
205 205 post 'bulk_update'
206 206 end
207 207 end
208 208 match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/
209 209 # TODO: delete /time_entries for bulk deletion
210 210 match '/time_entries/destroy', :to => 'timelog#destroy', :via => :delete
211 211
212 212 get 'projects/:id/activity', :to => 'activities#index', :as => :project_activity
213 213 get 'activity', :to => 'activities#index'
214 214
215 215 # repositories routes
216 216 get 'projects/:id/repository/:repository_id/statistics', :to => 'repositories#stats'
217 217 get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph'
218 218
219 219 get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))',
220 220 :to => 'repositories#changes'
221 221
222 222 get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision'
223 223 get 'projects/:id/repository/:repository_id/revision', :to => 'repositories#revision'
224 224 post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue'
225 225 delete 'projects/:id/repository/:repository_id/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
226 226 get 'projects/:id/repository/:repository_id/revisions', :to => 'repositories#revisions'
227 227 get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))',
228 228 :controller => 'repositories',
229 229 :format => false,
230 230 :constraints => {
231 231 :action => /(browse|show|entry|raw|annotate|diff)/,
232 232 :rev => /[a-z0-9\.\-_]+/
233 233 }
234 234
235 235 get 'projects/:id/repository/statistics', :to => 'repositories#stats'
236 236 get 'projects/:id/repository/graph', :to => 'repositories#graph'
237 237
238 238 get 'projects/:id/repository/changes(/*path(.:ext))',
239 239 :to => 'repositories#changes'
240 240
241 241 get 'projects/:id/repository/revisions', :to => 'repositories#revisions'
242 242 get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision'
243 243 get 'projects/:id/repository/revision', :to => 'repositories#revision'
244 244 post 'projects/:id/repository/revisions/:rev/issues', :to => 'repositories#add_related_issue'
245 245 delete 'projects/:id/repository/revisions/:rev/issues/:issue_id', :to => 'repositories#remove_related_issue'
246 246 get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))',
247 247 :controller => 'repositories',
248 248 :format => false,
249 249 :constraints => {
250 250 :action => /(browse|show|entry|raw|annotate|diff)/,
251 251 :rev => /[a-z0-9\.\-_]+/
252 252 }
253 253 get 'projects/:id/repository/:repository_id/:action(/*path(.:ext))',
254 254 :controller => 'repositories',
255 255 :action => /(browse|show|entry|raw|changes|annotate|diff)/
256 256 get 'projects/:id/repository/:action(/*path(.:ext))',
257 257 :controller => 'repositories',
258 258 :action => /(browse|show|entry|raw|changes|annotate|diff)/
259 259
260 260 get 'projects/:id/repository/:repository_id', :to => 'repositories#show', :path => nil
261 261 get 'projects/:id/repository', :to => 'repositories#show', :path => nil
262 262
263 263 # additional routes for having the file name at the end of url
264 264 get 'attachments/:id/:filename', :to => 'attachments#show', :id => /\d+/, :filename => /.*/, :as => 'named_attachment'
265 265 get 'attachments/download/:id/:filename', :to => 'attachments#download', :id => /\d+/, :filename => /.*/, :as => 'download_named_attachment'
266 266 get 'attachments/download/:id', :to => 'attachments#download', :id => /\d+/
267 267 get 'attachments/thumbnail/:id(/:size)', :to => 'attachments#thumbnail', :id => /\d+/, :size => /\d+/, :as => 'thumbnail'
268 268 resources :attachments, :only => [:show, :destroy]
269 269
270 270 resources :groups do
271 271 resources :memberships, :controller => 'principal_memberships'
272 272 member do
273 273 get 'autocomplete_for_user'
274 274 end
275 275 end
276 276
277 match 'groups/:id/users', :controller => 'groups', :action => 'add_users', :id => /\d+/, :via => :post, :as => 'group_users'
278 match 'groups/:id/users/:user_id', :controller => 'groups', :action => 'remove_user', :id => /\d+/, :via => :delete, :as => 'group_user'
277 get 'groups/:id/users/new', :to => 'groups#new_users', :id => /\d+/, :as => 'new_group_users'
278 post 'groups/:id/users', :to => 'groups#add_users', :id => /\d+/, :as => 'group_users'
279 delete 'groups/:id/users/:user_id', :to => 'groups#remove_user', :id => /\d+/, :as => 'group_user'
279 280
280 281 resources :trackers, :except => :show do
281 282 collection do
282 283 match 'fields', :via => [:get, :post]
283 284 end
284 285 end
285 286 resources :issue_statuses, :except => :show do
286 287 collection do
287 288 post 'update_issue_done_ratio'
288 289 end
289 290 end
290 291 resources :custom_fields, :except => :show
291 292 resources :roles do
292 293 collection do
293 294 match 'permissions', :via => [:get, :post]
294 295 end
295 296 end
296 297 resources :enumerations, :except => :show
297 298 match 'enumerations/:type', :to => 'enumerations#index', :via => :get
298 299
299 300 get 'projects/:id/search', :controller => 'search', :action => 'index'
300 301 get 'search', :controller => 'search', :action => 'index'
301 302
302 303 match 'mail_handler', :controller => 'mail_handler', :action => 'index', :via => :post
303 304
304 305 match 'admin', :controller => 'admin', :action => 'index', :via => :get
305 306 match 'admin/projects', :controller => 'admin', :action => 'projects', :via => :get
306 307 match 'admin/plugins', :controller => 'admin', :action => 'plugins', :via => :get
307 308 match 'admin/info', :controller => 'admin', :action => 'info', :via => :get
308 309 match 'admin/test_email', :controller => 'admin', :action => 'test_email', :via => :get
309 310 match 'admin/default_configuration', :controller => 'admin', :action => 'default_configuration', :via => :post
310 311
311 312 resources :auth_sources do
312 313 member do
313 314 get 'test_connection', :as => 'try_connection'
314 315 end
315 316 collection do
316 317 get 'autocomplete_for_new_user'
317 318 end
318 319 end
319 320
320 321 match 'workflows', :controller => 'workflows', :action => 'index', :via => :get
321 322 match 'workflows/edit', :controller => 'workflows', :action => 'edit', :via => [:get, :post]
322 323 match 'workflows/permissions', :controller => 'workflows', :action => 'permissions', :via => [:get, :post]
323 324 match 'workflows/copy', :controller => 'workflows', :action => 'copy', :via => [:get, :post]
324 325 match 'settings', :controller => 'settings', :action => 'index', :via => :get
325 326 match 'settings/edit', :controller => 'settings', :action => 'edit', :via => [:get, :post]
326 327 match 'settings/plugin/:id', :controller => 'settings', :action => 'plugin', :via => [:get, :post], :as => 'plugin_settings'
327 328
328 329 match 'sys/projects', :to => 'sys#projects', :via => :get
329 330 match 'sys/projects/:id/repository', :to => 'sys#create_project_repository', :via => :post
330 331 match 'sys/fetch_changesets', :to => 'sys#fetch_changesets', :via => [:get, :post]
331 332
332 333 match 'uploads', :to => 'attachments#upload', :via => :post
333 334
334 335 get 'robots.txt', :to => 'welcome#robots'
335 336
336 337 Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir|
337 338 file = File.join(plugin_dir, "config/routes.rb")
338 339 if File.exists?(file)
339 340 begin
340 341 instance_eval File.read(file)
341 342 rescue Exception => e
342 343 puts "An error occurred while loading the routes definition of #{File.basename(plugin_dir)} plugin (#{file}): #{e.message}."
343 344 exit 1
344 345 end
345 346 end
346 347 end
347 348 end
@@ -1,152 +1,164
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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, :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_index_should_show_user_count
34 34 get :index
35 35 assert_response :success
36 36 assert_select 'tr#group-11 td.user_count', :text => '1'
37 37 end
38 38
39 39 def test_show
40 40 get :show, :id => 10
41 41 assert_response :success
42 42 assert_template 'show'
43 43 end
44 44
45 45 def test_show_invalid_should_return_404
46 46 get :show, :id => 99
47 47 assert_response 404
48 48 end
49 49
50 50 def test_new
51 51 get :new
52 52 assert_response :success
53 53 assert_template 'new'
54 54 assert_select 'input[name=?]', 'group[name]'
55 55 end
56 56
57 57 def test_create
58 58 assert_difference 'Group.count' do
59 59 post :create, :group => {:name => 'New group'}
60 60 end
61 61 assert_redirected_to '/groups'
62 62 group = Group.order('id DESC').first
63 63 assert_equal 'New group', group.name
64 64 assert_equal [], group.users
65 65 end
66 66
67 67 def test_create_and_continue
68 68 assert_difference 'Group.count' do
69 69 post :create, :group => {:name => 'New group'}, :continue => 'Create and continue'
70 70 end
71 71 assert_redirected_to '/groups/new'
72 72 group = Group.order('id DESC').first
73 73 assert_equal 'New group', group.name
74 74 end
75 75
76 76 def test_create_with_failure
77 77 assert_no_difference 'Group.count' do
78 78 post :create, :group => {:name => ''}
79 79 end
80 80 assert_response :success
81 81 assert_template 'new'
82 82 end
83 83
84 84 def test_edit
85 85 get :edit, :id => 10
86 86 assert_response :success
87 87 assert_template 'edit'
88 88
89 89 assert_select 'div#tab-content-users'
90 90 assert_select 'div#tab-content-memberships' do
91 91 assert_select 'a', :text => 'Private child of eCookbook'
92 92 end
93 93 end
94 94
95 95 def test_update
96 96 new_name = 'New name'
97 97 put :update, :id => 10, :group => {:name => new_name}
98 98 assert_redirected_to '/groups'
99 99 group = Group.find(10)
100 100 assert_equal new_name, group.name
101 101 end
102 102
103 103 def test_update_with_failure
104 104 put :update, :id => 10, :group => {:name => ''}
105 105 assert_response :success
106 106 assert_template 'edit'
107 107 end
108 108
109 109 def test_destroy
110 110 assert_difference 'Group.count', -1 do
111 111 post :destroy, :id => 10
112 112 end
113 113 assert_redirected_to '/groups'
114 114 end
115 115
116 def test_new_users
117 get :new_users, :id => 10
118 assert_response :success
119 assert_template 'new_users'
120 end
121
122 def test_xhr_new_users
123 xhr :get, :new_users, :id => 10
124 assert_response :success
125 assert_equal 'text/javascript', response.content_type
126 end
127
116 128 def test_add_users
117 129 assert_difference 'Group.find(10).users.count', 2 do
118 130 post :add_users, :id => 10, :user_ids => ['2', '3']
119 131 end
120 132 end
121 133
122 134 def test_xhr_add_users
123 135 assert_difference 'Group.find(10).users.count', 2 do
124 136 xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
125 137 assert_response :success
126 138 assert_template 'add_users'
127 139 assert_equal 'text/javascript', response.content_type
128 140 end
129 141 assert_match /John Smith/, response.body
130 142 end
131 143
132 144 def test_remove_user
133 145 assert_difference 'Group.find(10).users.count', -1 do
134 146 delete :remove_user, :id => 10, :user_id => '8'
135 147 end
136 148 end
137 149
138 150 def test_xhr_remove_user
139 151 assert_difference 'Group.find(10).users.count', -1 do
140 152 xhr :delete, :remove_user, :id => 10, :user_id => '8'
141 153 assert_response :success
142 154 assert_template 'remove_user'
143 155 assert_equal 'text/javascript', response.content_type
144 156 end
145 157 end
146 158
147 159 def test_autocomplete_for_user
148 160 xhr :get, :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
149 161 assert_response :success
150 162 assert_include 'John Smith', response.body
151 163 end
152 164 end
@@ -1,98 +1,102
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 RoutingGroupsTest < ActionDispatch::IntegrationTest
21 21 def test_groups_resources
22 22 assert_routing(
23 23 { :method => 'get', :path => "/groups" },
24 24 { :controller => 'groups', :action => 'index' }
25 25 )
26 26 assert_routing(
27 27 { :method => 'get', :path => "/groups.xml" },
28 28 { :controller => 'groups', :action => 'index', :format => 'xml' }
29 29 )
30 30 assert_routing(
31 31 { :method => 'post', :path => "/groups" },
32 32 { :controller => 'groups', :action => 'create' }
33 33 )
34 34 assert_routing(
35 35 { :method => 'post', :path => "/groups.xml" },
36 36 { :controller => 'groups', :action => 'create', :format => 'xml' }
37 37 )
38 38 assert_routing(
39 39 { :method => 'get', :path => "/groups/new" },
40 40 { :controller => 'groups', :action => 'new' }
41 41 )
42 42 assert_routing(
43 43 { :method => 'get', :path => "/groups/1/edit" },
44 44 { :controller => 'groups', :action => 'edit', :id => '1' }
45 45 )
46 46 assert_routing(
47 47 { :method => 'get', :path => "/groups/1/autocomplete_for_user" },
48 48 { :controller => 'groups', :action => 'autocomplete_for_user', :id => '1' }
49 49 )
50 50 assert_routing(
51 51 { :method => 'get', :path => "/groups/1/autocomplete_for_user.js" },
52 52 { :controller => 'groups', :action => 'autocomplete_for_user', :id => '1', :format => 'js' }
53 53 )
54 54 assert_routing(
55 55 { :method => 'get', :path => "/groups/1" },
56 56 { :controller => 'groups', :action => 'show', :id => '1' }
57 57 )
58 58 assert_routing(
59 59 { :method => 'get', :path => "/groups/1.xml" },
60 60 { :controller => 'groups', :action => 'show', :id => '1', :format => 'xml' }
61 61 )
62 62 assert_routing(
63 63 { :method => 'put', :path => "/groups/1" },
64 64 { :controller => 'groups', :action => 'update', :id => '1' }
65 65 )
66 66 assert_routing(
67 67 { :method => 'put', :path => "/groups/1.xml" },
68 68 { :controller => 'groups', :action => 'update', :id => '1', :format => 'xml' }
69 69 )
70 70 assert_routing(
71 71 { :method => 'delete', :path => "/groups/1" },
72 72 { :controller => 'groups', :action => 'destroy', :id => '1' }
73 73 )
74 74 assert_routing(
75 75 { :method => 'delete', :path => "/groups/1.xml" },
76 76 { :controller => 'groups', :action => 'destroy', :id => '1', :format => 'xml' }
77 77 )
78 78 end
79 79
80 80 def test_groups
81 81 assert_routing(
82 { :method => 'get', :path => "/groups/567/users/new" },
83 { :controller => 'groups', :action => 'new_users', :id => '567' }
84 )
85 assert_routing(
82 86 { :method => 'post', :path => "/groups/567/users" },
83 87 { :controller => 'groups', :action => 'add_users', :id => '567' }
84 88 )
85 89 assert_routing(
86 90 { :method => 'post', :path => "/groups/567/users.xml" },
87 91 { :controller => 'groups', :action => 'add_users', :id => '567', :format => 'xml' }
88 92 )
89 93 assert_routing(
90 94 { :method => 'delete', :path => "/groups/567/users/12" },
91 95 { :controller => 'groups', :action => 'remove_user', :id => '567', :user_id => '12' }
92 96 )
93 97 assert_routing(
94 98 { :method => 'delete', :path => "/groups/567/users/12.xml" },
95 99 { :controller => 'groups', :action => 'remove_user', :id => '567', :user_id => '12', :format => 'xml' }
96 100 )
97 101 end
98 102 end
General Comments 0
You need to be logged in to leave comments. Login now