To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / d8 / d886d8a19901a4b56d0aaccc00956e0c5770dc2f.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (6.03 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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 | |||
| 21 | helper :issues |
||
| 22 | helper :users |
||
| 23 | helper :custom_fields |
||
| 24 | |||
| 25 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||
| 26 | 'issuesreportedbyme' => :label_reported_issues, |
||
| 27 | 'issueswatched' => :label_watched_issues, |
||
| 28 | 'news' => :label_news_latest, |
||
| 29 | 'calendar' => :label_calendar, |
||
| 30 | 'documents' => :label_document_plural, |
||
| 31 | 'timelog' => :label_spent_time |
||
| 32 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
||
| 33 | |||
| 34 | DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
||
| 35 | 'right' => ['issuesreportedbyme'] |
||
| 36 | }.freeze |
||
| 37 | |||
| 38 | def index |
||
| 39 | page |
||
| 40 | render :action => 'page' |
||
| 41 | end |
||
| 42 | |||
| 43 | # Show user's page |
||
| 44 | def page |
||
| 45 | @user = User.current |
||
| 46 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
||
| 47 | end |
||
| 48 | |||
| 49 | # Edit user's account |
||
| 50 | def account |
||
| 51 | @user = User.current |
||
| 52 | @pref = @user.pref |
||
| 53 | if request.post? |
||
| 54 | @user.safe_attributes = params[:user] |
||
| 55 | @user.pref.attributes = params[:pref] |
||
| 56 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
||
| 57 | if @user.save |
||
| 58 | @user.pref.save |
||
| 59 | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
||
| 60 | set_language_if_valid @user.language |
||
| 61 | flash[:notice] = l(:notice_account_updated) |
||
| 62 | redirect_to :action => 'account' |
||
| 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 :action => 'account' |
||
| 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 :action => 'account' |
||
| 92 | return |
||
| 93 | end |
||
| 94 | if request.post? |
||
| 95 | if @user.check_password?(params[:password]) |
||
| 96 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
||
| 97 | if @user.save |
||
| 98 | flash[:notice] = l(:notice_account_password_updated) |
||
| 99 | redirect_to :action => 'account' |
||
| 100 | end |
||
| 101 | else |
||
| 102 | flash[:error] = l(:notice_account_wrong_password) |
||
| 103 | end |
||
| 104 | end |
||
| 105 | end |
||
| 106 | |||
| 107 | # Create a new feeds key |
||
| 108 | def reset_rss_key |
||
| 109 | if request.post? |
||
| 110 | if User.current.rss_token |
||
| 111 | User.current.rss_token.destroy |
||
| 112 | User.current.reload |
||
| 113 | end |
||
| 114 | User.current.rss_key |
||
| 115 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
||
| 116 | end |
||
| 117 | redirect_to :action => 'account' |
||
| 118 | end |
||
| 119 | |||
| 120 | # Create a new API key |
||
| 121 | def reset_api_key |
||
| 122 | if request.post? |
||
| 123 | if User.current.api_token |
||
| 124 | User.current.api_token.destroy |
||
| 125 | User.current.reload |
||
| 126 | end |
||
| 127 | User.current.api_key |
||
| 128 | flash[:notice] = l(:notice_api_access_key_reseted) |
||
| 129 | end |
||
| 130 | redirect_to :action => 'account' |
||
| 131 | end |
||
| 132 | |||
| 133 | # User's page layout configuration |
||
| 134 | def page_layout |
||
| 135 | @user = User.current |
||
| 136 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
||
| 137 | @block_options = [] |
||
| 138 | BLOCKS.each do |k, v| |
||
| 139 | unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
|
||
| 140 | @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
||
| 141 | end |
||
| 142 | end |
||
| 143 | end |
||
| 144 | |||
| 145 | # Add a block to user's page |
||
| 146 | # The block is added on top of the page |
||
| 147 | # params[:block] : id of the block to add |
||
| 148 | def add_block |
||
| 149 | block = params[:block].to_s.underscore |
||
| 150 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) |
||
| 151 | @user = User.current |
||
| 152 | layout = @user.pref[:my_page_layout] || {}
|
||
| 153 | # remove if already present in a group |
||
| 154 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 155 | # add it on top |
||
| 156 | layout['top'].unshift block |
||
| 157 | @user.pref[:my_page_layout] = layout |
||
| 158 | @user.pref.save |
||
| 159 | redirect_to :action => 'page_layout' |
||
| 160 | end |
||
| 161 | |||
| 162 | # Remove a block to user's page |
||
| 163 | # params[:block] : id of the block to remove |
||
| 164 | def remove_block |
||
| 165 | block = params[:block].to_s.underscore |
||
| 166 | @user = User.current |
||
| 167 | # remove block in all groups |
||
| 168 | layout = @user.pref[:my_page_layout] || {}
|
||
| 169 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 170 | @user.pref[:my_page_layout] = layout |
||
| 171 | @user.pref.save |
||
| 172 | redirect_to :action => 'page_layout' |
||
| 173 | end |
||
| 174 | |||
| 175 | # Change blocks order on user's page |
||
| 176 | # params[:group] : group to order (top, left or right) |
||
| 177 | # params[:list-(top|left|right)] : array of block ids of the group |
||
| 178 | def order_blocks |
||
| 179 | group = params[:group] |
||
| 180 | @user = User.current |
||
| 181 | if group.is_a?(String) |
||
| 182 | group_items = (params["blocks"] || []).collect(&:underscore) |
||
| 183 | group_items.each {|s| s.sub!(/^block_/, '')}
|
||
| 184 | if group_items and group_items.is_a? Array |
||
| 185 | layout = @user.pref[:my_page_layout] || {}
|
||
| 186 | # remove group blocks if they are presents in other groups |
||
| 187 | %w(top left right).each {|f|
|
||
| 188 | layout[f] = (layout[f] || []) - group_items |
||
| 189 | } |
||
| 190 | layout[group] = group_items |
||
| 191 | @user.pref[:my_page_layout] = layout |
||
| 192 | @user.pref.save |
||
| 193 | end |
||
| 194 | end |
||
| 195 | render :nothing => true |
||
| 196 | end |
||
| 197 | end |