Actual changes...

This commit is contained in:
Daniel Munn 2012-06-03 18:03:14 +01:00
parent 835d02aedf
commit ae73ed64cd
10 changed files with 114 additions and 115 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,103 +1,98 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
#
# 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áš <vit.jonas@gmail.com>
#
# 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

View File

@ -10,7 +10,7 @@
<h3><%= l(:heading_send_documents_by_email) %></h3>
<% 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 %>
<div class="box">
<p>
@ -40,4 +40,4 @@
</p>
<p><%= submit_tag(l(:label_email_send)) %></p>
</div>
<% end %>
<% end %>

View File

@ -1 +1 @@
<%= ApplicationHelper.simple_format(@body) %>
<%= simple_format(@body) %>

View File

@ -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'

View File

@ -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'))