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