comparison app/controllers/users_controller.rb @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents 433d4f72a19b
children 4f746d8966dd
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
43 scope = User.logged.status(@status) 43 scope = User.logged.status(@status)
44 scope = scope.like(params[:name]) if params[:name].present? 44 scope = scope.like(params[:name]) if params[:name].present?
45 scope = scope.in_group(params[:group_id]) if params[:group_id].present? 45 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
46 46
47 @user_count = scope.count 47 @user_count = scope.count
48 @user_pages = Paginator.new self, @user_count, @limit, params['page'] 48 @user_pages = Paginator.new @user_count, @limit, params['page']
49 @offset ||= @user_pages.current.offset 49 @offset ||= @user_pages.offset
50 @users = scope.find :all, 50 @users = scope.order(sort_clause).limit(@limit).offset(@offset).all
51 :order => sort_clause,
52 :limit => @limit,
53 :offset => @offset
54 51
55 respond_to do |format| 52 respond_to do |format|
56 format.html { 53 format.html {
57 @groups = Group.all.sort 54 @groups = Group.all.sort
58 render :layout => !request.xhr? 55 render :layout => !request.xhr?
59 } 56 }
60 format.api 57 format.api
61 end 58 end
62 end 59 end
63 60
64 def show 61 def show
65 # show projects based on current user visibility 62 # show projects based on current user visibility
66 @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current)) 63 @memberships = @user.memberships.all(:conditions => Project.visible_condition(User.current))
81 end 78 end
82 end 79 end
83 80
84 def new 81 def new
85 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) 82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
86 @auth_sources = AuthSource.find(:all) 83 @auth_sources = AuthSource.all
87 end 84 end
88 85
89 def create 86 def create
90 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) 87 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
91 @user.safe_attributes = params[:user] 88 @user.safe_attributes = params[:user]
102 Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information] 99 Mailer.account_information(@user, params[:user][:password]).deliver if params[:send_information]
103 100
104 respond_to do |format| 101 respond_to do |format|
105 format.html { 102 format.html {
106 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) 103 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
107 redirect_to(params[:continue] ? 104 if params[:continue]
108 {:controller => 'users', :action => 'new'} : 105 redirect_to new_user_path
109 {:controller => 'users', :action => 'edit', :id => @user} 106 else
110 ) 107 redirect_to edit_user_path(@user)
108 end
111 } 109 }
112 format.api { render :action => 'show', :status => :created, :location => user_url(@user) } 110 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
113 end 111 end
114 else 112 else
115 @auth_sources = AuthSource.find(:all) 113 @auth_sources = AuthSource.all
116 # Clear password input 114 # Clear password input
117 @user.password = @user.password_confirmation = nil 115 @user.password = @user.password_confirmation = nil
118 116
119 respond_to do |format| 117 respond_to do |format|
120 format.html { render :action => 'new' } 118 format.html { render :action => 'new' }
122 end 120 end
123 end 121 end
124 end 122 end
125 123
126 def edit 124 def edit
127 @auth_sources = AuthSource.find(:all) 125 @auth_sources = AuthSource.all
128 @membership ||= Member.new 126 @membership ||= Member.new
129 end 127 end
130 128
131 def update 129 def update
132 @user.admin = params[:user][:admin] if params[:user][:admin] 130 @user.admin = params[:user][:admin] if params[:user][:admin]
157 redirect_to_referer_or edit_user_path(@user) 155 redirect_to_referer_or edit_user_path(@user)
158 } 156 }
159 format.api { render_api_ok } 157 format.api { render_api_ok }
160 end 158 end
161 else 159 else
162 @auth_sources = AuthSource.find(:all) 160 @auth_sources = AuthSource.all
163 @membership ||= Member.new 161 @membership ||= Member.new
164 # Clear password input 162 # Clear password input
165 @user.password = @user.password_confirmation = nil 163 @user.password = @user.password_confirmation = nil
166 164
167 respond_to do |format| 165 respond_to do |format|
172 end 170 end
173 171
174 def destroy 172 def destroy
175 @user.destroy 173 @user.destroy
176 respond_to do |format| 174 respond_to do |format|
177 format.html { redirect_back_or_default(users_url) } 175 format.html { redirect_back_or_default(users_path) }
178 format.api { render_api_ok } 176 format.api { render_api_ok }
179 end 177 end
180 end 178 end
181 179
182 def edit_membership 180 def edit_membership
183 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) 181 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user)
184 @membership.save 182 @membership.save
185 respond_to do |format| 183 respond_to do |format|
186 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } 184 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
187 format.js 185 format.js
188 end 186 end
189 end 187 end
190 188
191 def destroy_membership 189 def destroy_membership
192 @membership = Member.find(params[:membership_id]) 190 @membership = Member.find(params[:membership_id])
193 if @membership.deletable? 191 if @membership.deletable?
194 @membership.destroy 192 @membership.destroy
195 end 193 end
196 respond_to do |format| 194 respond_to do |format|
197 format.html { redirect_to :controller => 'users', :action => 'edit', :id => @user, :tab => 'memberships' } 195 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') }
198 format.js 196 format.js
199 end 197 end
200 end 198 end
201 199
202 private 200 private