Feature #1757 » notify_watcher_when_add_or_delete_in_issue.patch
| app/controllers/watchers_controller.rb | ||
|---|---|---|
|
Watcher.create(:watchable => watchable, :user => user)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
# send e-mail notify for user when he added as watcher in issue
|
||
|
current_user_add_watcher = User.current
|
||
|
@watchables.each do |issue|
|
||
|
Mailer.deliver_issue_watcher_add(issue, current_user_add_watcher, users)
|
||
|
end
|
||
|
respond_to do |format|
|
||
|
format.html do
|
||
|
redirect_to_referer_or do
|
||
| ... | ... | |
|
end
|
||
|
def destroy
|
||
|
user = Principal.find(params[:user_id])
|
||
|
user = Principal.find(params[:user_id]) # User who is being removed from the watchers
|
||
|
@watchables.each do |watchable|
|
||
|
watchable.set_watcher(user, false)
|
||
|
end
|
||
|
|
||
|
# send e-mail notify for user when he deleted as watcher in issue
|
||
|
current_user_delete_watcher = User.current
|
||
|
if params["object_type"] == "issue"
|
||
|
issue = Issue.find(params['object_id'])
|
||
|
Mailer.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher)
|
||
|
end
|
||
|
respond_to do |format|
|
||
|
format.html do
|
||
|
redirect_to_referer_or do
|
||
| app/models/mailer.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
# Builds a mail for notifying user about a new watcher
|
||
|
def issue_watcher_add(user, issue, current_user_add_watcher)
|
||
|
@current_user_add_watcher = current_user_add_watcher
|
||
|
@issue = issue
|
||
|
@user = user
|
||
|
@author = issue.author
|
||
|
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||
|
@table = Text::Table.new
|
||
|
@mail_signature = mail_signature_for(user, issue)
|
||
|
|
||
|
subject = "[##{issue.id} - #{issue.tracker.name}]"
|
||
|
subject += " (#{l(:field_watcher)})"
|
||
|
subject += " #{issue.subject}"
|
||
|
subject += " [#{issue.project.name}]"
|
||
|
|
||
|
mail :to => user,
|
||
|
:subject => subject
|
||
|
end
|
||
|
# Notifies users about a new watchers.
|
||
|
# Example:
|
||
|
# Mailer.deliver_issue_watcher_add(issue, current_user_add_watcher, users)
|
||
|
# Notifies users when they were ADDED as an watcher to issue
|
||
|
def self.deliver_issue_watcher_add(issue, current_user_add_watcher, users)
|
||
|
# if 'issue_updated' in Admin -> Settings -> tab Notifications in Redmine is checkboxed
|
||
|
if Setting.notified_events.include?('issue_updated')
|
||
|
notified = users
|
||
|
# if 'notified' contain <Groups> then divided into separate users
|
||
|
notified = notified.map {|n| n.is_a?(Group) ? n.users : n}.flatten
|
||
|
notified.uniq!
|
||
|
users = notified
|
||
|
|
||
|
users.each do |user|
|
||
|
issue_watcher_add(user, issue, current_user_add_watcher).deliver_later
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Builds a mail for notifying user about a DELETE watcher
|
||
|
def issue_watcher_delete(user, issue, current_user_delete_watcher)
|
||
|
@current_user_delete_watcher = current_user_delete_watcher
|
||
|
@issue = issue
|
||
|
@user = user
|
||
|
@author = issue.author
|
||
|
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
|
||
|
@table = Text::Table.new
|
||
|
@mail_signature = mail_signature_for(user, issue)
|
||
|
|
||
|
subject = "[##{issue.id} - #{issue.tracker.name}]"
|
||
|
subject += " (#{l(:field_watcher)})"
|
||
|
subject += " #{issue.subject}"
|
||
|
subject += " [#{issue.project.name}]"
|
||
|
|
||
|
mail :to => user,
|
||
|
:subject => subject
|
||
|
end
|
||
|
# Notifies users about a deleting watchers.
|
||
|
# Example:
|
||
|
# Mailer.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher)
|
||
|
# Notifies users when they were DELETED as an watcher to issue
|
||
|
def self.deliver_issue_watcher_delete(issue, user, current_user_delete_watcher)
|
||
|
# if 'issue_updated' in Admin -> Settings -> tab Notifications in Redmine is checkboxed
|
||
|
if Setting.notified_events.include?('issue_updated')
|
||
|
notified = [user]
|
||
|
# if 'notified' contain <Groups> then divided into separate users
|
||
|
notified = notified.map {|n| n.is_a?(Group) ? n.users : n}.flatten
|
||
|
notified.uniq!
|
||
|
users = notified
|
||
|
|
||
|
users.each do |user|
|
||
|
issue_watcher_delete(user, issue, current_user_delete_watcher).deliver_later
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Builds a mail to user about a new document.
|
||
|
def document_added(user, document, author)
|
||
|
redmine_headers 'Project' => document.project.identifier
|
||
| app/views/mailer/issue_watcher_add.html.erb | ||
|---|---|---|
|
<p>You have been added to the watchers in issue. Added <%= @current_user_add_watcher %>.</p>
|
||
|
<hr>
|
||
|
<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %>
|
||
|
<hr>
|
||
|
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
|
||
| app/views/mailer/issue_watcher_add.text.erb | ||
|---|---|---|
|
You have been added to the watchers in issue. Added <%= @current_user_add_watcher %>.
|
||
|
------------
|
||
|
<%= l(:text_issue_added, :id => "##{@issue.id}", :author => @issue.author) %>
|
||
|
----------------------------------------
|
||
|
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
|
||
| app/views/mailer/issue_watcher_delete.html.erb | ||
|---|---|---|
|
<p>You have been removed from the watchers in issue. Removed <%= @current_user_delete_watcher %>.</p>
|
||
|
<hr>
|
||
|
<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %>
|
||
|
<hr>
|
||
|
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
|
||
| app/views/mailer/issue_watcher_delete.text.erb | ||
|---|---|---|
|
You have been removed from the watchers in issue. Removed <%= @current_user_delete_watcher %>.
|
||
|
------------
|
||
|
<%= l(:text_issue_added, :id => "##{@issue.id}", :author => @issue.author) %>
|
||
|
----------------------------------------
|
||
|
<%= render :partial => 'issue', :formats => [:text], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
|
||
|
-
|
||
- « Previous
- 1
- 2
- Next »