send_file using disposition
This commit is contained in:
parent
ad277515e1
commit
6649784062
@ -60,7 +60,7 @@ class DmsfFilesController < ApplicationController
|
||||
send_file(@revision.disk_file,
|
||||
:filename => filename_for_content_disposition(@revision.formatted_name(title_format)),
|
||||
:type => @revision.detect_content_type,
|
||||
:disposition => 'inline')
|
||||
:disposition => @revision.dmsf_file.disposition)
|
||||
rescue DmsfAccessError => e
|
||||
Rails.logger.error e.message
|
||||
render_403
|
||||
@ -71,43 +71,6 @@ class DmsfFilesController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
# The download is put here to provide more clear and usable links
|
||||
if params.has_key?(:download)
|
||||
begin
|
||||
if params[:download].blank?
|
||||
@revision = @file.last_revision
|
||||
else
|
||||
@revision = DmsfFileRevision.find(params[:download].to_i)
|
||||
raise DmsfAccessError if @revision.dmsf_file != @file
|
||||
end
|
||||
check_project(@revision.dmsf_file)
|
||||
raise ActionController::MissingFile if @revision.dmsf_file.deleted?
|
||||
log_activity('downloaded')
|
||||
access = DmsfFileRevisionAccess.new
|
||||
access.user = User.current
|
||||
access.dmsf_file_revision = @revision
|
||||
access.action = DmsfFileRevisionAccess::DownloadAction
|
||||
access.save!
|
||||
member = Member.where(:user_id => User.current.id, :project_id => @file.project.id).first
|
||||
if member && !member.title_format.nil? && !member.title_format.empty?
|
||||
title_format = member.title_format
|
||||
else
|
||||
title_format = Setting.plugin_redmine_dmsf['dmsf_global_title_format']
|
||||
end
|
||||
send_file(@revision.disk_file,
|
||||
:filename => filename_for_content_disposition(@revision.formatted_name(title_format)),
|
||||
:type => @revision.detect_content_type,
|
||||
:disposition => 'attachment')
|
||||
rescue DmsfAccessError => e
|
||||
Rails.logger.error e.message
|
||||
render_403
|
||||
rescue Exception => e
|
||||
Rails.logger.error e.message
|
||||
render_404
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@revision = @file.last_revision
|
||||
@file_delete_allowed = User.current.allowed_to?(:file_delete, @project)
|
||||
@file_manipulation_allowed = User.current.allowed_to?(:file_manipulation, @project)
|
||||
|
||||
@ -420,6 +420,14 @@ class DmsfFile < ActiveRecord::Base
|
||||
self.last_revision && !!(self.last_revision.disk_filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|svg)$/i)
|
||||
end
|
||||
|
||||
def pdf?
|
||||
self.last_revision && !!(self.last_revision.disk_filename =~ /\.(pdf)$/i)
|
||||
end
|
||||
|
||||
def disposition
|
||||
(self.image? || self.pdf?) ? 'inline' : 'attachment'
|
||||
end
|
||||
|
||||
def preview(limit)
|
||||
result = 'No preview available'
|
||||
if (self.last_revision.disk_filename =~ /\.(txt|ini|diff|c|cpp|php|csv|rb|h|erb|html|css|py)$/i)
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
"$('#revision_access-#{revision.id}').toggle()",
|
||||
:title => l(:title_download_entries) %>
|
||||
<%= link_to image_tag('rev_download.png', :plugin => 'redmine_dmsf'),
|
||||
dmsf_file_path(@file, :download => revision),
|
||||
view_dmsf_file_path(@file, :download => revision),
|
||||
:title => l(:title_title_version_version_download, :title => h(revision.title), :version => revision.version) %>
|
||||
<%= link_to image_tag('rev_delete.png', :plugin => 'redmine_dmsf'),
|
||||
delete_revision_path(revision),
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Redmine plugin for Document Management System "Features"
|
||||
*
|
||||
* Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
|
||||
* Copyright (C) 2011-16 Karel Pičman <karel.picman@kontron.com>
|
||||
* Copyright (C) 2011 Vit Jonas <vit.jonas@gmail.com>
|
||||
* Copyright (C) 2011-16 Karel Picman <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
|
||||
|
||||
@ -77,8 +77,7 @@ RedmineApp::Application.routes.draw do
|
||||
post '/dmsf/files/:id/revision/create', :controller => 'dmsf_files', :action => 'create_revision'
|
||||
get '/dmsf/files/:id/revision/delete', :controller => 'dmsf_files', :action => 'delete_revision', :as => 'delete_revision'
|
||||
get '/dmsf/files/:id/download', :controller => 'dmsf_files', :action => 'show', :download => '' # Otherwise will not route nil download param
|
||||
get '/dmsf/files/:id/download/:download', :controller => 'dmsf_files', :action => 'show', :as => 'download_revision'
|
||||
get '/dmsf/files/:id/view', :controller => 'dmsf_files', :action => 'view'
|
||||
get '/dmsf/files/:id/view', :to => 'dmsf_files#view', :as => 'view_dmsf_file'
|
||||
get '/dmsf/files/:id', :controller => 'dmsf_files', :action => 'show', :as => 'dmsf_file'
|
||||
delete '/dmsf/files/:id', :controller => 'dmsf_files', :action => 'delete'
|
||||
get '/dmsf/files/:id/restore', :controller => 'dmsf_files', :action => 'restore', :as => 'restore_dmsf_file'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user