From d6500cb861fb56b77f70b74efb110c0f88bafafe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 14 Apr 2015 14:44:43 +0200 Subject: [PATCH] Links to deleted documents #376 --- README.md | 11 ++++---- app/controllers/dmsf_controller.rb | 18 +++++++++---- app/controllers/dmsf_files_controller.rb | 10 +++---- app/views/dmsf/_file_trash.html.erb | 11 +++----- init.rb | 34 +++++++++++------------- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 24cc6609..358f8484 100644 --- a/README.md +++ b/README.md @@ -120,11 +120,12 @@ In the file /public/help//wiki_syntax_detailed.html, aft
  • DMSF:
      -
    • {{dmsf(17)}} (link to file with id 17)
    • -
    • {{dmsf(17,File)}} (link to file with id 17 with link text "File")
    • -
    • {{dmsf(17,File,10)}} (link to file with id 17 with link text "File" and link pointing to revision 10)
    • -
    • {{dmsff(5)}} (link to folder with id 5)
    • -
    • {{dmsff(5,Folder)}} (link to folder with id 5 with link text "Folder")
    • +
    • {{dmsf(17)}} (a link to the file with id 17)
    • +
    • {{dmsf(17, File)}} (a link to the file with id 17 with the link text "File")
    • +
    • {{dmsf(17, File, 10)}} (a link to the file with id 17 with the link text "File" and the link pointing to the revision 10)
    • +
    • {{dmsfd(17)}} (a link to the description of the file with id 17)
    • +
    • {{dmsff(5)}} (a link to the folder with id 5)
    • +
    • {{dmsff(5, Folder)}} (a link to the folder with id 5 with the link text "Folder")
    The DMSF file/revision id can be found in the link for file/revision download from within Redmine.
    The DMSF folder id can be found in the link when opening folders within Redmine. diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index d7376b59..24497ec3 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -36,7 +36,7 @@ class DmsfController < ApplicationController helper :all - def show + def show @folder_manipulation_allowed = User.current.allowed_to?(:folder_manipulation, @project) @file_manipulation_allowed = User.current.allowed_to?(:file_manipulation, @project) @file_delete_allowed = User.current.allowed_to?(:file_delete, @project) @@ -120,6 +120,12 @@ class DmsfController < ApplicationController end @locked_for_user = false else + + if @folder.deleted + render_404 + return + end + @subfolders = @folder.subfolders.visible @files = @folder.files.visible @dir_links = @folder.folder_links.visible @@ -607,12 +613,16 @@ class DmsfController < ApplicationController @folder = DmsfFolder.find params[:folder_id] if params[:folder_id].present? rescue DmsfAccessError render_403 + rescue ActiveRecord::RecordNotFound + render_404 end def find_parent @parent = DmsfFolder.visible.find params[:parent_id] if params[:parent_id].present? rescue DmsfAccessError render_403 + rescue ActiveRecord::RecordNotFound + render_404 end def copy_folder(folder) @@ -628,7 +638,5 @@ class DmsfController < ApplicationController :to, :zipped_content, :email, :cc, :subject, :zipped_content => [], :files => []) end - - - -end + +end \ No newline at end of file diff --git a/app/controllers/dmsf_files_controller.rb b/app/controllers/dmsf_files_controller.rb index c9a843ee..43a11600 100644 --- a/app/controllers/dmsf_files_controller.rb +++ b/app/controllers/dmsf_files_controller.rb @@ -37,6 +37,7 @@ class DmsfFilesController < ApplicationController @revision = @file.last_revision check_project(@revision.file) begin + raise ActionController::MissingFile if @file.deleted log_activity('downloaded') access = DmsfFileRevisionAccess.new access.user = User.current @@ -47,8 +48,7 @@ class DmsfFilesController < ApplicationController :filename => filename_for_content_disposition(@revision.name), :type => @revision.detect_content_type, :disposition => 'inline') - rescue ActionController::MissingFile => e - logger.error e.message + rescue ActionController::MissingFile render_404 end end @@ -67,6 +67,7 @@ class DmsfFilesController < ApplicationController end check_project(@revision.file) begin + raise ActionController::MissingFile if @revision.file.deleted log_activity('downloaded') access = DmsfFileRevisionAccess.new access.user = User.current @@ -77,8 +78,7 @@ class DmsfFilesController < ApplicationController :filename => filename_for_content_disposition(@revision.name), :type => @revision.detect_content_type, :disposition => 'attachment') - rescue ActionController::MissingFile => e - logger.error e.message + rescue ActionController::MissingFile render_404 end return @@ -303,7 +303,7 @@ class DmsfFilesController < ApplicationController end def find_revision - @revision = DmsfFileRevision.visible.find(params[:id]) + @revision = DmsfFileRevision.visible.find params[:id] @file = @revision.file @project = @file.project rescue ActiveRecord::RecordNotFound diff --git a/app/views/dmsf/_file_trash.html.erb b/app/views/dmsf/_file_trash.html.erb index 7023f0b2..b00d59cc 100644 --- a/app/views/dmsf/_file_trash.html.erb +++ b/app/views/dmsf/_file_trash.html.erb @@ -20,13 +20,10 @@ <%= check_box_tag(name, id, false, :title => l(:title_check_for_restore_or_delete)) %> - - <% file_download_url = url_for({:only_path => false, :controller => :dmsf_files, :action => 'show', :id => file, :download => ''}) %> - <%= link_to(h(title), - file_download_url, - :class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}", - :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version), - 'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_download_url}") %> + + <%= content_tag(:span, h(title), + :title => h(title), + :class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}") %>
    <%= h(link ? link.path : file.display_name) %>
    <%= number_to_human_size(file.last_revision.size) %> diff --git a/init.rb b/init.rb index 5097a868..bffd57bc 100644 --- a/init.rb +++ b/init.rb @@ -89,19 +89,18 @@ Redmine::Plugin.register :redmine_dmsf do # Administration menu extension Redmine::MenuManager.map :admin_menu do |menu| - menu.push :approvalworkflows, {:controller => 'dmsf_workflows', :action => 'index'}, :caption => :label_dmsf_workflow_plural + menu.push :approvalworkflows, {:controller => 'dmsf_workflows', :action => 'index'}, :caption => :label_dmsf_workflow_plural end Redmine::WikiFormatting::Macros.register do desc "Wiki link to DMSF file:\n\n" + "!{{dmsf(file_id [, title [, revision_id]])}}\n\n" + - "_file_id_ / _revision_id_ can be found in link for file/revision download." + "_file_id_ / _revision_id_ can be found in the link for file/revision download." macro :dmsf do |obj, args| - return nil if args.length < 1 # require file id - entry_id = args[0].strip - entry = DmsfFile.find(entry_id) - if entry && !entry.deleted && User.current && User.current.allowed_to?(:view_dmsf_files, entry.project) + return nil if args.length < 1 # require file id + entry = DmsfFile.visible.find_by_id args[0].strip + if entry && User.current && User.current.allowed_to?(:view_dmsf_files, entry.project) title = args[1] ? args[1] : entry.title revision = args[2] ? args[2] : '' return link_to h(title), download_revision_path(entry, revision, :only_path => false) @@ -113,14 +112,13 @@ Redmine::Plugin.register :redmine_dmsf do Redmine::WikiFormatting::Macros.register do desc "Wiki link to DMSF folder:\n\n" + "!{{dmsff(folder_id [, title])}}\n\n" + - "_folder_id_ may be missing. _folder_id_ can be found in link for folder opening." + "_folder_id_ may be missing. _folder_id_ can be found in the link for folder opening." macro :dmsff do |obj, args| if args.length < 1 - return link_to l(:link_documents), :controller => 'dmsf', :action => 'show', :id => @project, :only_path => false - else - entry_id = args[0].strip - entry = DmsfFolder.find(entry_id) + return link_to l(:link_documents), dmsf_folder_path(@project, :only_path => false) + else + entry = DmsfFolder.visible.find_by_id args[0].strip if entry && User.current && User.current.allowed_to?(:view_dmsf_folders, entry.project) title = args[1] ? args[1] : entry.title return link_to h(title), dmsf_folder_path(entry.project, :folder_id => entry, :only_path => false) @@ -132,16 +130,14 @@ Redmine::Plugin.register :redmine_dmsf do Redmine::WikiFormatting::Macros.register do desc "Wiki link to DMSF document description:\n\n" + - "{{dmsfd(file_id [, title])}}\n\n" + - "_file_id_ / _revision_id_ can be found in link for file/revision download." + "{{dmsfd(file_id)}}\n\n" + + "_file_id_ can be found in the link for file/revision download." macro :dmsfd do |obj, args| - return nil if args.length < 1 # require file id - entry_id = args[0].strip - entry = DmsfFile.find(entry_id) - if entry && !entry.deleted && User.current && User.current.allowed_to?(:view_dmsf_files, entry.project) - title = args[1] ? args[1] : entry.title - return link_to h(title), dmsf_file_path(entry, :only_path => false) + return nil if args.length < 1 # require file id + entry = DmsfFile.visible.find_by_id args[0].strip + if entry && User.current && User.current.allowed_to?(:view_dmsf_files, entry.project) + return entry.description end nil end