diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 63ea7970..b5571381 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -75,8 +75,8 @@ class DmsfController < ApplicationController render :action => "email_entries" return end - DmsfMailer.deliver_send_documents(User.current, @email_params["to"], @email_params["cc"], - @email_params["subject"], @email_params["zipped_content"], @email_params["body"]) + DmsfMailer.send_documents(User.current, @email_params["to"], @email_params["cc"], + @email_params["subject"], @email_params["zipped_content"], @email_params["body"]).deliver File.delete(@email_params["zipped_content"]) flash[:notice] = l(:notice_email_sent) redirect_to({:controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder}) @@ -129,7 +129,7 @@ class DmsfController < ApplicationController end unless deleted_files.empty? deleted_files.each {|f| log_activity(f, "deleted")} - DmsfMailer.deliver_files_deleted(User.current, deleted_files) + DmsfMailer.files_deleted(User.current, deleted_files).deliver end if failed_entries.empty? flash[:notice] = l(:notice_entries_deleted) diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index c7a8e1ab..20d1def2 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -120,7 +120,7 @@ class DmsfFilesController < ApplicationController flash[:notice] = (flash[:notice].nil? ? "" : flash[:notice]) + l(:notice_file_revision_created) log_activity("new revision") begin - DmsfMailer.deliver_files_updated(User.current, [@file]) + DmsfMailer.files_updated(User.current, [@file]).deliver rescue ActionView::MissingTemplate => e Rails.logger.error "Could not send email notifications: " + e end @@ -136,7 +136,7 @@ class DmsfFilesController < ApplicationController if @file.delete flash[:notice] = l(:notice_file_deleted) log_activity("deleted") - DmsfMailer.deliver_files_deleted(User.current, [@file]) + DmsfMailer.files_deleted(User.current, [@file]).deliver else flash[:error] = l(:error_file_is_locked) end diff --git a/app/controllers/dmsf_files_copy_controller.rb b/app/controllers/dmsf_files_copy_controller.rb index 44dca170..217f332a 100644 --- a/app/controllers/dmsf_files_copy_controller.rb +++ b/app/controllers/dmsf_files_copy_controller.rb @@ -72,7 +72,7 @@ class DmsfFilesCopyController < ApplicationController flash[:notice] = l(:notice_file_copied) log_activity(new_file, "was copied (is copy)") begin - DmsfMailer.deliver_files_updated(User.current, [new_file]) + DmsfMailer.files_updated(User.current, [new_file]).deliver rescue ActionView::MissingTemplate => e Rails.logger.error "Could not send email notifications: " + e end @@ -110,7 +110,7 @@ class DmsfFilesCopyController < ApplicationController log_activity(@file, "was moved (is copy)") begin # TODO: implement proper mail notification - DmsfMailer.deliver_files_updated(User.current, [@file]) + DmsfMailer.files_updated(User.current, [@file]).deliver rescue ActionView::MissingTemplate => e Rails.logger.error "Could not send email notifications: " + e end diff --git a/app/controllers/dmsf_folders_copy_controller.rb b/app/controllers/dmsf_folders_copy_controller.rb index 5d1049e9..7778dc61 100644 --- a/app/controllers/dmsf_folders_copy_controller.rb +++ b/app/controllers/dmsf_folders_copy_controller.rb @@ -74,7 +74,7 @@ class DmsfFoldersCopyController < ApplicationController #TODO: implement proper notification for all new files #begin - # DmsfMailer.deliver_files_updated(User.current, [new_file]) + # DmsfMailer.files_updated(User.current, [new_file]).deliver #rescue ActionView::MissingTemplate => e # Rails.logger.error "Could not send email notifications: " + e #end diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index b48d285e..273eebe1 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -158,7 +158,7 @@ class DmsfUploadController < ApplicationController unless files.empty? files.each {|file| log_activity(file, "uploaded")} begin - DmsfMailer.deliver_files_updated(User.current, files) + DmsfMailer.files_updated(User.current, files).deliver rescue ActionView::MissingTemplate => e Rails.logger.error "Could not send email notifications: " + e end diff --git a/app/models/dmsf_mailer.rb b/app/models/dmsf_mailer.rb index 186f6526..9751fc73 100644 --- a/app/models/dmsf_mailer.rb +++ b/app/models/dmsf_mailer.rb @@ -1,103 +1,98 @@ -# Redmine plugin for Document Management System "Features" -# -# Copyright (C) 2011 Vít Jonáš -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -require "mailer" - -class DmsfMailer < Mailer - - def files_updated(user, files) - project = files[0].project - files = files.select { |file| file.notify? } - - redmine_headers "Project" => project.identifier - recipients get_notify_user_emails(user, files) - subject project.name + ": Dmsf files updated" - body :user => user, :files => files, :project => project - # TODO: correct way should be render_multipart("files_updated", body), but other plugin broke it - render_multipart(File.expand_path(File.dirname(__FILE__) + "/../views/dmsf_mailer/" + "files_updated"), body) - end - - def files_deleted(user, files) - project = files[0].project - files = files.select { |file| file.notify? } - - redmine_headers "Project" => project.identifier - recipients get_notify_user_emails(user, files) - subject project.name + ": Dmsf files deleted" - body :user => user, :files => files, :project => project - # TODO: correct way should be render_multipart("files_updated", body), but other plugin broke it - render_multipart(File.expand_path(File.dirname(__FILE__) + "/../views/dmsf_mailer/" + "files_deleted"), body) - end - - def send_documents(user, email_to, email_cc, email_subject, zipped_content, email_plain_body) - recipients email_to - if !email_cc.strip.blank? - cc email_cc - end - subject email_subject - from user.mail - content_type "multipart/mixed" - - part "text/plain" do |p| - p.body = email_plain_body - end - - zipped_content_data = open(zipped_content, "rb") {|io| io.read } - - attachment :content_type => "application/zip", - :filename => "Documents.zip", - :body => zipped_content_data - end - - private - - def get_notify_user_emails(user, files) - if files.empty? - return [] - end - - project = files[0].project - - notify_members = project.members - notify_members = notify_members.select do |notify_member| - notify_user = notify_member.user - if notify_user.pref[:no_self_notified] && notify_user == user - false - else - if notify_member.dmsf_mail_notification.nil? - case notify_user.mail_notification - when 'all' - true - when 'selected' - notify_member.mail_notification? - when 'only_my_events' - notify_user.allowed_to?(:file_approval, project) ? true : false - when 'only_owner' - notify_user.allowed_to?(:file_approval, project) ? true : false - else - false - end - else notify_member.dmsf_mail_notification - end - end - end - - notify_members.collect {|m| m.user.mail } - end - -end +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011 Vít Jonáš +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require "mailer" + +class DmsfMailer < Mailer + + def files_updated(user, files) + project = files[0].project + files = files.select { |file| file.notify? } + + redmine_headers "Project" => project.identifier + + @user = user + @files = files + @project = project + + mail :to => get_notify_user_emails(user, files), + :subject => project.name + ": Dmsf files updated" + end + + def files_deleted(user, files) + project = files[0].project + files = files.select { |file| file.notify? } + + redmine_headers "Project" => project.identifier + + @user = user + @files = files + @project = project + + mail :to => get_notify_user_emails(user, files), + :subject => project.name + ": Dmsf files deleted" + end + + def send_documents(user, email_to, email_cc, email_subject, zipped_content, email_plain_body) +debugger + zipped_content_data = open(zipped_content, "rb") {|io| io.read } + + @body = email_plain_body + + attachments['Documents.zip'] = {:content_type => "application/zip", :content => zipped_content_data} + mail(:to => email_to, :cc => email_cc, :subject => email_subject, :from => user.mail) + end + + private + + def get_notify_user_emails(user, files) + if files.empty? + return [] + end + + project = files[0].project + + notify_members = project.members + notify_members = notify_members.select do |notify_member| + notify_user = notify_member.user + if notify_user.pref[:no_self_notified] && notify_user == user + false + else + if notify_member.dmsf_mail_notification.nil? + case notify_user.mail_notification + when 'all' + true + when 'selected' + notify_member.mail_notification? + when 'only_my_events' + notify_user.allowed_to?(:file_approval, project) ? true : false + when 'only_owner' + notify_user.allowed_to?(:file_approval, project) ? true : false + else + false + end + else + notify_member.dmsf_mail_notification + end + end + end + + notify_members.collect {|m| m.user.mail } + end + +end diff --git a/app/views/dmsf/email_entries.html.erb b/app/views/dmsf/email_entries.html.erb index 32d55d1c..7740daa3 100644 --- a/app/views/dmsf/email_entries.html.erb +++ b/app/views/dmsf/email_entries.html.erb @@ -10,7 +10,7 @@

