Chris@0
|
1 # Redmine - project management software
|
Chris@1494
|
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@0
|
18 class MyController < ApplicationController
|
Chris@0
|
19 before_filter :require_login
|
Chris@1464
|
20 # let user change user's password when user has to
|
Chris@1464
|
21 skip_before_filter :check_password_change, :only => :password
|
Chris@0
|
22
|
Chris@0
|
23 helper :issues
|
Chris@117
|
24 helper :users
|
Chris@0
|
25 helper :custom_fields
|
chris@1086
|
26 helper :projects
|
chris@1217
|
27 helper :activities
|
Chris@0
|
28
|
Chris@0
|
29 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
Chris@0
|
30 'issuesreportedbyme' => :label_reported_issues,
|
Chris@0
|
31 'issueswatched' => :label_watched_issues,
|
chris@344
|
32 'activitymyprojects' => :label_activity_my_recent,
|
Chris@0
|
33 'news' => :label_news_latest,
|
chris@363
|
34 'tipoftheday' => :label_tipoftheday,
|
Chris@0
|
35 'calendar' => :label_calendar,
|
Chris@0
|
36 'documents' => :label_document_plural,
|
chris@1086
|
37 'timelog' => :label_spent_time,
|
chris@1217
|
38 'myprojects' => :label_my_projects,
|
chris@1217
|
39 'colleagues' => :label_my_colleagues
|
Chris@0
|
40 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
|
Chris@0
|
41
|
chris@1164
|
42 DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'],
|
Chris@1304
|
43 'right' => ['colleagues', 'tipoftheday', 'issueswatched']
|
Chris@0
|
44 }.freeze
|
Chris@0
|
45
|
Chris@0
|
46 def index
|
Chris@0
|
47 page
|
Chris@0
|
48 render :action => 'page'
|
Chris@0
|
49 end
|
Chris@0
|
50
|
Chris@0
|
51 # Show user's page
|
Chris@0
|
52 def page
|
Chris@0
|
53 @user = User.current
|
Chris@0
|
54 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
Chris@0
|
55 end
|
Chris@0
|
56
|
Chris@0
|
57 # Edit user's account
|
Chris@0
|
58 def account
|
Chris@0
|
59 @user = User.current
|
Chris@0
|
60 @pref = @user.pref
|
luisf@108
|
61 @ssamr_user_details = @user.ssamr_user_detail
|
luisf@164
|
62
|
luisf@188
|
63
|
luisf@188
|
64 if @user.ssamr_user_detail == nil
|
luisf@188
|
65 @selected_institution_id = nil
|
luisf@188
|
66 else
|
luisf@188
|
67 @selected_institution_id = @ssamr_user_details.institution_id.to_i
|
luisf@188
|
68 end
|
luisf@188
|
69
|
Chris@0
|
70 if request.post?
|
Chris@117
|
71 @user.safe_attributes = params[:user]
|
Chris@0
|
72 @user.pref.attributes = params[:pref]
|
Chris@1484
|
73
|
Chris@909
|
74 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
|
luisf@108
|
75
|
luisf@108
|
76 if @user.ssamr_user_detail == nil
|
luisf@108
|
77 @ssamr_user_details = SsamrUserDetail.new()
|
luisf@108
|
78 @user.ssamr_user_detail = @ssamr_user_details
|
luisf@108
|
79 else
|
luisf@108
|
80 @ssamr_user_details = @user.ssamr_user_detail
|
luisf@108
|
81 end
|
luisf@108
|
82
|
luisf@108
|
83 if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty?
|
luisf@108
|
84 @ssamr_user_details.description = @user.ssamr_user_detail.description
|
luisf@108
|
85 @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id
|
luisf@164
|
86 @institution_type = @ssamr_user_details.institution_type
|
luisf@164
|
87 @other_institution = @ssamr_user_details.other_institution
|
luisf@108
|
88 else
|
luisf@108
|
89 @ssamr_user_details.description = params[:ssamr_user_details][:description]
|
luisf@108
|
90 @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id]
|
luisf@164
|
91 @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type]
|
luisf@164
|
92 @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution]
|
luisf@108
|
93 end
|
luisf@164
|
94
|
Chris@0
|
95 if @user.save
|
Chris@0
|
96 @user.pref.save
|
Chris@0
|
97 set_language_if_valid @user.language
|
Chris@0
|
98 flash[:notice] = l(:notice_account_updated)
|
Chris@1464
|
99 redirect_to my_account_path
|
Chris@0
|
100 return
|
Chris@0
|
101 end
|
Chris@0
|
102 end
|
Chris@0
|
103 end
|
Chris@0
|
104
|
Chris@1115
|
105 # Destroys user's account
|
Chris@1115
|
106 def destroy
|
Chris@1115
|
107 @user = User.current
|
Chris@1115
|
108 unless @user.own_account_deletable?
|
Chris@1464
|
109 redirect_to my_account_path
|
Chris@1115
|
110 return
|
Chris@1115
|
111 end
|
Chris@1115
|
112
|
Chris@1115
|
113 if request.post? && params[:confirm]
|
Chris@1115
|
114 @user.destroy
|
Chris@1115
|
115 if @user.destroyed?
|
Chris@1115
|
116 logout_user
|
Chris@1115
|
117 flash[:notice] = l(:notice_account_deleted)
|
Chris@1115
|
118 end
|
Chris@1115
|
119 redirect_to home_path
|
Chris@1115
|
120 end
|
Chris@1115
|
121 end
|
Chris@1115
|
122
|
Chris@0
|
123 # Manage user's password
|
Chris@0
|
124 def password
|
Chris@0
|
125 @user = User.current
|
Chris@0
|
126 unless @user.change_password_allowed?
|
Chris@0
|
127 flash[:error] = l(:notice_can_t_change_password)
|
Chris@1464
|
128 redirect_to my_account_path
|
Chris@0
|
129 return
|
Chris@0
|
130 end
|
Chris@0
|
131 if request.post?
|
Chris@1464
|
132 if !@user.check_password?(params[:password])
|
Chris@1464
|
133 flash.now[:error] = l(:notice_account_wrong_password)
|
Chris@1464
|
134 elsif params[:password] == params[:new_password]
|
Chris@1464
|
135 flash.now[:error] = l(:notice_new_password_must_be_different)
|
Chris@1464
|
136 else
|
Chris@0
|
137 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
Chris@1464
|
138 @user.must_change_passwd = false
|
Chris@0
|
139 if @user.save
|
Chris@0
|
140 flash[:notice] = l(:notice_account_password_updated)
|
Chris@1464
|
141 redirect_to my_account_path
|
Chris@0
|
142 end
|
Chris@0
|
143 end
|
Chris@0
|
144 end
|
Chris@0
|
145 end
|
Chris@909
|
146
|
Chris@0
|
147 # Create a new feeds key
|
Chris@0
|
148 def reset_rss_key
|
Chris@0
|
149 if request.post?
|
Chris@0
|
150 if User.current.rss_token
|
Chris@0
|
151 User.current.rss_token.destroy
|
Chris@0
|
152 User.current.reload
|
Chris@0
|
153 end
|
Chris@0
|
154 User.current.rss_key
|
Chris@0
|
155 flash[:notice] = l(:notice_feeds_access_key_reseted)
|
Chris@0
|
156 end
|
Chris@1464
|
157 redirect_to my_account_path
|
Chris@0
|
158 end
|
Chris@0
|
159
|
Chris@0
|
160 # Create a new API key
|
Chris@0
|
161 def reset_api_key
|
Chris@0
|
162 if request.post?
|
Chris@0
|
163 if User.current.api_token
|
Chris@0
|
164 User.current.api_token.destroy
|
Chris@0
|
165 User.current.reload
|
Chris@0
|
166 end
|
Chris@0
|
167 User.current.api_key
|
Chris@0
|
168 flash[:notice] = l(:notice_api_access_key_reseted)
|
Chris@0
|
169 end
|
Chris@1464
|
170 redirect_to my_account_path
|
Chris@0
|
171 end
|
Chris@0
|
172
|
Chris@0
|
173 # User's page layout configuration
|
Chris@0
|
174 def page_layout
|
Chris@0
|
175 @user = User.current
|
Chris@0
|
176 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
Chris@0
|
177 @block_options = []
|
Chris@1115
|
178 BLOCKS.each do |k, v|
|
Chris@1517
|
179 unless @blocks.values.flatten.include?(k)
|
Chris@1115
|
180 @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
Chris@1115
|
181 end
|
Chris@1115
|
182 end
|
Chris@0
|
183 end
|
Chris@909
|
184
|
Chris@0
|
185 # Add a block to user's page
|
Chris@0
|
186 # The block is added on top of the page
|
Chris@0
|
187 # params[:block] : id of the block to add
|
Chris@0
|
188 def add_block
|
Chris@0
|
189 block = params[:block].to_s.underscore
|
Chris@1294
|
190 if block.present? && BLOCKS.key?(block)
|
Chris@1294
|
191 @user = User.current
|
Chris@1294
|
192 layout = @user.pref[:my_page_layout] || {}
|
Chris@1294
|
193 # remove if already present in a group
|
Chris@1294
|
194 %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
Chris@1294
|
195 # add it on top
|
Chris@1294
|
196 layout['top'].unshift block
|
Chris@1294
|
197 @user.pref[:my_page_layout] = layout
|
Chris@1294
|
198 @user.pref.save
|
Chris@1294
|
199 end
|
Chris@1464
|
200 redirect_to my_page_layout_path
|
Chris@0
|
201 end
|
Chris@909
|
202
|
Chris@0
|
203 # Remove a block to user's page
|
Chris@0
|
204 # params[:block] : id of the block to remove
|
Chris@0
|
205 def remove_block
|
Chris@0
|
206 block = params[:block].to_s.underscore
|
Chris@0
|
207 @user = User.current
|
Chris@0
|
208 # remove block in all groups
|
Chris@0
|
209 layout = @user.pref[:my_page_layout] || {}
|
Chris@0
|
210 %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
Chris@0
|
211 @user.pref[:my_page_layout] = layout
|
Chris@909
|
212 @user.pref.save
|
Chris@1464
|
213 redirect_to my_page_layout_path
|
Chris@0
|
214 end
|
Chris@0
|
215
|
Chris@0
|
216 # Change blocks order on user's page
|
Chris@0
|
217 # params[:group] : group to order (top, left or right)
|
Chris@0
|
218 # params[:list-(top|left|right)] : array of block ids of the group
|
Chris@0
|
219 def order_blocks
|
Chris@0
|
220 group = params[:group]
|
Chris@0
|
221 @user = User.current
|
Chris@0
|
222 if group.is_a?(String)
|
Chris@1115
|
223 group_items = (params["blocks"] || []).collect(&:underscore)
|
Chris@1115
|
224 group_items.each {|s| s.sub!(/^block_/, '')}
|
Chris@0
|
225 if group_items and group_items.is_a? Array
|
Chris@0
|
226 layout = @user.pref[:my_page_layout] || {}
|
Chris@0
|
227 # remove group blocks if they are presents in other groups
|
Chris@0
|
228 %w(top left right).each {|f|
|
Chris@0
|
229 layout[f] = (layout[f] || []) - group_items
|
Chris@0
|
230 }
|
Chris@0
|
231 layout[group] = group_items
|
Chris@0
|
232 @user.pref[:my_page_layout] = layout
|
Chris@909
|
233 @user.pref.save
|
Chris@0
|
234 end
|
Chris@0
|
235 end
|
Chris@0
|
236 render :nothing => true
|
Chris@0
|
237 end
|
Chris@0
|
238 end
|