Mercurial > hg > soundsoftware-site
comparison .svn/pristine/42/4253341f27fc3e107be2ed027175bb96fadeecca.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 class UsersController < ApplicationController | |
19 layout 'admin' | |
20 | |
21 before_filter :require_admin, :except => :show | |
22 before_filter :find_user, :only => [:show, :edit, :update, :destroy, :edit_membership, :destroy_membership] | |
23 accept_api_auth :index, :show, :create, :update, :destroy | |
24 | |
25 helper :sort | |
26 include SortHelper | |
27 helper :custom_fields | |
28 include CustomFieldsHelper | |
29 | |
30 def index | |
31 sort_init 'login', 'asc' | |
32 sort_update %w(login firstname lastname mail admin created_on last_login_on) | |
33 | |
34 case params[:format] | |
35 when 'xml', 'json' | |
36 @offset, @limit = api_offset_and_limit | |
37 else | |
38 @limit = per_page_option | |
39 end | |
40 | |
41 @status = params[:status] || 1 | |
42 | |
43 scope = User.logged.status(@status) | |
44 scope = scope.like(params[:name]) if params[:name].present? | |
45 scope = scope.in_group(params[:group_id]) if params[:group_id].present? | |
46 | |
47 @user_count = scope.count | |
48 @user_pages = Paginator.new @user_count, @limit, params['page'] | |
49 @offset ||= @user_pages.offset | |
50 @users = scope.order(sort_clause).limit(@limit).offset(@offset).all | |
51 | |
52 respond_to do |format| | |
53 format.html { | |
54 @groups = Group.all.sort | |
55 render :layout => !request.xhr? | |
56 } | |
57 format.api | |
58 end | |
59 end | |
60 | |
61 def show | |
62 # show projects based on current user visibility | |
63 @memberships = @user.memberships.where(Project.visible_condition(User.current)).all | |
64 | |
65 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10) | |
66 @events_by_day = events.group_by(&:event_date) | |
67 | |
68 unless User.current.admin? | |
69 if !@user.active? || (@user != User.current && @memberships.empty? && events.empty?) | |
70 render_404 | |
71 return | |
72 end | |
73 end | |
74 | |
75 respond_to do |format| | |
76 format.html { render :layout => 'base' } | |
77 format.api | |
78 end | |
79 end | |
80 | |
81 def new | |
82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
83 @user.safe_attributes = params[:user] | |
84 @auth_sources = AuthSource.all | |
85 end | |
86 | |
87 def create | |
88 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option) | |
89 @user.safe_attributes = params[:user] | |
90 @user.admin = params[:user][:admin] || false | |
91 @user.login = params[:user][:login] | |
92 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id | |
93 @user.pref.attributes = params[:pref] | |
94 | |
95 if @user.save | |
96 Mailer.account_information(@user, @user.password).deliver if params[:send_information] | |
97 | |
98 respond_to do |format| | |
99 format.html { | |
100 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user))) | |
101 if params[:continue] | |
102 attrs = params[:user].slice(:generate_password) | |
103 redirect_to new_user_path(:user => attrs) | |
104 else | |
105 redirect_to edit_user_path(@user) | |
106 end | |
107 } | |
108 format.api { render :action => 'show', :status => :created, :location => user_url(@user) } | |
109 end | |
110 else | |
111 @auth_sources = AuthSource.all | |
112 # Clear password input | |
113 @user.password = @user.password_confirmation = nil | |
114 | |
115 respond_to do |format| | |
116 format.html { render :action => 'new' } | |
117 format.api { render_validation_errors(@user) } | |
118 end | |
119 end | |
120 end | |
121 | |
122 def edit | |
123 @auth_sources = AuthSource.all | |
124 @membership ||= Member.new | |
125 end | |
126 | |
127 def update | |
128 @user.admin = params[:user][:admin] if params[:user][:admin] | |
129 @user.login = params[:user][:login] if params[:user][:login] | |
130 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?) | |
131 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] | |
132 end | |
133 @user.safe_attributes = params[:user] | |
134 # Was the account actived ? (do it before User#save clears the change) | |
135 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE]) | |
136 # TODO: Similar to My#account | |
137 @user.pref.attributes = params[:pref] | |
138 | |
139 if @user.save | |
140 @user.pref.save | |
141 | |
142 if was_activated | |
143 Mailer.account_activated(@user).deliver | |
144 elsif @user.active? && params[:send_information] && @user.password.present? && @user.auth_source_id.nil? | |
145 Mailer.account_information(@user, @user.password).deliver | |
146 end | |
147 | |
148 respond_to do |format| | |
149 format.html { | |
150 flash[:notice] = l(:notice_successful_update) | |
151 redirect_to_referer_or edit_user_path(@user) | |
152 } | |
153 format.api { render_api_ok } | |
154 end | |
155 else | |
156 @auth_sources = AuthSource.all | |
157 @membership ||= Member.new | |
158 # Clear password input | |
159 @user.password = @user.password_confirmation = nil | |
160 | |
161 respond_to do |format| | |
162 format.html { render :action => :edit } | |
163 format.api { render_validation_errors(@user) } | |
164 end | |
165 end | |
166 end | |
167 | |
168 def destroy | |
169 @user.destroy | |
170 respond_to do |format| | |
171 format.html { redirect_back_or_default(users_path) } | |
172 format.api { render_api_ok } | |
173 end | |
174 end | |
175 | |
176 def edit_membership | |
177 @membership = Member.edit_membership(params[:membership_id], params[:membership], @user) | |
178 @membership.save | |
179 respond_to do |format| | |
180 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') } | |
181 format.js | |
182 end | |
183 end | |
184 | |
185 def destroy_membership | |
186 @membership = Member.find(params[:membership_id]) | |
187 if @membership.deletable? | |
188 @membership.destroy | |
189 end | |
190 respond_to do |format| | |
191 format.html { redirect_to edit_user_path(@user, :tab => 'memberships') } | |
192 format.js | |
193 end | |
194 end | |
195 | |
196 private | |
197 | |
198 def find_user | |
199 if params[:id] == 'current' | |
200 require_login || return | |
201 @user = User.current | |
202 else | |
203 @user = User.find(params[:id]) | |
204 end | |
205 rescue ActiveRecord::RecordNotFound | |
206 render_404 | |
207 end | |
208 end |