To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / my_controller.rb @ 1535:e2c122809c5c
History | View | Annotate | Download (7.61 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1494:e248c7af89ec | Chris | # Copyright (C) 2006-2014 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 15 | # along with this program; if not, write to the Free Software
|
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 17 | |||
| 18 | class MyController < ApplicationController |
||
| 19 | before_filter :require_login
|
||
| 20 | 1464:261b3d9a4903 | Chris | # let user change user's password when user has to
|
| 21 | skip_before_filter :check_password_change, :only => :password |
||
| 22 | 0:513646585e45 | Chris | |
| 23 | helper :issues
|
||
| 24 | 117:af80e5618e9b | Chris | helper :users
|
| 25 | 0:513646585e45 | Chris | helper :custom_fields
|
| 26 | 1086:5ebdeb79ea9c | chris | helper :projects
|
| 27 | 1217:875b5b4c574d | chris | helper :activities
|
| 28 | 0:513646585e45 | Chris | |
| 29 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, |
||
| 30 | 'issuesreportedbyme' => :label_reported_issues, |
||
| 31 | 'issueswatched' => :label_watched_issues, |
||
| 32 | 344:1a514b9347d4 | chris | 'activitymyprojects' => :label_activity_my_recent, |
| 33 | 0:513646585e45 | Chris | 'news' => :label_news_latest, |
| 34 | 363:ce85aa993384 | chris | 'tipoftheday' => :label_tipoftheday, |
| 35 | 0:513646585e45 | Chris | 'calendar' => :label_calendar, |
| 36 | 'documents' => :label_document_plural, |
||
| 37 | 1086:5ebdeb79ea9c | chris | 'timelog' => :label_spent_time, |
| 38 | 1217:875b5b4c574d | chris | 'myprojects' => :label_my_projects, |
| 39 | 'colleagues' => :label_my_colleagues |
||
| 40 | 0:513646585e45 | Chris | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
| 41 | |||
| 42 | 1164:a943f341c99d | chris | DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'], |
| 43 | 1304:6137548ba453 | Chris | 'right' => ['colleagues', 'tipoftheday', 'issueswatched'] |
| 44 | 0:513646585e45 | Chris | }.freeze |
| 45 | |||
| 46 | def index |
||
| 47 | page |
||
| 48 | render :action => 'page' |
||
| 49 | end
|
||
| 50 | |||
| 51 | # Show user's page
|
||
| 52 | def page |
||
| 53 | @user = User.current |
||
| 54 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
||
| 55 | end
|
||
| 56 | |||
| 57 | # Edit user's account
|
||
| 58 | def account |
||
| 59 | @user = User.current |
||
| 60 | @pref = @user.pref |
||
| 61 | 108:d70a0b926135 | luisf | @ssamr_user_details = @user.ssamr_user_detail |
| 62 | 164:bb9724ba3d60 | luisf | |
| 63 | 188:f9fe5ef6156e | luisf | |
| 64 | if @user.ssamr_user_detail == nil |
||
| 65 | @selected_institution_id = nil |
||
| 66 | else
|
||
| 67 | @selected_institution_id = @ssamr_user_details.institution_id.to_i |
||
| 68 | end
|
||
| 69 | |||
| 70 | 0:513646585e45 | Chris | if request.post?
|
| 71 | 117:af80e5618e9b | Chris | @user.safe_attributes = params[:user] |
| 72 | 0:513646585e45 | Chris | @user.pref.attributes = params[:pref] |
| 73 | 1484:51364c0cd58f | Chris | |
| 74 | 909:cbb26bc654de | Chris | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
| 75 | 108:d70a0b926135 | luisf | |
| 76 | if @user.ssamr_user_detail == nil |
||
| 77 | @ssamr_user_details = SsamrUserDetail.new() |
||
| 78 | @user.ssamr_user_detail = @ssamr_user_details |
||
| 79 | else
|
||
| 80 | @ssamr_user_details = @user.ssamr_user_detail |
||
| 81 | end
|
||
| 82 | |||
| 83 | if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? |
||
| 84 | @ssamr_user_details.description = @user.ssamr_user_detail.description |
||
| 85 | @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id |
||
| 86 | 164:bb9724ba3d60 | luisf | @institution_type = @ssamr_user_details.institution_type |
| 87 | @other_institution = @ssamr_user_details.other_institution |
||
| 88 | 108:d70a0b926135 | luisf | else
|
| 89 | @ssamr_user_details.description = params[:ssamr_user_details][:description] |
||
| 90 | @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id] |
||
| 91 | 164:bb9724ba3d60 | luisf | @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type] |
| 92 | @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution] |
||
| 93 | 108:d70a0b926135 | luisf | end
|
| 94 | 164:bb9724ba3d60 | luisf | |
| 95 | 0:513646585e45 | Chris | if @user.save |
| 96 | @user.pref.save
|
||
| 97 | set_language_if_valid @user.language
|
||
| 98 | flash[:notice] = l(:notice_account_updated) |
||
| 99 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 100 | 0:513646585e45 | Chris | return
|
| 101 | end
|
||
| 102 | end
|
||
| 103 | end
|
||
| 104 | |||
| 105 | 1115:433d4f72a19b | Chris | # Destroys user's account
|
| 106 | def destroy |
||
| 107 | @user = User.current |
||
| 108 | unless @user.own_account_deletable? |
||
| 109 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 110 | 1115:433d4f72a19b | Chris | return
|
| 111 | end
|
||
| 112 | |||
| 113 | if request.post? && params[:confirm] |
||
| 114 | @user.destroy
|
||
| 115 | if @user.destroyed? |
||
| 116 | logout_user |
||
| 117 | flash[:notice] = l(:notice_account_deleted) |
||
| 118 | end
|
||
| 119 | redirect_to home_path |
||
| 120 | end
|
||
| 121 | end
|
||
| 122 | |||
| 123 | 0:513646585e45 | Chris | # Manage user's password
|
| 124 | def password |
||
| 125 | @user = User.current |
||
| 126 | unless @user.change_password_allowed? |
||
| 127 | flash[:error] = l(:notice_can_t_change_password) |
||
| 128 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 129 | 0:513646585e45 | Chris | return
|
| 130 | end
|
||
| 131 | if request.post?
|
||
| 132 | 1464:261b3d9a4903 | Chris | if !@user.check_password?(params[:password]) |
| 133 | flash.now[:error] = l(:notice_account_wrong_password) |
||
| 134 | elsif params[:password] == params[:new_password] |
||
| 135 | flash.now[:error] = l(:notice_new_password_must_be_different) |
||
| 136 | else
|
||
| 137 | 0:513646585e45 | Chris | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
| 138 | 1464:261b3d9a4903 | Chris | @user.must_change_passwd = false |
| 139 | 0:513646585e45 | Chris | if @user.save |
| 140 | flash[:notice] = l(:notice_account_password_updated) |
||
| 141 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 142 | 0:513646585e45 | Chris | end
|
| 143 | end
|
||
| 144 | end
|
||
| 145 | end
|
||
| 146 | 909:cbb26bc654de | Chris | |
| 147 | 0:513646585e45 | Chris | # Create a new feeds key
|
| 148 | def reset_rss_key |
||
| 149 | if request.post?
|
||
| 150 | if User.current.rss_token |
||
| 151 | User.current.rss_token.destroy
|
||
| 152 | User.current.reload
|
||
| 153 | end
|
||
| 154 | User.current.rss_key
|
||
| 155 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
||
| 156 | end
|
||
| 157 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 158 | 0:513646585e45 | Chris | end
|
| 159 | |||
| 160 | # Create a new API key
|
||
| 161 | def reset_api_key |
||
| 162 | if request.post?
|
||
| 163 | if User.current.api_token |
||
| 164 | User.current.api_token.destroy
|
||
| 165 | User.current.reload
|
||
| 166 | end
|
||
| 167 | User.current.api_key
|
||
| 168 | flash[:notice] = l(:notice_api_access_key_reseted) |
||
| 169 | end
|
||
| 170 | 1464:261b3d9a4903 | Chris | redirect_to my_account_path |
| 171 | 0:513646585e45 | Chris | end
|
| 172 | |||
| 173 | # User's page layout configuration
|
||
| 174 | def page_layout |
||
| 175 | @user = User.current |
||
| 176 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
||
| 177 | @block_options = []
|
||
| 178 | 1115:433d4f72a19b | Chris | BLOCKS.each do |k, v| |
| 179 | 1517:dffacf8a6908 | Chris | unless @blocks.values.flatten.include?(k) |
| 180 | 1115:433d4f72a19b | Chris | @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] |
| 181 | end
|
||
| 182 | end
|
||
| 183 | 0:513646585e45 | Chris | end
|
| 184 | 909:cbb26bc654de | Chris | |
| 185 | 0:513646585e45 | Chris | # Add a block to user's page
|
| 186 | # The block is added on top of the page
|
||
| 187 | # params[:block] : id of the block to add
|
||
| 188 | def add_block |
||
| 189 | block = params[:block].to_s.underscore
|
||
| 190 | 1294:3e4c3460b6ca | Chris | if block.present? && BLOCKS.key?(block) |
| 191 | @user = User.current |
||
| 192 | layout = @user.pref[:my_page_layout] || {} |
||
| 193 | # remove if already present in a group
|
||
| 194 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 195 | # add it on top
|
||
| 196 | layout['top'].unshift block
|
||
| 197 | @user.pref[:my_page_layout] = layout |
||
| 198 | @user.pref.save
|
||
| 199 | end
|
||
| 200 | 1464:261b3d9a4903 | Chris | redirect_to my_page_layout_path |
| 201 | 0:513646585e45 | Chris | end
|
| 202 | 909:cbb26bc654de | Chris | |
| 203 | 0:513646585e45 | Chris | # Remove a block to user's page
|
| 204 | # params[:block] : id of the block to remove
|
||
| 205 | def remove_block |
||
| 206 | block = params[:block].to_s.underscore
|
||
| 207 | @user = User.current |
||
| 208 | # remove block in all groups
|
||
| 209 | layout = @user.pref[:my_page_layout] || {} |
||
| 210 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 211 | @user.pref[:my_page_layout] = layout |
||
| 212 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 213 | 1464:261b3d9a4903 | Chris | redirect_to my_page_layout_path |
| 214 | 0:513646585e45 | Chris | end
|
| 215 | |||
| 216 | # Change blocks order on user's page
|
||
| 217 | # params[:group] : group to order (top, left or right)
|
||
| 218 | # params[:list-(top|left|right)] : array of block ids of the group
|
||
| 219 | def order_blocks |
||
| 220 | group = params[:group]
|
||
| 221 | @user = User.current |
||
| 222 | if group.is_a?(String) |
||
| 223 | 1115:433d4f72a19b | Chris | group_items = (params["blocks"] || []).collect(&:underscore) |
| 224 | group_items.each {|s| s.sub!(/^block_/, '')}
|
||
| 225 | 0:513646585e45 | Chris | if group_items and group_items.is_a? Array |
| 226 | layout = @user.pref[:my_page_layout] || {} |
||
| 227 | # remove group blocks if they are presents in other groups
|
||
| 228 | %w(top left right).each {|f|
|
||
| 229 | layout[f] = (layout[f] || []) - group_items |
||
| 230 | } |
||
| 231 | layout[group] = group_items |
||
| 232 | @user.pref[:my_page_layout] = layout |
||
| 233 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 234 | 0:513646585e45 | Chris | end
|
| 235 | end
|
||
| 236 | render :nothing => true |
||
| 237 | end
|
||
| 238 | end |