annotate .svn/pristine/d8/d886d8a19901a4b56d0aaccc00956e0c5770dc2f.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 class MyController < ApplicationController
Chris@1295 19 before_filter :require_login
Chris@1295 20
Chris@1295 21 helper :issues
Chris@1295 22 helper :users
Chris@1295 23 helper :custom_fields
Chris@1295 24
Chris@1295 25 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
Chris@1295 26 'issuesreportedbyme' => :label_reported_issues,
Chris@1295 27 'issueswatched' => :label_watched_issues,
Chris@1295 28 'news' => :label_news_latest,
Chris@1295 29 'calendar' => :label_calendar,
Chris@1295 30 'documents' => :label_document_plural,
Chris@1295 31 'timelog' => :label_spent_time
Chris@1295 32 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
Chris@1295 33
Chris@1295 34 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
Chris@1295 35 'right' => ['issuesreportedbyme']
Chris@1295 36 }.freeze
Chris@1295 37
Chris@1295 38 def index
Chris@1295 39 page
Chris@1295 40 render :action => 'page'
Chris@1295 41 end
Chris@1295 42
Chris@1295 43 # Show user's page
Chris@1295 44 def page
Chris@1295 45 @user = User.current
Chris@1295 46 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
Chris@1295 47 end
Chris@1295 48
Chris@1295 49 # Edit user's account
Chris@1295 50 def account
Chris@1295 51 @user = User.current
Chris@1295 52 @pref = @user.pref
Chris@1295 53 if request.post?
Chris@1295 54 @user.safe_attributes = params[:user]
Chris@1295 55 @user.pref.attributes = params[:pref]
Chris@1295 56 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
Chris@1295 57 if @user.save
Chris@1295 58 @user.pref.save
Chris@1295 59 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
Chris@1295 60 set_language_if_valid @user.language
Chris@1295 61 flash[:notice] = l(:notice_account_updated)
Chris@1295 62 redirect_to :action => 'account'
Chris@1295 63 return
Chris@1295 64 end
Chris@1295 65 end
Chris@1295 66 end
Chris@1295 67
Chris@1295 68 # Destroys user's account
Chris@1295 69 def destroy
Chris@1295 70 @user = User.current
Chris@1295 71 unless @user.own_account_deletable?
Chris@1295 72 redirect_to :action => 'account'
Chris@1295 73 return
Chris@1295 74 end
Chris@1295 75
Chris@1295 76 if request.post? && params[:confirm]
Chris@1295 77 @user.destroy
Chris@1295 78 if @user.destroyed?
Chris@1295 79 logout_user
Chris@1295 80 flash[:notice] = l(:notice_account_deleted)
Chris@1295 81 end
Chris@1295 82 redirect_to home_path
Chris@1295 83 end
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 # Manage user's password
Chris@1295 87 def password
Chris@1295 88 @user = User.current
Chris@1295 89 unless @user.change_password_allowed?
Chris@1295 90 flash[:error] = l(:notice_can_t_change_password)
Chris@1295 91 redirect_to :action => 'account'
Chris@1295 92 return
Chris@1295 93 end
Chris@1295 94 if request.post?
Chris@1295 95 if @user.check_password?(params[:password])
Chris@1295 96 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
Chris@1295 97 if @user.save
Chris@1295 98 flash[:notice] = l(:notice_account_password_updated)
Chris@1295 99 redirect_to :action => 'account'
Chris@1295 100 end
Chris@1295 101 else
Chris@1295 102 flash[:error] = l(:notice_account_wrong_password)
Chris@1295 103 end
Chris@1295 104 end
Chris@1295 105 end
Chris@1295 106
Chris@1295 107 # Create a new feeds key
Chris@1295 108 def reset_rss_key
Chris@1295 109 if request.post?
Chris@1295 110 if User.current.rss_token
Chris@1295 111 User.current.rss_token.destroy
Chris@1295 112 User.current.reload
Chris@1295 113 end
Chris@1295 114 User.current.rss_key
Chris@1295 115 flash[:notice] = l(:notice_feeds_access_key_reseted)
Chris@1295 116 end
Chris@1295 117 redirect_to :action => 'account'
Chris@1295 118 end
Chris@1295 119
Chris@1295 120 # Create a new API key
Chris@1295 121 def reset_api_key
Chris@1295 122 if request.post?
Chris@1295 123 if User.current.api_token
Chris@1295 124 User.current.api_token.destroy
Chris@1295 125 User.current.reload
Chris@1295 126 end
Chris@1295 127 User.current.api_key
Chris@1295 128 flash[:notice] = l(:notice_api_access_key_reseted)
Chris@1295 129 end
Chris@1295 130 redirect_to :action => 'account'
Chris@1295 131 end
Chris@1295 132
Chris@1295 133 # User's page layout configuration
Chris@1295 134 def page_layout
Chris@1295 135 @user = User.current
Chris@1295 136 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
Chris@1295 137 @block_options = []
Chris@1295 138 BLOCKS.each do |k, v|
Chris@1295 139 unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)}
Chris@1295 140 @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
Chris@1295 141 end
Chris@1295 142 end
Chris@1295 143 end
Chris@1295 144
Chris@1295 145 # Add a block to user's page
Chris@1295 146 # The block is added on top of the page
Chris@1295 147 # params[:block] : id of the block to add
Chris@1295 148 def add_block
Chris@1295 149 block = params[:block].to_s.underscore
Chris@1295 150 (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
Chris@1295 151 @user = User.current
Chris@1295 152 layout = @user.pref[:my_page_layout] || {}
Chris@1295 153 # remove if already present in a group
Chris@1295 154 %w(top left right).each {|f| (layout[f] ||= []).delete block }
Chris@1295 155 # add it on top
Chris@1295 156 layout['top'].unshift block
Chris@1295 157 @user.pref[:my_page_layout] = layout
Chris@1295 158 @user.pref.save
Chris@1295 159 redirect_to :action => 'page_layout'
Chris@1295 160 end
Chris@1295 161
Chris@1295 162 # Remove a block to user's page
Chris@1295 163 # params[:block] : id of the block to remove
Chris@1295 164 def remove_block
Chris@1295 165 block = params[:block].to_s.underscore
Chris@1295 166 @user = User.current
Chris@1295 167 # remove block in all groups
Chris@1295 168 layout = @user.pref[:my_page_layout] || {}
Chris@1295 169 %w(top left right).each {|f| (layout[f] ||= []).delete block }
Chris@1295 170 @user.pref[:my_page_layout] = layout
Chris@1295 171 @user.pref.save
Chris@1295 172 redirect_to :action => 'page_layout'
Chris@1295 173 end
Chris@1295 174
Chris@1295 175 # Change blocks order on user's page
Chris@1295 176 # params[:group] : group to order (top, left or right)
Chris@1295 177 # params[:list-(top|left|right)] : array of block ids of the group
Chris@1295 178 def order_blocks
Chris@1295 179 group = params[:group]
Chris@1295 180 @user = User.current
Chris@1295 181 if group.is_a?(String)
Chris@1295 182 group_items = (params["blocks"] || []).collect(&:underscore)
Chris@1295 183 group_items.each {|s| s.sub!(/^block_/, '')}
Chris@1295 184 if group_items and group_items.is_a? Array
Chris@1295 185 layout = @user.pref[:my_page_layout] || {}
Chris@1295 186 # remove group blocks if they are presents in other groups
Chris@1295 187 %w(top left right).each {|f|
Chris@1295 188 layout[f] = (layout[f] || []) - group_items
Chris@1295 189 }
Chris@1295 190 layout[group] = group_items
Chris@1295 191 @user.pref[:my_page_layout] = layout
Chris@1295 192 @user.pref.save
Chris@1295 193 end
Chris@1295 194 end
Chris@1295 195 render :nothing => true
Chris@1295 196 end
Chris@1295 197 end