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