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