##// END OF EJS Templates
Redirect to referer to preserve pagination and filter....
Jean-Philippe Lang -
r15376:f435d1844d9e
parent child
Show More
@@ -1,154 +1,154
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 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_action :require_admin
22 22 before_action :find_group, :except => [:index, :new, :create]
23 23 accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user
24 24
25 25 require_sudo_mode :add_users, :remove_user, :create, :update, :destroy, :edit_membership, :destroy_membership
26 26
27 27 helper :custom_fields
28 28 helper :principal_memberships
29 29
30 30 def index
31 31 respond_to do |format|
32 32 format.html {
33 33 scope = Group.sorted
34 34 scope = scope.like(params[:name]) if params[:name].present?
35 35
36 36 @group_count = scope.count
37 37 @group_pages = Paginator.new @group_count, per_page_option, params['page']
38 38 @groups = scope.limit(@group_pages.per_page).offset(@group_pages.offset).to_a
39 39 @user_count_by_group_id = user_count_by_group_id
40 40 }
41 41 format.api {
42 42 scope = Group.sorted
43 43 scope = scope.givable unless params[:builtin] == '1'
44 44 @groups = scope.to_a
45 45 }
46 46 end
47 47 end
48 48
49 49 def show
50 50 respond_to do |format|
51 51 format.html
52 52 format.api
53 53 end
54 54 end
55 55
56 56 def new
57 57 @group = Group.new
58 58 end
59 59
60 60 def create
61 61 @group = Group.new
62 62 @group.safe_attributes = params[:group]
63 63
64 64 respond_to do |format|
65 65 if @group.save
66 66 format.html {
67 67 flash[:notice] = l(:notice_successful_create)
68 68 redirect_to(params[:continue] ? new_group_path : groups_path)
69 69 }
70 70 format.api { render :action => 'show', :status => :created, :location => group_url(@group) }
71 71 else
72 72 format.html { render :action => "new" }
73 73 format.api { render_validation_errors(@group) }
74 74 end
75 75 end
76 76 end
77 77
78 78 def edit
79 79 end
80 80
81 81 def update
82 82 @group.safe_attributes = params[:group]
83 83
84 84 respond_to do |format|
85 85 if @group.save
86 86 flash[:notice] = l(:notice_successful_update)
87 format.html { redirect_to(groups_path) }
87 format.html { redirect_to_referer_or(groups_path) }
88 88 format.api { render_api_ok }
89 89 else
90 90 format.html { render :action => "edit" }
91 91 format.api { render_validation_errors(@group) }
92 92 end
93 93 end
94 94 end
95 95
96 96 def destroy
97 97 @group.destroy
98 98
99 99 respond_to do |format|
100 format.html { redirect_to(groups_path) }
100 format.html { redirect_to_referer_or(groups_path) }
101 101 format.api { render_api_ok }
102 102 end
103 103 end
104 104
105 105 def new_users
106 106 end
107 107
108 108 def add_users
109 109 @users = User.not_in_group(@group).where(:id => (params[:user_id] || params[:user_ids])).to_a
110 110 @group.users << @users
111 111 respond_to do |format|
112 112 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
113 113 format.js
114 114 format.api {
115 115 if @users.any?
116 116 render_api_ok
117 117 else
118 118 render_api_errors "#{l(:label_user)} #{l('activerecord.errors.messages.invalid')}"
119 119 end
120 120 }
121 121 end
122 122 end
123 123
124 124 def remove_user
125 125 @group.users.delete(User.find(params[:user_id])) if request.delete?
126 126 respond_to do |format|
127 127 format.html { redirect_to edit_group_path(@group, :tab => 'users') }
128 128 format.js
129 129 format.api { render_api_ok }
130 130 end
131 131 end
132 132
133 133 def autocomplete_for_user
134 134 respond_to do |format|
135 135 format.js
136 136 end
137 137 end
138 138
139 139 private
140 140
141 141 def find_group
142 142 @group = Group.find(params[:id])
143 143 rescue ActiveRecord::RecordNotFound
144 144 render_404
145 145 end
146 146
147 147 def user_count_by_group_id
148 148 h = User.joins(:groups).group('group_id').count
149 149 h.keys.each do |key|
150 150 h[key.to_i] = h.delete(key)
151 151 end
152 152 h
153 153 end
154 154 end
General Comments 0
You need to be logged in to leave comments. Login now