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 @ 1298:4f746d8966dd
History | View | Annotate | Download (7.46 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 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 | |||
| 21 | helper :issues
|
||
| 22 | 117:af80e5618e9b | Chris | helper :users
|
| 23 | 0:513646585e45 | Chris | helper :custom_fields
|
| 24 | 1086:5ebdeb79ea9c | chris | helper :projects
|
| 25 | 1217:875b5b4c574d | chris | helper :activities
|
| 26 | 0:513646585e45 | Chris | |
| 27 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, |
||
| 28 | 'issuesreportedbyme' => :label_reported_issues, |
||
| 29 | 'issueswatched' => :label_watched_issues, |
||
| 30 | 344:1a514b9347d4 | chris | 'activitymyprojects' => :label_activity_my_recent, |
| 31 | 0:513646585e45 | Chris | 'news' => :label_news_latest, |
| 32 | 363:ce85aa993384 | chris | 'tipoftheday' => :label_tipoftheday, |
| 33 | 0:513646585e45 | Chris | 'calendar' => :label_calendar, |
| 34 | 'documents' => :label_document_plural, |
||
| 35 | 1086:5ebdeb79ea9c | chris | 'timelog' => :label_spent_time, |
| 36 | 1217:875b5b4c574d | chris | 'myprojects' => :label_my_projects, |
| 37 | 'colleagues' => :label_my_colleagues |
||
| 38 | 0:513646585e45 | Chris | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
| 39 | |||
| 40 | 1164:a943f341c99d | chris | DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'], |
| 41 | 1226:d280360758e5 | Chris | 'right' => ['tipoftheday', 'issueswatched'] |
| 42 | 0:513646585e45 | Chris | }.freeze |
| 43 | |||
| 44 | def index |
||
| 45 | page |
||
| 46 | render :action => 'page' |
||
| 47 | end
|
||
| 48 | |||
| 49 | # Show user's page
|
||
| 50 | def page |
||
| 51 | @user = User.current |
||
| 52 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
||
| 53 | end
|
||
| 54 | |||
| 55 | # Edit user's account
|
||
| 56 | def account |
||
| 57 | @user = User.current |
||
| 58 | @pref = @user.pref |
||
| 59 | 108:d70a0b926135 | luisf | @ssamr_user_details = @user.ssamr_user_detail |
| 60 | 164:bb9724ba3d60 | luisf | |
| 61 | 188:f9fe5ef6156e | luisf | |
| 62 | if @user.ssamr_user_detail == nil |
||
| 63 | @selected_institution_id = nil |
||
| 64 | else
|
||
| 65 | @selected_institution_id = @ssamr_user_details.institution_id.to_i |
||
| 66 | end
|
||
| 67 | |||
| 68 | 0:513646585e45 | Chris | if request.post?
|
| 69 | 117:af80e5618e9b | Chris | @user.safe_attributes = params[:user] |
| 70 | 0:513646585e45 | Chris | @user.pref.attributes = params[:pref] |
| 71 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
||
| 72 | 108:d70a0b926135 | luisf | |
| 73 | if @user.ssamr_user_detail == nil |
||
| 74 | @ssamr_user_details = SsamrUserDetail.new() |
||
| 75 | @user.ssamr_user_detail = @ssamr_user_details |
||
| 76 | else
|
||
| 77 | @ssamr_user_details = @user.ssamr_user_detail |
||
| 78 | end
|
||
| 79 | |||
| 80 | if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? |
||
| 81 | @ssamr_user_details.description = @user.ssamr_user_detail.description |
||
| 82 | @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id |
||
| 83 | 164:bb9724ba3d60 | luisf | @institution_type = @ssamr_user_details.institution_type |
| 84 | @other_institution = @ssamr_user_details.other_institution |
||
| 85 | 108:d70a0b926135 | luisf | else
|
| 86 | @ssamr_user_details.description = params[:ssamr_user_details][:description] |
||
| 87 | @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id] |
||
| 88 | 164:bb9724ba3d60 | luisf | @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type] |
| 89 | @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution] |
||
| 90 | 108:d70a0b926135 | luisf | end
|
| 91 | 164:bb9724ba3d60 | luisf | |
| 92 | 0:513646585e45 | Chris | if @user.save |
| 93 | @user.pref.save
|
||
| 94 | 117:af80e5618e9b | Chris | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
| 95 | 0:513646585e45 | Chris | set_language_if_valid @user.language
|
| 96 | flash[:notice] = l(:notice_account_updated) |
||
| 97 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 98 | 0:513646585e45 | Chris | return
|
| 99 | end
|
||
| 100 | end
|
||
| 101 | end
|
||
| 102 | |||
| 103 | 1115:433d4f72a19b | Chris | # Destroys user's account
|
| 104 | def destroy |
||
| 105 | @user = User.current |
||
| 106 | unless @user.own_account_deletable? |
||
| 107 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 108 | 1115:433d4f72a19b | Chris | return
|
| 109 | end
|
||
| 110 | |||
| 111 | if request.post? && params[:confirm] |
||
| 112 | @user.destroy
|
||
| 113 | if @user.destroyed? |
||
| 114 | logout_user |
||
| 115 | flash[:notice] = l(:notice_account_deleted) |
||
| 116 | end
|
||
| 117 | redirect_to home_path |
||
| 118 | end
|
||
| 119 | end
|
||
| 120 | |||
| 121 | 0:513646585e45 | Chris | # Manage user's password
|
| 122 | def password |
||
| 123 | @user = User.current |
||
| 124 | unless @user.change_password_allowed? |
||
| 125 | flash[:error] = l(:notice_can_t_change_password) |
||
| 126 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 127 | 0:513646585e45 | Chris | return
|
| 128 | end
|
||
| 129 | if request.post?
|
||
| 130 | if @user.check_password?(params[:password]) |
||
| 131 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
||
| 132 | if @user.save |
||
| 133 | flash[:notice] = l(:notice_account_password_updated) |
||
| 134 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 135 | 0:513646585e45 | Chris | end
|
| 136 | else
|
||
| 137 | flash[:error] = l(:notice_account_wrong_password) |
||
| 138 | end
|
||
| 139 | end
|
||
| 140 | end
|
||
| 141 | 909:cbb26bc654de | Chris | |
| 142 | 0:513646585e45 | Chris | # Create a new feeds key
|
| 143 | def reset_rss_key |
||
| 144 | if request.post?
|
||
| 145 | if User.current.rss_token |
||
| 146 | User.current.rss_token.destroy
|
||
| 147 | User.current.reload
|
||
| 148 | end
|
||
| 149 | User.current.rss_key
|
||
| 150 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
||
| 151 | end
|
||
| 152 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 153 | 0:513646585e45 | Chris | end
|
| 154 | |||
| 155 | # Create a new API key
|
||
| 156 | def reset_api_key |
||
| 157 | if request.post?
|
||
| 158 | if User.current.api_token |
||
| 159 | User.current.api_token.destroy
|
||
| 160 | User.current.reload
|
||
| 161 | end
|
||
| 162 | User.current.api_key
|
||
| 163 | flash[:notice] = l(:notice_api_access_key_reseted) |
||
| 164 | end
|
||
| 165 | 1295:622f24f53b42 | Chris | redirect_to my_account_path |
| 166 | 0:513646585e45 | Chris | end
|
| 167 | |||
| 168 | # User's page layout configuration
|
||
| 169 | def page_layout |
||
| 170 | @user = User.current |
||
| 171 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
||
| 172 | @block_options = []
|
||
| 173 | 1115:433d4f72a19b | Chris | BLOCKS.each do |k, v| |
| 174 | unless %w(top left right).detect {|f| (@blocks[f] ||= []).include?(k)} |
||
| 175 | @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] |
||
| 176 | end
|
||
| 177 | end
|
||
| 178 | 0:513646585e45 | Chris | end
|
| 179 | 909:cbb26bc654de | Chris | |
| 180 | 0:513646585e45 | Chris | # Add a block to user's page
|
| 181 | # The block is added on top of the page
|
||
| 182 | # params[:block] : id of the block to add
|
||
| 183 | def add_block |
||
| 184 | block = params[:block].to_s.underscore
|
||
| 185 | 1294:3e4c3460b6ca | Chris | if block.present? && BLOCKS.key?(block) |
| 186 | @user = User.current |
||
| 187 | layout = @user.pref[:my_page_layout] || {} |
||
| 188 | # remove if already present in a group
|
||
| 189 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 190 | # add it on top
|
||
| 191 | layout['top'].unshift block
|
||
| 192 | @user.pref[:my_page_layout] = layout |
||
| 193 | @user.pref.save
|
||
| 194 | end
|
||
| 195 | 1295:622f24f53b42 | Chris | redirect_to my_page_layout_path |
| 196 | 0:513646585e45 | Chris | end
|
| 197 | 909:cbb26bc654de | Chris | |
| 198 | 0:513646585e45 | Chris | # Remove a block to user's page
|
| 199 | # params[:block] : id of the block to remove
|
||
| 200 | def remove_block |
||
| 201 | block = params[:block].to_s.underscore
|
||
| 202 | @user = User.current |
||
| 203 | # remove block in all groups
|
||
| 204 | layout = @user.pref[:my_page_layout] || {} |
||
| 205 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 206 | @user.pref[:my_page_layout] = layout |
||
| 207 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 208 | 1295:622f24f53b42 | Chris | redirect_to my_page_layout_path |
| 209 | 0:513646585e45 | Chris | end
|
| 210 | |||
| 211 | # Change blocks order on user's page
|
||
| 212 | # params[:group] : group to order (top, left or right)
|
||
| 213 | # params[:list-(top|left|right)] : array of block ids of the group
|
||
| 214 | def order_blocks |
||
| 215 | group = params[:group]
|
||
| 216 | @user = User.current |
||
| 217 | if group.is_a?(String) |
||
| 218 | 1115:433d4f72a19b | Chris | group_items = (params["blocks"] || []).collect(&:underscore) |
| 219 | group_items.each {|s| s.sub!(/^block_/, '')}
|
||
| 220 | 0:513646585e45 | Chris | if group_items and group_items.is_a? Array |
| 221 | layout = @user.pref[:my_page_layout] || {} |
||
| 222 | # remove group blocks if they are presents in other groups
|
||
| 223 | %w(top left right).each {|f|
|
||
| 224 | layout[f] = (layout[f] || []) - group_items |
||
| 225 | } |
||
| 226 | layout[group] = group_items |
||
| 227 | @user.pref[:my_page_layout] = layout |
||
| 228 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 229 | 0:513646585e45 | Chris | end
|
| 230 | end
|
||
| 231 | render :nothing => true |
||
| 232 | end
|
||
| 233 | end |