Use Redmine's temp folder #1360
This commit is contained in:
parent
0892e536e1
commit
2112567be6
@ -35,19 +35,10 @@ module DmsfHelper
|
||||
|
||||
end
|
||||
|
||||
def self.temp_dir
|
||||
if Setting.plugin_redmine_dmsf['dmsf_tmpdir'].present?
|
||||
tmpdir = Pathname.new(Setting.plugin_redmine_dmsf['dmsf_tmpdir'])
|
||||
else
|
||||
tmpdir = Pathname.new(Dir.tmpdir)
|
||||
end
|
||||
tmpdir
|
||||
end
|
||||
|
||||
def self.temp_filename(filename)
|
||||
filename = sanitize_filename(filename)
|
||||
timestamp = DateTime.current.strftime('%y%m%d%H%M%S')
|
||||
while temp_dir.join("#{timestamp}_#{filename}").exist?
|
||||
while File.exist?(File.join(Rails.root, 'tmp', "#{timestamp}_#{filename}"))
|
||||
timestamp.succ!
|
||||
end
|
||||
"#{timestamp}_#{filename}"
|
||||
|
||||
@ -39,7 +39,7 @@ class DmsfUpload
|
||||
attr_accessor :digest
|
||||
|
||||
def disk_file
|
||||
DmsfHelper.temp_dir.join(disk_filename).to_s
|
||||
File.join Rails.root, 'tmp', disk_filename
|
||||
end
|
||||
|
||||
def self.create_from_uploaded_attachment(project, folder, uploaded_file)
|
||||
|
||||
@ -80,36 +80,6 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= content_tag(:label, l(:label_tmpdir)) %>
|
||||
<%
|
||||
tmpdir = @settings['dmsf_tmpdir'].strip if @settings['dmsf_tmpdir'].present?
|
||||
tmpdir = Dir.tmpdir if tmpdir.blank?
|
||||
%>
|
||||
<%= text_field_tag 'settings[dmsf_tmpdir]', tmpdir, size: 256 %>
|
||||
<em class="info">
|
||||
<%= l(:label_default) %>: <%= Dir.tmpdir %>
|
||||
</em>
|
||||
</p>
|
||||
<% unless File.exist?(tmpdir) %>
|
||||
<% begin %>
|
||||
<% FileUtils.mkdir_p tmpdir %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_file_tmpdir_does_not_exist) %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% path = Pathname.new(tmpdir) %>
|
||||
<% testfilename = path.join('test.test') %>
|
||||
<% if File.exist?(tmpdir) %>
|
||||
<% begin %>
|
||||
<% File.open(testfilename, 'wb') {} %>
|
||||
<% rescue %>
|
||||
<p class="warning"><%= l(:error_tmpfile_can_not_be_created) %></p>
|
||||
<% ensure %>
|
||||
<% FileUtils.rm_f testfilename %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= content_tag :label, l(:label_dmsf_office_bin) %>
|
||||
<%= text_field_tag 'settings[office_bin]', @settings['office_bin'], size: 10 %>
|
||||
|
||||
@ -378,10 +378,6 @@ cs:
|
||||
label_dmsf_attachments: DMS přílohy
|
||||
label_basic_attachments: Souborové přílohy
|
||||
|
||||
label_tmpdir: Adresář pro dočasné soubory
|
||||
error_file_tmpdir_does_not_exist: Adresář pro dočasné soubory neexistuje a nemůže být vytvořen
|
||||
error_tmpfile_can_not_be_created: Nelze vytvořit soubor v adresáři pro dočasné soubory
|
||||
|
||||
label_email_from_override: Od
|
||||
text_email_from_override: aktuálně přihlášený uživatel
|
||||
label_email_reply_to: Odpovědět komu
|
||||
|
||||
@ -374,10 +374,6 @@ de:
|
||||
label_dmsf_attachments: DMS Anhänge
|
||||
label_basic_attachments: Dateianhänge
|
||||
|
||||
label_tmpdir: Temporärer Dateipfad
|
||||
error_file_tmpdir_does_not_exist: "Temporärer Dateipfad existiert nicht und kann nicht erstellt werden."
|
||||
error_tmpfile_can_not_be_created: "Dateien können nicht im temporären Dateipfad erstellt werden."
|
||||
|
||||
label_email_from_override: Von
|
||||
text_email_from_override: Der angemeldete Benutzer
|
||||
label_email_reply_to: Antwort an
|
||||
|
||||
@ -378,10 +378,6 @@ en:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ es:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ fr:
|
||||
label_dmsf_attachments: Pièces-jointes DMS
|
||||
label_basic_attachments: Pièces-jointes standards
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -377,10 +377,6 @@ hu:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ it: # Italian strings thx 2 Matteo Arceci!
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ ja:
|
||||
label_dmsf_attachments: DMS 添付ファイル
|
||||
label_basic_attachments: 標準 添付ファイル
|
||||
|
||||
label_tmpdir: 一時フォルダのパス
|
||||
error_file_tmpdir_does_not_exist: 指定された一時フォルダが存在せず、作成もできません
|
||||
error_tmpfile_can_not_be_created: 指定された一時フォルダにファイルを作成できません
|
||||
|
||||
label_email_from_override: 差出人
|
||||
text_email_from_override: 現在ログインしているユーザー
|
||||
label_email_reply_to: 返信先
|
||||
|
||||
@ -378,10 +378,6 @@ ko:
|
||||
label_dmsf_attachments: DMS 첨부
|
||||
label_basic_attachments: 기본 첨부
|
||||
|
||||
label_tmpdir: 임시 파일 경로
|
||||
error_file_tmpdir_does_not_exist: "임시 파일 경로가 존재하지 않거나 만들 수 없습니다"
|
||||
error_tmpfile_can_not_be_created: "임시 파일 경로 디렉터리 내에 파일을 만들 수 없습니다"
|
||||
|
||||
label_email_from_override: 송신
|
||||
text_email_from_override: 로그인한 사용자
|
||||
label_email_reply_to: 회신
|
||||
|
||||
@ -378,10 +378,6 @@ nl:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ pl:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ pt-BR:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ sl:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -377,10 +377,6 @@ zh-TW:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
@ -378,10 +378,6 @@ zh:
|
||||
label_dmsf_attachments: DMS Attachments
|
||||
label_basic_attachments: Basic Attachments
|
||||
|
||||
label_tmpdir: Temporary file path
|
||||
error_file_tmpdir_does_not_exist: "Temporary file path doesn't exist and can't be created"
|
||||
error_tmpfile_can_not_be_created: "Files can't be created in temporary file path directory"
|
||||
|
||||
label_email_from_override: From
|
||||
text_email_from_override: The user currently logged in
|
||||
label_email_reply_to: Reply-to
|
||||
|
||||
1
init.rb
1
init.rb
@ -53,7 +53,6 @@ Redmine::Plugin.register :redmine_dmsf do
|
||||
'dmsf_webdav_disable_versioning' => '^\~\$|\.tmp$',
|
||||
'dmsf_keep_documents_locked' => nil,
|
||||
'dmsf_act_as_attachable' => nil,
|
||||
'dmsf_tmpdir' => Dir.tmpdir,
|
||||
'dmsf_documents_email_from' => '',
|
||||
'dmsf_documents_email_reply_to' => '',
|
||||
'dmsf_documents_email_links_only' => nil,
|
||||
|
||||
@ -30,7 +30,7 @@ module RedmineDmsf
|
||||
attr_reader :files
|
||||
|
||||
def initialize
|
||||
@temp_file = Tempfile.new(%w(dmsf_zip_ .zip), DmsfHelper.temp_dir)
|
||||
@temp_file = Tempfile.new(%w(dmsf_zip_ .zip), File.join(Rails.root, 'tmp'))
|
||||
@zip_file = ::Zip::OutputStream.open(@temp_file)
|
||||
@files = []
|
||||
@folders = []
|
||||
|
||||
@ -317,7 +317,7 @@ class DmsfControllerTest < RedmineDmsf::Test::TestCase
|
||||
end
|
||||
|
||||
def test_entries_email
|
||||
zip_file = Tempfile.new('test', DmsfHelper::temp_dir)
|
||||
zip_file = Tempfile.new('test', File.join(Rails.root, 'tmp'))
|
||||
get :entries_email, params: { id: @project1, email:
|
||||
{
|
||||
to: 'to@test.com', from: 'from@test.com', subject: 'subject', body: 'body', expired_at: '2015-01-01',
|
||||
|
||||
@ -232,9 +232,9 @@ class DmsfFileTest < RedmineDmsf::Test::UnitTest
|
||||
|
||||
def test_findn_file_by_name
|
||||
assert DmsfFile.find_file_by_name(@project1, nil, 'test.txt')
|
||||
assert_nil DmsfFile.find_file_by_name(@project1, nil, 'test.odt')
|
||||
assert_nil DmsfFile.find_file_by_name(@project1, nil, 'test.ods')
|
||||
assert DmsfFile.find_file_by_name(@issue1, nil, 'test.pdf')
|
||||
assert_nil DmsfFile.find_file_by_name(@issue1, nil, 'test.odt')
|
||||
assert_nil DmsfFile.find_file_by_name(@issue1, nil, 'test.ods')
|
||||
end
|
||||
|
||||
def test_storage_path
|
||||
|
||||
@ -56,7 +56,7 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
||||
def test_dmsf_count
|
||||
User.current = @jsmith
|
||||
hash = @project1.dmsf_count
|
||||
assert_equal 9, hash[:files]
|
||||
assert_equal 10, hash[:files]
|
||||
assert_equal 5, hash[:folders]
|
||||
end
|
||||
|
||||
@ -70,7 +70,7 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
||||
def test_copy_dmsf
|
||||
User.current = @jsmith
|
||||
|
||||
assert_equal 4, @project1.dmsf_files.visible.all.size
|
||||
assert_equal 5, @project1.dmsf_files.visible.all.size
|
||||
assert_equal 3, @project1.dmsf_folders.visible.all.size
|
||||
assert_equal 2, @project1.file_links.visible.all.size
|
||||
assert_equal 1, @project1.folder_links.visible.all.size
|
||||
@ -84,7 +84,7 @@ class ProjectPatchTest < RedmineDmsf::Test::UnitTest
|
||||
|
||||
@project3.copy_dmsf @project1
|
||||
|
||||
assert_equal 5, @project3.dmsf_files.visible.all.size
|
||||
assert_equal 6, @project3.dmsf_files.visible.all.size
|
||||
assert_equal 0, @project3.dmsf_folders.visible.all.size
|
||||
assert_equal 2, @project3.file_links.visible.all.size
|
||||
assert_equal 1, @project3.folder_links.visible.all.size
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user