Feature #1757 » notify_watcher_when_add_or_delete_in_issue.patch
app/controllers/watchers_controller.rb | ||
---|---|---|
49 | 49 |
Watcher.create(:watchable => watchable, :user => user) |
50 | 50 |
end |
51 | 51 |
end |
52 |
|
|
53 |
# send e-mail notify for user when he added as watcher in issue |
|
54 |
current_user_add_watcher = User.current |
|
55 |
@watchables.each do |issue| |
|
56 |
Mailer.deliver_issue_watcher_add(issue, current_user_add_watcher, users) |
|
57 |
end |
|
58 | ||
52 | 59 |
respond_to do |format| |
53 | 60 |
format.html do |
54 | 61 |
redirect_to_referer_or do |
... | ... | |
71 | 81 |
end |
72 | 82 | |
73 | 83 |
def destroy |
74 |
user = Principal.find(params[:user_id]) |
|
84 |
user = Principal.find(params[:user_id]) # User who is being removed from the watchers
|
|
75 | 85 |
@watchables.each do |watchable| |
76 | 86 |
watchable.set_watcher(user, false) |
77 | 87 |
end |
88 |
|
|
89 |
# send e-mail notify for user when he deleted as watcher in issue |
|
90 |
current_user_delete_watcher = User.current |
|
91 |
if params["object_type"] == "issue" |
|
92 |
issue = Issue.find(params['object_id']) |
|
93 |
Mailer.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher) |
|
94 |
end |
|
95 | ||
78 | 96 |
respond_to do |format| |
79 | 97 |
format.html do |
80 | 98 |
redirect_to_referer_or do |
app/models/mailer.rb | ||
---|---|---|
138 | 138 |
end |
139 | 139 |
end |
140 |
# Builds a mail for notifying user about a new watcher |
|
141 |
def issue_watcher_add(user, issue, current_user_add_watcher) |
|
142 |
@current_user_add_watcher = current_user_add_watcher |
|
143 |
@issue = issue |
|
144 |
@user = user |
|
145 |
@author = issue.author |
|
146 | ||
147 |
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
148 | ||
149 |
@table = Text::Table.new |
|
150 |
@mail_signature = mail_signature_for(user, issue) |
|
151 |
|
|
152 |
subject = "[##{issue.id} - #{issue.tracker.name}]" |
|
153 |
subject += " (#{l(:field_watcher)})" |
|
154 |
subject += " #{issue.subject}" |
|
155 |
subject += " [#{issue.project.name}]" |
|
156 |
|
|
157 |
mail :to => user, |
|
158 |
:subject => subject |
|
159 |
end |
|
160 | ||
161 |
# Notifies users about a new watchers. |
|
162 |
# Example: |
|
163 |
# Mailer.deliver_issue_watcher_add(issue, current_user_add_watcher, users) |
|
164 | ||
165 |
# Notifies users when they were ADDED as an watcher to issue |
|
166 |
def self.deliver_issue_watcher_add(issue, current_user_add_watcher, users) |
|
167 |
# if 'issue_updated' in Admin -> Settings -> tab Notifications in Redmine is checkboxed |
|
168 |
if Setting.notified_events.include?('issue_updated') |
|
169 |
notified = users |
|
170 |
# if 'notified' contain <Groups> then divided into separate users |
|
171 |
notified = notified.map {|n| n.is_a?(Group) ? n.users : n}.flatten |
|
172 |
notified.uniq! |
|
173 |
users = notified |
|
174 |
|
|
175 |
users.each do |user| |
|
176 |
issue_watcher_add(user, issue, current_user_add_watcher).deliver_later |
|
177 |
end |
|
178 |
end |
|
179 |
end |
|
180 | ||
181 |
# Builds a mail for notifying user about a DELETE watcher |
|
182 |
def issue_watcher_delete(user, issue, current_user_delete_watcher) |
|
183 |
@current_user_delete_watcher = current_user_delete_watcher |
|
184 |
@issue = issue |
|
185 |
@user = user |
|
186 |
@author = issue.author |
|
187 | ||
188 |
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
189 | ||
190 |
@table = Text::Table.new |
|
191 |
@mail_signature = mail_signature_for(user, issue) |
|
192 |
|
|
193 |
subject = "[##{issue.id} - #{issue.tracker.name}]" |
|
194 |
subject += " (#{l(:field_watcher)})" |
|
195 |
subject += " #{issue.subject}" |
|
196 |
subject += " [#{issue.project.name}]" |
|
197 |
|
|
198 |
mail :to => user, |
|
199 |
:subject => subject |
|
200 |
end |
|
201 | ||
202 |
# Notifies users about a deleting watchers. |
|
203 |
# Example: |
|
204 |
# Mailer.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher) |
|
205 | ||
206 |
# Notifies users when they were DELETED as an watcher to issue |
|
207 |
def self.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher) |
|
208 |
# if 'issue_updated' in Admin -> Settings -> tab Notifications in Redmine is checkboxed |
|
209 |
if Setting.notified_events.include?('issue_updated') |
|
210 |
notified = [user] |
|
211 |
# if 'notified' contain <Groups> then divided into separate users |
|
212 |
notified = notified.map {|n| n.is_a?(Group) ? n.users : n}.flatten |
|
213 |
notified.uniq! |
|
214 |
users = notified |
|
215 |
|
|
216 |
users.each do |user| |
|
217 |
issue_watcher_delete(user, issue, current_user_delete_watcher).deliver_later |
|
218 |
end |
|
219 |
end |
|
220 |
end |
|
221 | ||
222 | ||
223 | ||
140 | 224 |
# Builds a mail to user about a new document. |
141 | 225 |
def document_added(user, document, author) |
142 | 226 |
redmine_headers 'Project' => document.project.identifier |
app/views/mailer/issue_watcher_add.html.erb | ||
---|---|---|
1 |
<p>You have been added to the watchers in issue. Added <%= @current_user_add_watcher %>.</p> |
|
2 |
<hr> |
|
3 | ||
4 |
<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %> |
|
5 |
<hr> |
|
6 |
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %> |
app/views/mailer/issue_watcher_add.text.erb | ||
---|---|---|
1 |
You have been added to the watchers in issue. Added <%= @current_user_add_watcher %>. |
|
2 |
------------ |
|
3 | ||
4 |
<%= l(:text_issue_added, :id => "##{@issue.id}", :author => @issue.author) %> |
|
5 | ||
6 |
---------------------------------------- |
|
7 |
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %> |
app/views/mailer/issue_watcher_delete.html.erb | ||
---|---|---|
1 |
<p>You have been removed from the watchers in issue. Removed <%= @current_user_delete_watcher %>.</p> |
|
2 |
<hr> |
|
3 | ||
4 |
<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %> |
|
5 |
<hr> |
|
6 |
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %> |
app/views/mailer/issue_watcher_delete.text.erb | ||
---|---|---|
1 |
You have been removed from the watchers in issue. Removed <%= @current_user_delete_watcher %>. |
|
2 |
------------ |
|
3 | ||
4 |
<%= l(:text_issue_added, :id => "##{@issue.id}", :author => @issue.author) %> |
|
5 | ||
6 |
---------------------------------------- |
|
7 |
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %> |
|
0 |
- |
- « Previous
- 1
- 2
- Next »