annotate .svn/pristine/83/83a431c356c51da0a7c44b91b4b4ad94435f65e3.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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