##// END OF EJS Templates
remove trailing tabs from app/controllers/users_controller.rb...
Toshi MARUYAMA -
r11189:e0215681b480
parent child
Show More
@@ -1,212 +1,212
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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 UsersController < ApplicationController
19 19 layout 'admin'
20 20
21 21 before_filter :require_admin, :except => :show
22 22 before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership]
23 23 accept_api_auth :index, :show, :create, :update, :destroy
24 24
25 25 helper :sort
26 26 include SortHelper
27 27 helper :custom_fields
28 28 include CustomFieldsHelper
29 29
30 30 def index
31 31 sort_init 'login', 'asc'
32 32 sort_update %w(login firstname lastname mail admin created_on last_login_on)
33 33
34 34 case params[:format]
35 35 when 'xml', 'json'
36 36 @offset, @limit = api_offset_and_limit
37 37 else
38 38 @limit = per_page_option
39 39 end
40 40
41 41 @status = params[:status] || 1
42 42
43 43 scope = User.logged.status(@status)
44 44 scope = scope.like(params[:name]) if params[:name].present?
45 45 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
46 46
47 47 @user_count = scope.count
48 48 @user_pages = Paginator.new @user_count, @limit, params['page']
49 49 @offset ||= @user_pages.offset
50 50 @users = scope.order(sort_clause).limit(@limit).offset(@offset).all
51 51
52 52 respond_to do |format|
53 53 format.html {
54 54 @groups = Group.all.sort
55 55 render :layout => !request.xhr?
56 56 }
57 57 format.api
58 end
58 end
59 59 end
60 60
61 61 def show
62 62 # show projects based on current user visibility
63 63 @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
64 64
65 65 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
66 66 @events_by_day = events.group_by(&:event_date)
67 67
68 68 unless User.current.admin?
69 69 if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?)
70 70 render_404
71 71 return
72 72 end
73 73 end
74 74
75 75 respond_to do |format|
76 76 format.html { render :layout => 'base' }
77 77 format.api
78 78 end
79 79 end
80 80
81 81 def new
82 82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
83 83 @auth_sources = AuthSource.all
84 84 end
85 85
86 86 def create
87 87 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
88 88 @user.safe_attributes = params[:user]
89 89 @user.admin = params[:user][:admin] || false
90 90 @user.login = params[:user][:login]
91 91 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
92 92
93 93 if @user.save
94 94 @user.pref.attributes = params[:pref]
95 95 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
96 96 @user.pref.save
97 97 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
98 98
99 99 Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
100 100
101 101 respond_to do |format|
102 102 format.html {
103 103 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
104 104 if params[:continue]
105 105 redirect_to new_user_path
106 106 else
107 107 redirect_to edit_user_path(@user)
108 108 end
109 109 }
110 110 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
111 111 end
112 112 else
113 113 @auth_sources = AuthSource.all
114 114 # Clear password input
115 115 @user.password = @user.password_confirmation = nil
116 116
117 117 respond_to do |format|
118 118 format.html { render :action => 'new' }
119 119 format.api { render_validation_errors(@user) }
120 120 end
121 121 end
122 122 end
123 123
124 124 def edit
125 125 @auth_sources = AuthSource.all
126 126 @membership ||= Member.new
127 127 end
128 128
129 129 def update
130 130 @user.admin = params[:user][:admin] if params[:user][:admin]
131 131 @user.login = params[:user][:login] if params[:user][:login]
132 132 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
133 133 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
134 134 end
135 135 @user.safe_attributes = params[:user]
136 136 # Was the account actived ? (do it before User#save clears the change)
137 137 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
138 138 # TODO: Similar to My#account
139 139 @user.pref.attributes = params[:pref]
140 140 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
141 141
142 142 if @user.save
143 143 @user.pref.save
144 144 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
145 145
146 146 if was_activated
147 147 Mailer.account_activated(@user).deliver
148 148 elsif @user.active? && params[:send_information] && !params[:user][:password].blank? && @user.auth_source_id.nil?
149 149 Mailer.account_information(@user, params[:user][:password]).deliver
150 150 end
151 151
152 152 respond_to do |format|
153 153 format.html {
154 154 flash[:notice] = l(:notice_successful_update)
155 155 redirect_to_referer_or edit_user_path(@user)
156 156 }
157 157 format.api { render_api_ok }
158 158 end
159 159 else
160 160 @auth_sources = AuthSource.all
161 161 @membership ||= Member.new
162 162 # Clear password input
163 163 @user.password = @user.password_confirmation = nil
164 164
165 165 respond_to do |format|
166 166 format.html { render :action => :edit }
167 167 format.api { render_validation_errors(@user) }
168 168 end
169 169 end
170 170 end
171 171
172 172 def destroy
173 173 @user.destroy
174 174 respond_to do |format|
175 175 format.html { redirect_back_or_default(users_path) }
176 176 format.api { render_api_ok }
177 177 end
178 178 end
179 179
180 180 def edit_membership
181 181 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
182 182 @membership.save
183 183 respond_to do |format|
184 184 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
185 185 format.js
186 186 end
187 187 end
188 188
189 189 def destroy_membership
190 190 @membership = Member.find(params[:membership_id])
191 191 if @membership.deletable?
192 192 @membership.destroy
193 193 end
194 194 respond_to do |format|
195 195 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
196 196 format.js
197 197 end
198 198 end
199 199
200 200 private
201 201
202 202 def find_user
203 203 if params[:id] == 'current'
204 204 require_login || return
205 205 @user = User.current
206 206 else
207 207 @user = User.find(params[:id])
208 208 end
209 209 rescue ActiveRecord::RecordNotFound
210 210 render_404
211 211 end
212 212 end
General Comments 0
You need to be logged in to leave comments. Login now