#201 Download link by email

This commit is contained in:
Karel Picman 2014-02-26 10:17:56 +01:00
parent 31463cdba2
commit 79a3216d40
17 changed files with 129 additions and 24 deletions

View File

@ -63,6 +63,16 @@ class DmsfController < ApplicationController
@ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].present? ? Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'] : 100
end
def download_email_entries
send_file(
params[:path],
:filename => 'Documents.zip',
:type => 'application/zip',
:disposition => 'attachment')
rescue Exception => e
flash[:error] = e.message
end
def entries_operation
selected_folders = params[:subfolders].present? ? params[:subfolders] : []
@ -110,16 +120,16 @@ class DmsfController < ApplicationController
def entries_email
@email_params = params[:email]
if @email_params['to'].strip.blank?
if @email_params[:to].strip.blank?
flash.now[:error] = l(:error_email_to_must_be_entered)
render :action => 'email_entries'
return
end
DmsfMailer.send_documents(@project, User.current, @email_params['to'], @email_params['cc'],
@email_params['subject'], @email_params['zipped_content'], @email_params['body']).deliver
end
DmsfMailer.send_documents(@project, User.current, @email_params).deliver
File.delete(@email_params['zipped_content'])
flash[:notice] = l(:notice_email_sent, @email_params['to'])
redirect_to({:controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @folder})
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
end
def delete_entries
@ -342,9 +352,9 @@ class DmsfController < ApplicationController
zip = DmsfZip.new
zip_entries(zip, selected_folders, selected_files)
ziped_content = "#{DmsfHelper.temp_dir}/#{DmsfHelper.temp_filename('dmsf_email_sent_documents.zip')}";
zipped_content = "#{DmsfHelper.temp_dir}/#{DmsfHelper.temp_filename('dmsf_email_sent_documents.zip')}";
File.open(ziped_content, 'wb') do |f|
File.open(zipped_content, 'wb') do |f|
zip_file = File.open(zip.finish, 'rb')
while (buffer = zip_file.read(8192))
f.write(buffer)
@ -352,7 +362,7 @@ class DmsfController < ApplicationController
end
max_filesize = Setting.plugin_redmine_dmsf['dmsf_max_email_filesize'].to_f
if max_filesize > 0 && File.size(ziped_content) > max_filesize * 1048576
if max_filesize > 0 && File.size(zipped_content) > max_filesize * 1048576
raise EmailMaxFileSize
end
@ -363,7 +373,11 @@ class DmsfController < ApplicationController
audit.save!
end
@email_params = {'zipped_content' => ziped_content}
@email_params = {
:zipped_content => zipped_content,
:folders => selected_folders,
:files => selected_files
}
render :action => 'email_entries'
rescue Exception => e
flash[:error] = e.message

View File

@ -140,6 +140,12 @@ class DmsfFolder < ActiveRecord::Base
return tree
end
def folder_tree
tree = [[self.title, self.id]]
DmsfFolder.directory_subtree(tree, self, 2, nil)
return tree
end
def self.file_list(files)
options = Array.new
options.push ['', nil]

View File

@ -55,16 +55,22 @@ class DmsfMailer < Mailer
:subject => l(:text_email_doc_deleted_subject, :project => project.name)
end
end
def send_documents(project, user, email_to, email_cc, email_subject, zipped_content, email_plain_body)
zipped_content_data = open(zipped_content, 'rb') {|io| io.read }
def send_documents(project, user, email_params)
zipped_content_data = open(email_params[:zipped_content], 'rb') { |io| io.read }
redmine_headers 'Project' => project.identifier if project
@body = email_plain_body
@body = email_params[:body]
@links_only = email_params[:links_only]
@folders = email_params[:folders]
@files = email_params[:files]
attachments['Documents.zip'] = {:content_type => 'application/zip', :content => zipped_content_data}
mail :to => email_to, :cc => email_cc, :subject => email_subject, :from => user.mail
unless @links_only == '1'
attachments['Documents.zip'] = { :content_type => 'application/zip', :content => zipped_content_data }
end
mail :to => email_params[:to], :cc => email_params[:cc], :subject => email_params[:subject], :from => user.mail
end
def workflow_notification(user, workflow, revision, subject, text1, text2)

View File

