WebDAV code rework
This commit is contained in:
parent
57cb656f5b
commit
2bf3fd35d0
@ -3,7 +3,7 @@
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
|
||||
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com>
|
||||
# Copyright (C) 2011-16 Karel Pičman <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
|
||||
@ -39,12 +39,12 @@ module RedmineDmsf
|
||||
@__proxy = klass
|
||||
end
|
||||
|
||||
#Overridable function to provide better listing for GET requests
|
||||
# Overridable function to provide better listing for GET requests
|
||||
def long_name
|
||||
nil
|
||||
end
|
||||
|
||||
#Overridable function to provide better listing for GET requests
|
||||
# Overridable function to provide better listing for GET requests
|
||||
def special_type
|
||||
nil
|
||||
end
|
||||
@ -59,15 +59,15 @@ module RedmineDmsf
|
||||
@public_path.force_encoding('utf-8')
|
||||
end
|
||||
|
||||
#Generate HTML for Get requests
|
||||
# Generate HTML for Get requests
|
||||
def html_display
|
||||
@response.body = ''
|
||||
Confict unless collection?
|
||||
Confict unless collection?
|
||||
entities = children.map{|child|
|
||||
DIR_FILE % [
|
||||
child.public_path,
|
||||
child.long_name || child.name,
|
||||
child.collection? ? '-' : number_to_human_size(child.content_length),
|
||||
child.collection? ? '' : number_to_human_size(child.content_length),
|
||||
child.special_type || child.content_type,
|
||||
child.last_modified
|
||||
]
|
||||
@ -75,11 +75,11 @@ module RedmineDmsf
|
||||
entities = DIR_FILE % [
|
||||
parent.public_path,
|
||||
l(:parent_directory),
|
||||
'-',
|
||||
'',
|
||||
'',
|
||||
] + entities if parent
|
||||
@response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path , entities ]
|
||||
'',
|
||||
] + entities if parent
|
||||
@response.body << index_page % [ path.empty? ? '/' : path, path.empty? ? '/' : path, entities ]
|
||||
end
|
||||
|
||||
# Run method through proxy class - ensuring always compatible child is generated
|
||||
@ -99,37 +99,43 @@ module RedmineDmsf
|
||||
return p.resource.nil? ? p : p.resource
|
||||
end
|
||||
|
||||
#Override index_page from DAV4Rack::Resource
|
||||
# Override index_page from DAV4Rack::Resource
|
||||
def index_page
|
||||
return <<-PAGE
|
||||
<html><head>
|
||||
<title>%s</title>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Index of %s</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
||||
<style type='text/css'>
|
||||
table { width:100%%; }
|
||||
.name { text-align:left; }
|
||||
.size, .mtime { text-align:right; }
|
||||
.type { width:11em; }
|
||||
.mtime { width:15em; }
|
||||
table { width:100%%; }
|
||||
.name { text-align:left; }
|
||||
.size { text-align: center; }
|
||||
.type { text-align: center; width: 11em; }
|
||||
.mtime { width:15em; }
|
||||
</style>
|
||||
</head><body>
|
||||
<h1>%s</h1>
|
||||
<hr />
|
||||
<table>
|
||||
<tr>
|
||||
<th class='name'>Name</th>
|
||||
<th class='size'>Size</th>
|
||||
<th class='type'>Type</th>
|
||||
<th class='mtime'>Last Modified</th>
|
||||
</tr>
|
||||
%s
|
||||
</table>
|
||||
<hr />
|
||||
</body></html>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Index of %s</h1>
|
||||
<hr/>
|
||||
<table>
|
||||
<tr>
|
||||
<th class='name'>Name</th>
|
||||
<th class='size'>Size</th>
|
||||
<th class='type'>Type</th>
|
||||
<th class='mtime'>Last Modified</th>
|
||||
</tr>
|
||||
%s
|
||||
</table>
|
||||
<hr/>
|
||||
</body>
|
||||
</html>
|
||||
PAGE
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def basename
|
||||
File.basename(path)
|
||||
end
|
||||
@ -163,4 +169,4 @@ table { width:100%%; }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -46,14 +46,16 @@ module RedmineDmsf
|
||||
# Our already quite heavy usage of DB would just get silly every time we called
|
||||
# this method.
|
||||
def children
|
||||
return @children if @children
|
||||
@children = []
|
||||
return [] unless collection?
|
||||
folder.subfolders.visible.map do |p|
|
||||
@children.push child(p.title)
|
||||
end
|
||||
folder.files.visible.map do |p|
|
||||
@children.push child(p.name)
|
||||
unless @childern
|
||||
@children = []
|
||||
if collection?
|
||||
folder.subfolders.visible.map do |p|
|
||||
@children.push child(p.title)
|
||||
end
|
||||
folder.files.visible.map do |p|
|
||||
@children.push child(p.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@children
|
||||
end
|
||||
@ -97,7 +99,7 @@ module RedmineDmsf
|
||||
|
||||
# Check if current entity exists as a file (DmsfFile), and returns corresponding object if found (nil otherwise)
|
||||
# Currently has a dual search approach (depending on if parent can be determined)
|
||||
def file
|
||||
def file
|
||||
unless @file
|
||||
return nil unless project # Again if entity project is nil, it cannot exist in context of this object
|
||||
# Hunt for files parent path
|
||||
|
||||
@ -50,4 +50,4 @@ module RedmineDmsf
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -3,7 +3,7 @@
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2012 Daniel Munn <dan.munn@munnster.co.uk>
|
||||
# Copyright (C) 2011-15 Karel Pičman <karel.picman@kontron.com>
|
||||
# Copyright (C) 2011-16 Karel Pičman <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
|
||||
@ -22,25 +22,16 @@
|
||||
module RedmineDmsf
|
||||
module Webdav
|
||||
class IndexResource < BaseResource
|
||||
|
||||
def initialize(public_path, path, request, response, options)
|
||||
super(public_path, path, request, response, options)
|
||||
end
|
||||
|
||||
|
||||
def children
|
||||
if @projects.blank?
|
||||
unless @projects
|
||||
@projects = []
|
||||
if User.current.admin?
|
||||
@projects = Project.visible.order('lft').to_a
|
||||
elsif User.current.logged? # If user is not admin, we should only show memberships relevant
|
||||
User.current.memberships.each{ |m| @projects << m.project if m.roles.detect{ |r| r.allowed_to?(:view_dmsf_folders) } }
|
||||
Project.has_module(:dmsf).where(Project.allowed_to_condition(
|
||||
User.current, :view_dmsf_folders)).order('lft').all.each do |p|
|
||||
@projects << child(p.identifier)
|
||||
end
|
||||
end
|
||||
@projects.delete_if { |node| !node.module_enabled?('dmsf') } if @projects
|
||||
return [] if @projects.blank?
|
||||
@projects.map do |p|
|
||||
child p.identifier
|
||||
end
|
||||
@projects
|
||||
end
|
||||
|
||||
def collection?
|
||||
|
||||
@ -22,24 +22,21 @@
|
||||
module RedmineDmsf
|
||||
module Webdav
|
||||
class ProjectResource < BaseResource
|
||||
|
||||
def initialize(public_path, path, request, response, options)
|
||||
super(public_path, path, request, response, options)
|
||||
end
|
||||
|
||||
def children
|
||||
#caching for repeat usage
|
||||
return @children unless @children.nil?
|
||||
return [] if project.nil? || project.id.nil?
|
||||
@children = []
|
||||
project.dmsf_folders.visible.map do |p|
|
||||
@children.push child(p.title)
|
||||
end
|
||||
project.dmsf_files.visible.map do |p|
|
||||
@children.push child(p.name)
|
||||
|
||||
def children
|
||||
unless @children
|
||||
@children = []
|
||||
if project
|
||||
project.dmsf_folders.visible.map do |p|
|
||||
@children.push child(p.title)
|
||||
end
|
||||
project.dmsf_files.visible.map do |p|
|
||||
@children.push child(p.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
@children
|
||||
end
|
||||
end
|
||||
|
||||
def exist?
|
||||
return false if (project.nil? || User.current.anonymous?)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user