# HG changeset patch # User luisf # Date 1315574354 -3600 # Node ID f029431de4ddaf60f5691a4978a122ce614652f8 # Parent 7a7dcbdffe26834ef07e3430abfb7b0a0fc1ae4f Feature #253: Correctly sending emails to users when new publication is added. diff -r 7a7dcbdffe26 -r f029431de4dd vendor/plugins/redmine_bibliography/app/models/publication.rb --- 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 diff -r 7a7dcbdffe26 -r f029431de4dd vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.html.rhtml --- 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 @@ -

<%= l(:notice_account_activated) %>

-

<%= l(:label_login) %>: <%= link_to @login_url, @login_url %>

+<%= link_to(h(@publication.title), @publication_url) %>
+
+<%= textilizable(@publication, :title, :only_path => false) %> diff -r 7a7dcbdffe26 -r f029431de4dd vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.plain.rhtml --- 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 %> + diff -r 7a7dcbdffe26 -r f029431de4dd vendor/plugins/redmine_bibliography/init.rb --- 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 diff -r 7a7dcbdffe26 -r f029431de4dd vendor/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb --- 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