@ -28,10 +28,13 @@
<%= form_tag({:action => 'entries_email', :id => @project, :folder_id => @folder},
{ :method=>:post, :class => 'tabular'}) do %>
<%= hidden_field_tag('email[zipped_content]', @email_params[:zipped_content]) %>
<%= hidden_field_tag('email[folders]', @email_params[:folders].to_json) %>
<%= hidden_field_tag('email[files]', @email_params[:files].to_json) %>
<div class="box">
<p>
<%= label_tag('', "#{l(:label_email_from)}:") %>
<%= h(User.current.mail) %>
<i><%= h(User.current.mail) %></i>
</p>
<p>
<%= label_tag('email[to]', "#{l(:label_email_to)}:") %>
@ -47,8 +50,9 @@
</p>
<p>
<%= label_tag('', "#{l(:label_email_documents)}:") %>
<strong>Documents.zip</strong>
<%= hidden_field_tag('email[zipped_content]', @email_params['zipped_content']) %>
<%= link_to 'Documents.zip',
download_email_entries_path(:id => @project, :folder_id => @folder, :path => @email_params['zipped_content']) %>
<%= l(:label_or) %> <%= check_box_tag('email[links_only]') %> <%= l(:label_links_only) %>
</p>
<p>
<%= label_tag('email[body]', "#{l(:label_email_body)}:") %>
@ -57,3 +61,5 @@
<p><%= submit_tag(l(:label_email_send)) %></p>
</div>
<% end %>
<%= wikitoolbar_for 'email_body' %>

View File

@ -1,7 +1,8 @@
<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -17,4 +18,38 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= simple_format(@body) %>
<%= textilizable(@body) %>
<% if @links_only == '1' %>
<% if @folders.present? %>
<% JSON.parse(@folders).each do |id| %>
<% folder = DmsfFolder.find_by_id id %>
<% if folder %>
<% folder.folder_tree.each do |name, i| %>
<% dir = DmsfFolder.find_by_id i %>
<% if dir %>
<br/>
<%= link_to(h(dir.dmsf_path_str), dmsf_folder_path(:id => dir.project_id, :folder_id => dir.id, :only_path => false)) %>
<br/><br/>
<% dir.files.each do |file| %>
<%= link_to(h(file.title), dmsf_file_path(file, :only_path => false)) %>
&nbsp;(<%= link_to(h(file.name), dmsf_file_path(file, :download => '', :only_path => false)) %>)
<br/>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% if @files.present? %>
<br/>
<% JSON.parse(@files).each do |id| %>
<% file = DmsfFile.find_by_id id %>
<% if file %>
<%= link_to(h(file.title), dmsf_file_path(file, :only_path => false)) %>
&nbsp;(<%= link_to(h(file.name), dmsf_file_path(file, :download => '', :only_path => false)) %>)
<br/>
<% end %>
<% end %>
<% end %>
<% end %>

View File

@ -1,7 +1,8 @@
<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,3 +19,30 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= @body %>
<% if @links_only == '1' %>
<% if @folders.present? %>
<% JSON.parse(@folders).each do |id| %>
<% folder = DmsfFolder.find_by_id id %>
<% if folder %>
<% folder.folder_tree.each do |name, i| %>
<% dir = DmsfFolder.find_by_id i %>
<% if dir %>
<%= dir.dmsf_path_str %>
<% dir.files.each do |file| %>
<%= dmsf_file_path(file, :download => '', :only_path => false) %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% if @files.present? %>
<% JSON.parse(@files).each do |id| %>
<% file = DmsfFile.find_by_id id %>
<% if file %>
<%= dmsf_file_path(file, :download => '', :only_path => false) %>
<% end %>
<% end %>
<% end %>
<% end %>

View File

@ -284,6 +284,7 @@ cs:
text_email_doc_follows: takto
text_email_doc_deleted_subject: "Dokumenty projektu %{project} smazány"
text_email_doc_deleted: právě smazal dokumety projektu
label_links_only: pouze odkazy
my:
blocks:

View File

@ -279,6 +279,7 @@ de:
label_notifications_off: Notifications off
field_target_file: Target file
title_download_entries: Download entries
label_links_only: links only
my:
blocks:

View File

@ -288,6 +288,7 @@ en:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -285,6 +285,7 @@ es:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -288,6 +288,7 @@ fr:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -285,6 +285,7 @@ ja:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -285,6 +285,7 @@ ru:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -285,6 +285,7 @@ sl:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -286,6 +286,7 @@ zh:
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
label_links_only: links only
my:
blocks:

View File

@ -34,6 +34,7 @@ RedmineApp::Application.routes.draw do
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/entries/download_email_entries', :controller => 'dmsf', :action => 'download_email_entries', :as => 'download_email_entries'
get '/projects/:id/dmsf/lock', :controller => 'dmsf', :action => 'lock', :as => 'lock_dmsf'
get '/projects/:id/dmsf/unlock', :controller => 'dmsf', :action => 'unlock', :as => 'unlock_dmsf'
get '/projects/:id/dmsf/', :controller => 'dmsf', :action => 'show', :as => 'dmsf_folder'

View File

@ -57,7 +57,7 @@ Redmine::Plugin.register :redmine_dmsf do
permission :user_preferences,
{:dmsf_state => [:user_pref_save]}
permission :view_dmsf_files,
{:dmsf => [:entries_operation, :entries_email],
{:dmsf => [:entries_operation, :entries_email, :download_email_entries],
:dmsf_files => [:show],
:dmsf_files_copy => [:new, :create, :move],
:dmsf_workflows => [:log]},