##// END OF EJS Templates
Don't load user activity for API responses (#18128)....
Jean-Philippe Lang -
r13205:c74098bbd696
parent child
Show More
@@ -1,187 +1,188
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 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]
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 helper :principal_memberships
30 30
31 31 def index
32 32 sort_init 'login', 'asc'
33 33 sort_update %w(login firstname lastname mail admin created_on last_login_on)
34 34
35 35 case params[:format]
36 36 when 'xml', 'json'
37 37 @offset, @limit = api_offset_and_limit
38 38 else
39 39 @limit = per_page_option
40 40 end
41 41
42 42 @status = params[:status] || 1
43 43
44 44 scope = User.logged.status(@status)
45 45 scope = scope.like(params[:name]) if params[:name].present?
46 46 scope = scope.in_group(params[:group_id]) if params[:group_id].present?
47 47
48 48 @user_count = scope.count
49 49 @user_pages = Paginator.new @user_count, @limit, params['page']
50 50 @offset ||= @user_pages.offset
51 51 @users = scope.order(sort_clause).limit(@limit).offset(@offset).to_a
52 52
53 53 respond_to do |format|
54 54 format.html {
55 55 @groups = Group.all.sort
56 56 render :layout => !request.xhr?
57 57 }
58 58 format.api
59 59 end
60 60 end
61 61
62 62 def show
63 63 unless @user.visible?
64 64 render_404
65 65 return
66 66 end
67 67
68 68 # show projects based on current user visibility
69 69 @memberships = @user.memberships.where(Project.visible_condition(User.current)).to_a
70 70
71 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
72 @events_by_day = events.group_by(&:event_date)
73
74 71 respond_to do |format|
75 format.html { render :layout => 'base' }
72 format.html {
73 events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
74 @events_by_day = events.group_by(&:event_date)
75 render :layout => 'base'
76 }
76 77 format.api
77 78 end
78 79 end
79 80
80 81 def new
81 82 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
82 83 @user.safe_attributes = params[:user]
83 84 @auth_sources = AuthSource.all
84 85 end
85 86
86 87 def create
87 88 @user = User.new(:language => Setting.default_language, :mail_notification => Setting.default_notification_option)
88 89 @user.safe_attributes = params[:user]
89 90 @user.admin = params[:user][:admin] || false
90 91 @user.login = params[:user][:login]
91 92 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id
92 93 @user.pref.attributes = params[:pref] if params[:pref]
93 94
94 95 if @user.save
95 96 Mailer.account_information(@user, @user.password).deliver if params[:send_information]
96 97
97 98 respond_to do |format|
98 99 format.html {
99 100 flash[:notice] = l(:notice_user_successful_create, :id => view_context.link_to(@user.login, user_path(@user)))
100 101 if params[:continue]
101 102 attrs = params[:user].slice(:generate_password)
102 103 redirect_to new_user_path(:user => attrs)
103 104 else
104 105 redirect_to edit_user_path(@user)
105 106 end
106 107 }
107 108 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
108 109 end
109 110 else
110 111 @auth_sources = AuthSource.all
111 112 # Clear password input
112 113 @user.password = @user.password_confirmation = nil
113 114
114 115 respond_to do |format|
115 116 format.html { render :action => 'new' }
116 117 format.api { render_validation_errors(@user) }
117 118 end
118 119 end
119 120 end
120 121
121 122 def edit
122 123 @auth_sources = AuthSource.all
123 124 @membership ||= Member.new
124 125 end
125 126
126 127 def update
127 128 @user.admin = params[:user][:admin] if params[:user][:admin]
128 129 @user.login = params[:user][:login] if params[:user][:login]
129 130 if params[:user][:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
130 131 @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation]
131 132 end
132 133 @user.safe_attributes = params[:user]
133 134 # Was the account actived ? (do it before User#save clears the change)
134 135 was_activated = (@user.status_change == [User::STATUS_REGISTERED, User::STATUS_ACTIVE])
135 136 # TODO: Similar to My#account
136 137 @user.pref.attributes = params[:pref] if params[:pref]
137 138
138 139 if @user.save
139 140 @user.pref.save
140 141
141 142 if was_activated
142 143 Mailer.account_activated(@user).deliver
143 144 elsif @user.active? && params[:send_information] && @user.password.present? && @user.auth_source_id.nil?
144 145 Mailer.account_information(@user, @user.password).deliver
145 146 end
146 147
147 148 respond_to do |format|
148 149 format.html {
149 150 flash[:notice] = l(:notice_successful_update)
150 151 redirect_to_referer_or edit_user_path(@user)
151 152 }
152 153 format.api { render_api_ok }
153 154 end
154 155 else
155 156 @auth_sources = AuthSource.all
156 157 @membership ||= Member.new
157 158 # Clear password input
158 159 @user.password = @user.password_confirmation = nil
159 160
160 161 respond_to do |format|
161 162 format.html { render :action => :edit }
162 163 format.api { render_validation_errors(@user) }
163 164 end
164 165 end
165 166 end
166 167
167 168 def destroy
168 169 @user.destroy
169 170 respond_to do |format|
170 171 format.html { redirect_back_or_default(users_path) }
171 172 format.api { render_api_ok }
172 173 end
173 174 end
174 175
175 176 private
176 177
177 178 def find_user
178 179 if params[:id] == 'current'
179 180 require_login || return
180 181 @user = User.current
181 182 else
182 183 @user = User.find(params[:id])
183 184 end
184 185 rescue ActiveRecord::RecordNotFound
185 186 render_404
186 187 end
187 188 end
General Comments 0
You need to be logged in to leave comments. Login now