Links to deleted documents #376

This commit is contained in:
Karel Pičman 2015-04-14 14:44:43 +02:00
parent de47a7ef36
commit d6500cb861
5 changed files with 43 additions and 41 deletions

View File

@ -120,11 +120,12 @@ In the file <redmine_root>/public/help/<language>/wiki_syntax_detailed.html, aft
<li>
DMSF:
<ul>
<li><strong>{{dmsf(17)}}</strong> (link to file with id 17)</li>
<li><strong>{{dmsf(17,File)}}</strong> (link to file with id 17 with link text "File")</li>
<li><strong>{{dmsf(17,File,10)}}</strong> (link to file with id 17 with link text "File" and link pointing to revision 10)</li>
<li><strong>{{dmsff(5)}}</strong> (link to folder with id 5)</li>
<li><strong>{{dmsff(5,Folder)}}</strong> (link to folder with id 5 with link text "Folder")</li>
<li><strong>{{dmsf(17)}}</strong> (a link to the file with id 17)</li>
<li><strong>{{dmsf(17, File)}}</strong> (a link to the file with id 17 with the link text "File")</li>
<li><strong>{{dmsf(17, File, 10)}}</strong> (a link to the file with id 17 with the link text "File" and the link pointing to the revision 10)</li>
<li><strong>{{dmsfd(17)}}</strong> (a link to the description of the file with id 17)</li>
<li><strong>{{dmsff(5)}}</strong> (a link to the folder with id 5)</li>
<li><strong>{{dmsff(5, Folder)}}</strong> (a link to the folder with id 5 with the link text "Folder")</li>
</ul>
The DMSF file/revision id can be found in the link for file/revision download from within Redmine.<br />
The DMSF folder id can be found in the link when opening folders within Redmine.

View File

@ -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

View File

@ -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

View File

@ -20,13 +20,10 @@
<td class="check"><%= check_box_tag(name, id, false,
:title => l(:title_check_for_restore_or_delete)) %></td>
<td class="title">
<% 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}") %>
<td class="title">
<%= content_tag(:span, h(title),
:title => h(title),
:class => "icon icon-file #{DmsfHelper.filetype_css(file.name)}") %>
<div class="filename" title="<%= l(:title_filename_for_download)%>"><%= h(link ? link.path : file.display_name) %></div>
</td>
<td class="size"><%= number_to_human_size(file.last_revision.size) %></td>

34
init.rb
View File

@ -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