changeset 651:f029431de4dd feature_36

Feature #253: Correctly sending emails to users when new publication is added.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 09 Sep 2011 14:19:14 +0100
parents 7a7dcbdffe26
children 0c872fe77797
files vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.html.rhtml vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.plain.rhtml vendor/plugins/redmine_bibliography/init.rb vendor/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb
diffstat 5 files changed, 39 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Sep 09 12:27:32 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Sep 09 14:19:14 2011 +0100
@@ -21,8 +21,9 @@
   
   # Returns the mail adresses of users that should be notified
   def notify_authors
-    
+        
     self.authors.each do |author|
+      Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
       Mailer.deliver_publication_added(author.user, self) unless author.user.nil?
     end
     
--- a/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.html.rhtml	Fri Sep 09 12:27:32 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.html.rhtml	Fri Sep 09 14:19:14 2011 +0100
@@ -1,2 +1,3 @@
-<p><%= l(:notice_account_activated) %></p>
-<p><%= l(:label_login) %>: <%= link_to @login_url, @login_url %></p>
+<%= link_to(h(@publication.title), @publication_url) %> <br />
+<br />
+<%= textilizable(@publication, :title, :only_path => false) %>
--- a/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.plain.rhtml	Fri Sep 09 12:27:32 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.plain.rhtml	Fri Sep 09 14:19:14 2011 +0100
@@ -1,2 +1,3 @@
-<%= l(:notice_account_activated) %>
-<%= l(:label_login) %>: <%= @login_url %>
+<%= @publication.title %>
+<%= @publication_url %>
+
--- a/vendor/plugins/redmine_bibliography/init.rb	Fri Sep 09 12:27:32 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/init.rb	Fri Sep 09 14:19:14 2011 +0100
@@ -7,7 +7,7 @@
 Dispatcher.to_prepare :redmine_model_dependencies do
   require_dependency 'project'
   require_dependency 'user'
-  require_dependency 'mailer_patch'
+  require_dependency 'mailer'
 
   unless Project.included_modules.include? Bibliography::ProjectPublicationsPatch
     Project.send(:include, Bibliography::ProjectPublicationsPatch)
@@ -17,8 +17,8 @@
     User.send(:include, Bibliography::UserAuthorPatch)
   end
 
-  unless Mailer.included_modules.include? MailerPatch
-    Mailer.send(:include, MailerPatch)
+  unless Mailer.included_modules.include? Bibliography::MailerPatch
+    Mailer.send(:include, Bibliography::MailerPatch)
   end
 
 
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb	Fri Sep 09 12:27:32 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb	Fri Sep 09 14:19:14 2011 +0100
@@ -0,0 +1,28 @@
+require_dependency 'mailer'
+
+module Bibliography
+  module MailerPatch
+      def self.included(base) # :nodoc:
+
+        # Builds a tmail object used to email the specified user that a publication was created and the user is 
+        # an author of that publication
+        #
+        # Example:
+        #   publication_added(user) => tmail object
+        #   Mailer.deliver_add_to_project(user) => sends an email to the registered user
+        def publication_added(user, publication)
+
+          @publication = publication
+
+          set_language_if_valid user.language
+          recipients user.mail
+          subject l(:mail_subject_publication_added, Setting.app_title)
+          body :publication_url => url_for( :controller => 'publications', :action => 'show', :id => publication.id ),
+              :publication_title => publication.title
+          render_multipart('publication_added', body)
+        end
+        
+        
+    end
+  end
+end