diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index a589590c..56976d2c 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -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) diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 824bc68b..82cba93b 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -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) diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb index b14b6c70..f693de80 100644 --- a/app/views/dmsf_files/show.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -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), diff --git a/assets/stylesheets/redmine_dmsf.css b/assets/stylesheets/redmine_dmsf.css index 08275958..ff1b515d 100644 --- a/assets/stylesheets/redmine_dmsf.css +++ b/assets/stylesheets/redmine_dmsf.css @@ -1,8 +1,8 @@ /* * Redmine plugin for Document Management System "Features" * -* Copyright (C) 2011 Vít Jonáš -* Copyright (C) 2011-16 Karel Pičman +* Copyright (C) 2011 Vit Jonas +* Copyright (C) 2011-16 Karel Picman * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/config/routes.rb b/config/routes.rb index cc7801bf..166e836d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'