<%= l(:heading_send_documents_by_email) %>

-<% form_tag({:action => "entries_email", :id => @project, :folder_id => @folder}, +<%= form_tag({:action => "entries_email", :id => @project, :folder_id => @folder}, { :method=>:post, :class => "tabular"}) do %>

@@ -40,4 +40,4 @@

<%= submit_tag(l(:label_email_send)) %>

-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/dmsf_mailer/send_documents.html.erb b/app/views/dmsf_mailer/send_documents.html.erb index 85a89fce..64463098 100644 --- a/app/views/dmsf_mailer/send_documents.html.erb +++ b/app/views/dmsf_mailer/send_documents.html.erb @@ -1 +1 @@ -<%= ApplicationHelper.simple_format(@body) %> +<%= simple_format(@body) %> diff --git a/config/routes.rb b/config/routes.rb index 40b4c4a4..a87d4e9c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,6 +35,7 @@ RedmineApp::Application.routes.draw do post '/projects/:id/dmsf/save/root', :controller => 'dmsf', :action => 'save_root' post '/projects/:id/dmsf/entries', :controller => 'dmsf', :action => 'entries_operation' post '/projects/:id/dmsf/entries/delete', :controller => 'dmsf', :action => 'delete_entries' + post '/projects/:id/dmsf/entries/email', :controller => 'dmsf', :action => 'entries_email' get '/projects/:id/dmsf/', :controller => 'dmsf', :action => 'show' get '/projects/:id/dmsf/new', :controller => 'dmsf', :action => 'new' get '/projects/:id/dmsf/edit', :controller=> 'dmsf', :action => 'edit' diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 6e870418..a06e9306 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -4,3 +4,6 @@ require 'redmine_dmsf/patches/project_patch' module RedmineDmsf end + +#Add plugin's view folder into ActionMailer's paths to search +ActionMailer::Base.append_view_path(File.expand_path(File.dirname(__FILE__) + '/../app/views'))