1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
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.
9 # 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.
14 # 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.
18 class MyController < ApplicationController
22 before_filter :require_login
24 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 'issuesreportedbyme' => :label_reported_issues,
26 'issueswatched' => :label_watched_issues,
27 'news' => :label_news_latest,
28 'calendar' => :label_calendar,
29 'documents' => :label_document_plural
32 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
33 'right' => ['issuesreportedbyme']
37 :session => :page_layout,
38 :only => [:add_block, :remove_block, :order_blocks]
42 render :action => 'page'
47 @user = self.logged_in_user
48 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
56 @user.attributes = params[:user]
57 @user.mail_notification = (params[:notification_option] == 'all')
58 @user.pref.attributes = params[:pref]
61 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
62 set_language_if_valid @user.language
63 flash[:notice] = l(:notice_account_updated)
64 redirect_to :action => 'account'
68 @notification_options = [[l(:label_user_mail_option_all), 'all'],
69 [l(:label_user_mail_option_none), 'none']]
70 # Only users that belong to more than 1 project can select projects for which they are notified
71 # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
72 @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
73 @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
76 # Manage user's password
78 @user = self.logged_in_user
79 flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
81 if @user.check_password?(params[:password])
82 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
84 flash[:notice] = l(:notice_account_password_updated)
85 redirect_to :action => 'account'
88 flash[:error] = l(:notice_account_wrong_password)
93 # Create a new feeds key
95 if request.post? && User.current.rss_token
96 User.current.rss_token.destroy
97 flash[:notice] = l(:notice_feeds_access_key_reseted)
99 redirect_to :action => 'account'
102 # User's page layout configuration
104 @user = self.logged_in_user
105 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
106 session[:page_layout] = @blocks
107 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
109 BLOCKS.each {|k, v| @block_options << [l(v), k]}
112 # Add a block to user's page
113 # The block is added on top of the page
114 # params[:block] : id of the block to add
116 block = params[:block]
117 render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
118 @user = self.logged_in_user
119 # remove if already present in a group
120 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
122 session[:page_layout]['top'].unshift block
123 render :partial => "block", :locals => {:user => @user, :block_name => block}
126 # Remove a block to user's page
127 # params[:block] : id of the block to remove
129 block = params[:block]
130 # remove block in all groups
131 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
132 render :nothing => true
135 # Change blocks order on user's page
136 # params[:group] : group to order (top, left or right)
137 # params[:list-(top|left|right)] : array of block ids of the group
139 group = params[:group]
140 group_items = params["list-#{group}"]
141 if group_items and group_items.is_a? Array
142 # remove group blocks if they are presents in other groups
143 %w(top left right).each {|f|
144 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
146 session[:page_layout][group] = group_items
148 render :nothing => true
151 # Save user's page layout
153 @user = self.logged_in_user
154 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
156 session[:page_layout] = nil
157 redirect_to :action => 'page'