annotate .svn/pristine/a1/a1b77b806397cc5fdef1b8ec65e5b9652bc154db.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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