Updating Dav to list second level (folders / other), doesn't function in webdav client until 3rd level object functions
This commit is contained in:
parent
bf6c4e8f53
commit
fa4207dfce
@ -3,3 +3,5 @@ require 'redmine_dmsf/webdav/resource_proxy'
|
||||
require 'redmine_dmsf/webdav/base_resource'
|
||||
|
||||
require 'redmine_dmsf/webdav/index_resource'
|
||||
require 'redmine_dmsf/webdav/project_resource'
|
||||
require 'redmine_dmsf/webdav/dmsf_resource'
|
||||
|
||||
@ -1,42 +1,34 @@
|
||||
module RedmineDmsf
|
||||
module Webdav
|
||||
|
||||
class BaseResource < DAV4Rack::Resource
|
||||
|
||||
DIR_FILE = "<tr><td class=\"name\"><a href=\"%s\">%s</a></td><td class=\"size\">%s</td><td class=\"type\">%s</td><td class=\"mtime\">%s</td></tr>"
|
||||
|
||||
def initialize(public_path, path, request, response, options)
|
||||
super(public_path, path, request, response, options)
|
||||
pinfo = path.split('/').drop(1)
|
||||
if pinfo.length > 0
|
||||
@project = Project.find(pinfo.first)
|
||||
end
|
||||
end
|
||||
|
||||
def accessor=(klass)
|
||||
@__proxy = klass
|
||||
end
|
||||
|
||||
def name
|
||||
nil
|
||||
end
|
||||
|
||||
def long_name
|
||||
nil
|
||||
end
|
||||
|
||||
def special_type
|
||||
nil
|
||||
end
|
||||
|
||||
def html_display
|
||||
|
||||
@response.body = ""
|
||||
#@response.body << "<h1>HELLO WORLD</H1>"
|
||||
Confict unless collection?
|
||||
entities = children.map{|child| DIR_FILE % [child.public_path.html_safe, child.long_name || child.name, "-", child.content_type, child.last_modified]} * "\n"
|
||||
page = index_page % [ path.empty? ? "/" : path, path.empty? ? "/" : path , entities ]
|
||||
page.each_line{|l| @response.body << l}
|
||||
entities = children.map{|child| DIR_FILE % [child.public_path.html_safe, child.long_name || child.name, "-", child.special_type || child.content_type, child.last_modified]} * "\n"
|
||||
@response.body << index_page % [ path.empty? ? "/" : path, path.empty? ? "/" : path , entities ]
|
||||
end
|
||||
|
||||
def child(name)
|
||||
def child(name, options = nil)
|
||||
@__proxy.child(name)
|
||||
end
|
||||
|
||||
@ -68,6 +60,18 @@ table { width:100%%; }
|
||||
</body></html>
|
||||
PAGE
|
||||
end
|
||||
|
||||
protected
|
||||
def Project
|
||||
return @Project unless @Project.nil?
|
||||
pinfo = @path.split('/').drop(1)
|
||||
if pinfo.length > 0
|
||||
begin
|
||||
@project = Project.find(pinfo.first)
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,11 +2,18 @@ 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
|
||||
projects = Project.visible.find(:all, :order => 'lft')
|
||||
return nill if projects.nil? || projects.empty?
|
||||
projects.delete_if { |node| node.module_enabled?('dmsf').nil? }
|
||||
projects.map do |p|
|
||||
if @Projects.nil? || @Projects.empty?
|
||||
@Projects = Project.visible.find(:all, :order => 'lft')
|
||||
@Projects.delete_if { |node| node.module_enabled?('dmsf').nil? }
|
||||
end
|
||||
return nil if @Projects.nil? || @Projects.empty?
|
||||
@Projects.map do |p|
|
||||
child p.identifier
|
||||
end
|
||||
end
|
||||
@ -15,15 +22,41 @@ module RedmineDmsf
|
||||
true
|
||||
end
|
||||
|
||||
def creation_date
|
||||
Time.now
|
||||
end
|
||||
|
||||
def last_modified
|
||||
Time.now
|
||||
end
|
||||
|
||||
def last_modified=
|
||||
MethodNotAllowed
|
||||
end
|
||||
|
||||
#Index resource ALWAYS exists
|
||||
def exist?
|
||||
true
|
||||
end
|
||||
|
||||
def etag
|
||||
sprintf('%x-%x-%x', children.count, 4096, Time.now.to_i)
|
||||
end
|
||||
|
||||
def content_type
|
||||
"text/html"
|
||||
end
|
||||
|
||||
def content_length
|
||||
4096
|
||||
end
|
||||
|
||||
def get(request, response)
|
||||
html_display
|
||||
response['Content-Length'] = response.body.bytesize.to_s
|
||||
OK
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,32 +2,70 @@ 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?
|
||||
DmsfFolder.project_root_folders(self.Project).map do |p|
|
||||
child p.title, p
|
||||
end
|
||||
DmsfFile.project_root_files(self.Project).map do |p|
|
||||
child p.display_name, p
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def name
|
||||
@project.name
|
||||
self.Project.name unless self.Project.nil?
|
||||
end
|
||||
|
||||
def exist?
|
||||
!@Project.nil?
|
||||
!self.Project.nil?
|
||||
end
|
||||
|
||||
def collection?
|
||||
exist?
|
||||
end
|
||||
|
||||
def creation_date
|
||||
self.Project.created_on unless self.Project.nil?
|
||||
end
|
||||
|
||||
def last_modified
|
||||
@project.updated_on unless @project.nil?
|
||||
self.Project.updated_on unless self.Project.nil?
|
||||
end
|
||||
|
||||
def etag
|
||||
sprintf('%x-%x-%x', 0, 4096, last_modified.to_i)
|
||||
end
|
||||
|
||||
def name
|
||||
@project.identifier unless @project.nil?
|
||||
self.Project.identifier unless self.Project.nil?
|
||||
end
|
||||
|
||||
def long_name
|
||||
@project.name unless @project.nil?
|
||||
self.Project.name unless self.Project.nil?
|
||||
end
|
||||
|
||||
def content_type
|
||||
"Project" #l(:field_project)
|
||||
"inode/directory" #l(:field_project)
|
||||
end
|
||||
|
||||
def special_type
|
||||
"Project"
|
||||
end
|
||||
|
||||
def content_length
|
||||
4096
|
||||
end
|
||||
|
||||
def get(request, response)
|
||||
html_display
|
||||
response['Content-Length'] = response.body.bytesize.to_s
|
||||
OK
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -1,11 +1,7 @@
|
||||
require 'webrick/httputils'
|
||||
|
||||
module RedmineDmsf
|
||||
module Webdav
|
||||
class ResourceProxy < DAV4Rack::Resource
|
||||
|
||||
include WEBrick::HTTPUtils
|
||||
|
||||
def initialize(public_path, path, request, response, options)
|
||||
super(public_path, path, request, response, options)
|
||||
pinfo = path.split('/').drop(1)
|
||||
@ -14,6 +10,7 @@ module RedmineDmsf
|
||||
elsif (pinfo.length == 1) #This is first level, and as such, project path
|
||||
@resource_c = ProjectResource.new(public_path, path, request, response, options)
|
||||
else #We made it all the way to DMSF Data
|
||||
@resource_c = DmsfResource.new(public_path, path, request, response, options)
|
||||
end
|
||||
|
||||
@resource_c.accessor= self unless @resource_c.nil?
|
||||
@ -21,7 +18,8 @@ module RedmineDmsf
|
||||
|
||||
def authenticate(username, password)
|
||||
User.current = User.try_to_login(username, password) || nil
|
||||
!User.current.nil?
|
||||
return !User.current.anonymous? unless User.current.nil?
|
||||
return false
|
||||
end
|
||||
|
||||
def children
|
||||
@ -71,6 +69,10 @@ module RedmineDmsf
|
||||
def long_name
|
||||
@resource_c.long_name
|
||||
end
|
||||
|
||||
def special_type
|
||||
@resource_c.special_type
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user