@@ -1,201 +1,201 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 MyController < ApplicationController |
|
19 | 19 | before_filter :require_login |
|
20 |
# let user change |
|
|
20 | # let user change user's password when user has to | |
|
21 | 21 | skip_before_filter :check_password_change, :only => :password |
|
22 | 22 | |
|
23 | 23 | helper :issues |
|
24 | 24 | helper :users |
|
25 | 25 | helper :custom_fields |
|
26 | 26 | |
|
27 | 27 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, |
|
28 | 28 | 'issuesreportedbyme' => :label_reported_issues, |
|
29 | 29 | 'issueswatched' => :label_watched_issues, |
|
30 | 30 | 'news' => :label_news_latest, |
|
31 | 31 | 'calendar' => :label_calendar, |
|
32 | 32 | 'documents' => :label_document_plural, |
|
33 | 33 | 'timelog' => :label_spent_time |
|
34 | 34 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
|
35 | 35 | |
|
36 | 36 | DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'], |
|
37 | 37 | 'right' => ['issuesreportedbyme'] |
|
38 | 38 | }.freeze |
|
39 | 39 | |
|
40 | 40 | def index |
|
41 | 41 | page |
|
42 | 42 | render :action => 'page' |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | # Show user's page |
|
46 | 46 | def page |
|
47 | 47 | @user = User.current |
|
48 | 48 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | # Edit user's account |
|
52 | 52 | def account |
|
53 | 53 | @user = User.current |
|
54 | 54 | @pref = @user.pref |
|
55 | 55 | if request.post? |
|
56 | 56 | @user.safe_attributes = params[:user] |
|
57 | 57 | @user.pref.attributes = params[:pref] |
|
58 | 58 | if @user.save |
|
59 | 59 | @user.pref.save |
|
60 | 60 | set_language_if_valid @user.language |
|
61 | 61 | flash[:notice] = l(:notice_account_updated) |
|
62 | 62 | redirect_to my_account_path |
|
63 | 63 | return |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | end |
|
67 | 67 | |
|
68 | 68 | # Destroys user's account |
|
69 | 69 | def destroy |
|
70 | 70 | @user = User.current |
|
71 | 71 | unless @user.own_account_deletable? |
|
72 | 72 | redirect_to my_account_path |
|
73 | 73 | return |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | if request.post? && params[:confirm] |
|
77 | 77 | @user.destroy |
|
78 | 78 | if @user.destroyed? |
|
79 | 79 | logout_user |
|
80 | 80 | flash[:notice] = l(:notice_account_deleted) |
|
81 | 81 | end |
|
82 | 82 | redirect_to home_path |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | # Manage user's password |
|
87 | 87 | def password |
|
88 | 88 | @user = User.current |
|
89 | 89 | unless @user.change_password_allowed? |
|
90 | 90 | flash[:error] = l(:notice_can_t_change_password) |
|
91 | 91 | redirect_to my_account_path |
|
92 | 92 | return |
|
93 | 93 | end |
|
94 | 94 | if request.post? |
|
95 | 95 | if !@user.check_password?(params[:password]) |
|
96 | 96 | flash.now[:error] = l(:notice_account_wrong_password) |
|
97 | 97 | elsif params[:password] == params[:new_password] |
|
98 | 98 | flash.now[:error] = l(:notice_new_password_must_be_different) |
|
99 | 99 | else |
|
100 | 100 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
|
101 | 101 | @user.must_change_passwd = false |
|
102 | 102 | if @user.save |
|
103 | 103 | flash[:notice] = l(:notice_account_password_updated) |
|
104 | 104 | redirect_to my_account_path |
|
105 | 105 | end |
|
106 | 106 | end |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | # Create a new feeds key |
|
111 | 111 | def reset_rss_key |
|
112 | 112 | if request.post? |
|
113 | 113 | if User.current.rss_token |
|
114 | 114 | User.current.rss_token.destroy |
|
115 | 115 | User.current.reload |
|
116 | 116 | end |
|
117 | 117 | User.current.rss_key |
|
118 | 118 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
|
119 | 119 | end |
|
120 | 120 | redirect_to my_account_path |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | # Create a new API key |
|
124 | 124 | def reset_api_key |
|
125 | 125 | if request.post? |
|
126 | 126 | if User.current.api_token |
|
127 | 127 | User.current.api_token.destroy |
|
128 | 128 | User.current.reload |
|
129 | 129 | end |
|
130 | 130 | User.current.api_key |
|
131 | 131 | flash[:notice] = l(:notice_api_access_key_reseted) |
|
132 | 132 | end |
|
133 | 133 | redirect_to my_account_path |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | # User's page layout configuration |
|
137 | 137 | def page_layout |
|
138 | 138 | @user = User.current |
|
139 | 139 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
|
140 | 140 | @block_options = [] |
|
141 | 141 | BLOCKS.each do |k, v| |
|
142 | 142 | unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)} |
|
143 | 143 | @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] |
|
144 | 144 | end |
|
145 | 145 | end |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | # Add a block to user's page |
|
149 | 149 | # The block is added on top of the page |
|
150 | 150 | # params[:block] : id of the block to add |
|
151 | 151 | def add_block |
|
152 | 152 | block = params[:block].to_s.underscore |
|
153 | 153 | if block.present? && BLOCKS.key?(block) |
|
154 | 154 | @user = User.current |
|
155 | 155 | layout = @user.pref[:my_page_layout] || {} |
|
156 | 156 | # remove if already present in a group |
|
157 | 157 | %w(top left right).each {|f| (layout[f] ||= []).delete block } |
|
158 | 158 | # add it on top |
|
159 | 159 | layout['top'].unshift block |
|
160 | 160 | @user.pref[:my_page_layout] = layout |
|
161 | 161 | @user.pref.save |
|
162 | 162 | end |
|
163 | 163 | redirect_to my_page_layout_path |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | # Remove a block to user's page |
|
167 | 167 | # params[:block] : id of the block to remove |
|
168 | 168 | def remove_block |
|
169 | 169 | block = params[:block].to_s.underscore |
|
170 | 170 | @user = User.current |
|
171 | 171 | # remove block in all groups |
|
172 | 172 | layout = @user.pref[:my_page_layout] || {} |
|
173 | 173 | %w(top left right).each {|f| (layout[f] ||= []).delete block } |
|
174 | 174 | @user.pref[:my_page_layout] = layout |
|
175 | 175 | @user.pref.save |
|
176 | 176 | redirect_to my_page_layout_path |
|
177 | 177 | end |
|
178 | 178 | |
|
179 | 179 | # Change blocks order on user's page |
|
180 | 180 | # params[:group] : group to order (top, left or right) |
|
181 | 181 | # params[:list-(top|left|right)] : array of block ids of the group |
|
182 | 182 | def order_blocks |
|
183 | 183 | group = params[:group] |
|
184 | 184 | @user = User.current |
|
185 | 185 | if group.is_a?(String) |
|
186 | 186 | group_items = (params["blocks"] || []).collect(&:underscore) |
|
187 | 187 | group_items.each {|s| s.sub!(/^block_/, '')} |
|
188 | 188 | if group_items and group_items.is_a? Array |
|
189 | 189 | layout = @user.pref[:my_page_layout] || {} |
|
190 | 190 | # remove group blocks if they are presents in other groups |
|
191 | 191 | %w(top left right).each {|f| |
|
192 | 192 | layout[f] = (layout[f] || []) - group_items |
|
193 | 193 | } |
|
194 | 194 | layout[group] = group_items |
|
195 | 195 | @user.pref[:my_page_layout] = layout |
|
196 | 196 | @user.pref.save |
|
197 | 197 | end |
|
198 | 198 | end |
|
199 | 199 | render :nothing => true |
|
200 | 200 | end |
|
201 | 201 | end |
General Comments 0
You need to be logged in to leave comments.
Login now