annotate app/controllers/my_controller.rb @ 1271:cf4cc816278a live last_rails2_version

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