##// END OF EJS Templates
Added an option on 'My account' for users who don't want to be notified of changes that they make....
Jean-Philippe Lang -
r886:0fe5c7b3e0d8
parent child
Show More
@@ -1,159 +1,160
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class MyController < ApplicationController
19 19 helper :issues
20 20
21 21 layout 'base'
22 22 before_filter :require_login
23 23
24 24 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 25 'issuesreportedbyme' => :label_reported_issues,
26 26 'issueswatched' => :label_watched_issues,
27 27 'news' => :label_news_latest,
28 28 'calendar' => :label_calendar,
29 29 'documents' => :label_document_plural
30 30 }.freeze
31 31
32 32 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
33 33 'right' => ['issuesreportedbyme']
34 34 }.freeze
35 35
36 36 verify :xhr => true,
37 37 :session => :page_layout,
38 38 :only => [:add_block, :remove_block, :order_blocks]
39 39
40 40 def index
41 41 page
42 42 render :action => 'page'
43 43 end
44 44
45 45 # Show user's page
46 46 def page
47 47 @user = self.logged_in_user
48 48 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
49 49 end
50 50
51 51 # Edit user's account
52 52 def account
53 53 @user = User.current
54 54 @pref = @user.pref
55 55 if request.post?
56 56 @user.attributes = params[:user]
57 57 @user.mail_notification = (params[:notification_option] == 'all')
58 58 @user.pref.attributes = params[:pref]
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
59 60 if @user.save
60 61 @user.pref.save
61 62 @user.notified_project_ids = (params[:notification_option] == 'selected' ? params[:notified_project_ids] : [])
62 63 set_language_if_valid @user.language
63 64 flash[:notice] = l(:notice_account_updated)
64 65 redirect_to :action => 'account'
65 66 return
66 67 end
67 68 end
68 69 @notification_options = [[l(:label_user_mail_option_all), 'all'],
69 70 [l(:label_user_mail_option_none), 'none']]
70 71 # Only users that belong to more than 1 project can select projects for which they are notified
71 72 # Note that @user.membership.size would fail since AR ignores :include association option when doing a count
72 73 @notification_options.insert 1, [l(:label_user_mail_option_selected), 'selected'] if @user.memberships.length > 1
73 74 @notification_option = @user.mail_notification? ? 'all' : (@user.notified_projects_ids.empty? ? 'none' : 'selected')
74 75 end
75 76
76 77 # Manage user's password
77 78 def password
78 79 @user = self.logged_in_user
79 80 flash[:error] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
80 81 if request.post?
81 82 if @user.check_password?(params[:password])
82 83 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
83 84 if @user.save
84 85 flash[:notice] = l(:notice_account_password_updated)
85 86 redirect_to :action => 'account'
86 87 end
87 88 else
88 89 flash[:error] = l(:notice_account_wrong_password)
89 90 end
90 91 end
91 92 end
92 93
93 94 # Create a new feeds key
94 95 def reset_rss_key
95 96 if request.post? && User.current.rss_token
96 97 User.current.rss_token.destroy
97 98 flash[:notice] = l(:notice_feeds_access_key_reseted)
98 99 end
99 100 redirect_to :action => 'account'
100 101 end
101 102
102 103 # User's page layout configuration
103 104 def page_layout
104 105 @user = self.logged_in_user
105 106 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
106 107 session[:page_layout] = @blocks
107 108 %w(top left right).each {|f| session[:page_layout][f] ||= [] }
108 109 @block_options = []
109 110 BLOCKS.each {|k, v| @block_options << [l(v), k]}
110 111 end
111 112
112 113 # Add a block to user's page
113 114 # The block is added on top of the page
114 115 # params[:block] : id of the block to add
115 116 def add_block
116 117 block = params[:block]
117 118 render(:nothing => true) and return unless block && (BLOCKS.keys.include? block)
118 119 @user = self.logged_in_user
119 120 # remove if already present in a group
120 121 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
121 122 # add it on top
122 123 session[:page_layout]['top'].unshift block
123 124 render :partial => "block", :locals => {:user => @user, :block_name => block}
124 125 end
125 126
126 127 # Remove a block to user's page
127 128 # params[:block] : id of the block to remove
128 129 def remove_block
129 130 block = params[:block]
130 131 # remove block in all groups
131 132 %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
132 133 render :nothing => true
133 134 end
134 135
135 136 # Change blocks order on user's page
136 137 # params[:group] : group to order (top, left or right)
137 138 # params[:list-(top|left|right)] : array of block ids of the group
138 139 def order_blocks
139 140 group = params[:group]
140 141 group_items = params["list-#{group}"]
141 142 if group_items and group_items.is_a? Array
142 143 # remove group blocks if they are presents in other groups
143 144 %w(top left right).each {|f|
144 145 session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
145 146 }
146 147 session[:page_layout][group] = group_items
147 148 end
148 149 render :nothing => true
149 150 end
150 151
151 152 # Save user's page layout
152 153 def page_layout_save
153 154 @user = self.logged_in_user
154 155 @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
155 156 @user.pref.save
156 157 session[:page_layout] = nil
157 158 redirect_to :action => 'page'
158 159 end
159 160 end
@@ -1,130 +1,138
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class Mailer < ActionMailer::Base
19 19 helper ApplicationHelper
20 20 helper IssuesHelper
21 21 helper CustomFieldsHelper
22 22
23 23 include ActionController::UrlWriter
24 24
25 25 def issue_add(issue)
26 26 recipients issue.recipients
27 27 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
28 28 body :issue => issue,
29 29 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
30 30 end
31 31
32 32 def issue_edit(journal)
33 33 issue = journal.journalized
34 34 recipients issue.recipients
35 35 # Watchers in cc
36 36 cc(issue.watcher_recipients - @recipients)
37 37 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
38 38 body :issue => issue,
39 39 :journal => journal,
40 40 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
41 41 end
42 42
43 43 def document_added(document)
44 44 recipients document.project.recipients
45 45 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
46 46 body :document => document,
47 47 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
48 48 end
49 49
50 50 def attachments_added(attachments)
51 51 container = attachments.first.container
52 52 added_to = ''
53 53 added_to_url = ''
54 54 case container.class.name
55 55 when 'Version'
56 56 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
57 57 added_to = "#{l(:label_version)}: #{container.name}"
58 58 when 'Document'
59 59 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
60 60 added_to = "#{l(:label_document)}: #{container.title}"
61 61 end
62 62 recipients container.project.recipients
63 63 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
64 64 body :attachments => attachments,
65 65 :added_to => added_to,
66 66 :added_to_url => added_to_url
67 67 end
68 68
69 69 def news_added(news)
70 70 recipients news.project.recipients
71 71 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
72 72 body :news => news,
73 73 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
74 74 end
75 75
76 76 def message_posted(message, recipients)
77 77 recipients(recipients)
78 78 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
79 79 body :message => message,
80 80 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
81 81 end
82 82
83 83 def account_information(user, password)
84 84 set_language_if_valid user.language
85 85 recipients user.mail
86 86 subject l(:mail_subject_register)
87 87 body :user => user,
88 88 :password => password,
89 89 :login_url => url_for(:controller => 'account', :action => 'login')
90 90 end
91 91
92 92 def lost_password(token)
93 93 set_language_if_valid(token.user.language)
94 94 recipients token.user.mail
95 95 subject l(:mail_subject_lost_password)
96 96 body :token => token,
97 97 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
98 98 end
99 99
100 100 def register(token)
101 101 set_language_if_valid(token.user.language)
102 102 recipients token.user.mail
103 103 subject l(:mail_subject_register)
104 104 body :token => token,
105 105 :url => url_for(:controller => 'account', :action => 'register', :token => token.value)
106 106 end
107 107
108 108 def test(user)
109 109 set_language_if_valid(user.language)
110 110 recipients user.mail
111 111 subject 'Redmine test'
112 112 body :url => url_for(:controller => 'welcome')
113 113 end
114 114
115 115 private
116 116 def initialize_defaults(method_name)
117 117 super
118 118 set_language_if_valid Setting.default_language
119 119 from Setting.mail_from
120 120 default_url_options[:host] = Setting.host_name
121 121 default_url_options[:protocol] = Setting.protocol
122 122 end
123 123
124 # Overrides the create_mail method to remove the current user from the recipients and cc
125 # if he doesn't want to receive notifications about what he does
126 def create_mail
127 recipients.delete(User.current.mail) if recipients && User.current.pref[:no_self_notified]
128 cc.delete(User.current.mail) if cc && User.current.pref[:no_self_notified]
129 super
130 end
131
124 132 # Renders a message with the corresponding layout
125 133 def render_message(method_name, body)
126 134 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
127 135 body[:content_for_layout] = render(:file => method_name, :body => body)
128 136 ActionView::Base.new(File.join(template_root, 'mailer'), body, self).render(:file => layout)
129 137 end
130 138 end
@@ -1,41 +1,42
1 1 <div class="contextual">
2 2 <%= link_to(l(:button_change_password), :action => 'password') unless @user.auth_source_id %>
3 3 </div>
4 4 <h2><%=l(:label_my_account)%></h2>
5 5 <%= error_messages_for 'user' %>
6 6
7 7 <% form_for :user, @user, :url => { :action => "account" }, :builder => TabularFormBuilder, :lang => current_language do |f| %>
8 8 <div class="splitcontentleft">
9 9 <h3><%=l(:label_information_plural)%></h3>
10 10 <div class="box tabular">
11 11 <p><%= f.text_field :firstname, :required => true %></p>
12 12 <p><%= f.text_field :lastname, :required => true %></p>
13 13 <p><%= f.text_field :mail, :required => true %></p>
14 14 <p><%= f.select :language, lang_options_for_select %></p>
15 15
16 16 <% fields_for :pref, @user.pref, :builder => TabularFormBuilder, :lang => current_language do |pref_fields| %>
17 17 <p><%= pref_fields.check_box :hide_mail %></p>
18 18 <% end %>
19 19 </div>
20 20
21 21 <%= submit_tag l(:button_save) %>
22 22 </div>
23 23
24 24 <div class="splitcontentright">
25 25 <h3><%=l(:field_mail_notification)%></h3>
26 26 <div class="box">
27 27 <%= select_tag 'notification_option', options_for_select(@notification_options, @notification_option),
28 28 :onchange => 'if ($("notification_option").value == "selected") {Element.show("notified-projects")} else {Element.hide("notified-projects")}' %>
29 29 <% content_tag 'div', :id => 'notified-projects', :style => (@notification_option == 'selected' ? '' : 'display:none;') do %>
30 30 <p><% User.current.projects.each do |project| %>
31 31 <label><%= check_box_tag 'notified_project_ids[]', project.id, @user.notified_projects_ids.include?(project.id) %> <%= project.name %></label><br />
32 32 <% end %></p>
33 33 <p><em><%= l(:text_user_mail_option) %></em></p>
34 34 <% end %>
35 <p><label><%= check_box_tag 'no_self_notified', 1, @user.pref[:no_self_notified] %> I don't want to be notified of changes that I make myself.</label></p>
35 36 </div>
36 37 </div>
37 38 <% end %>
38 39
39 40 <% content_for :sidebar do %>
40 41 <%= render :partial => 'sidebar' %>
41 42 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now