Webdav integration - introduced get respond page for top level. TODO: define permission denied for move / copy new folder directives until after entered project; file inclusion still outstanding
This commit is contained in:
parent
83a1613467
commit
bf6c4e8f53
@ -91,6 +91,6 @@ RedmineApp::Application.routes.draw do
|
|||||||
mount DAV4Rack::Handler.new(
|
mount DAV4Rack::Handler.new(
|
||||||
# :root => Rails.root.to_s,
|
# :root => Rails.root.to_s,
|
||||||
:root_uri_path => "/dmsf/webdav",
|
:root_uri_path => "/dmsf/webdav",
|
||||||
:resource_class => RedmineDmsf::Webdav::ResourceFactory
|
:resource_class => RedmineDmsf::Webdav::ResourceProxy,
|
||||||
), :at => "/dmsf/webdav"
|
), :at => "/dmsf/webdav"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1 +1,5 @@
|
|||||||
require 'redmine_dmsf/webdav/resource_factory'
|
require 'redmine_dmsf/webdav/resource_proxy'
|
||||||
|
|
||||||
|
require 'redmine_dmsf/webdav/base_resource'
|
||||||
|
|
||||||
|
require 'redmine_dmsf/webdav/index_resource'
|
||||||
|
|||||||
75
lib/redmine_dmsf/webdav/base_resource.rb
Normal file
75
lib/redmine_dmsf/webdav/base_resource.rb
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
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 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}
|
||||||
|
end
|
||||||
|
|
||||||
|
def child(name)
|
||||||
|
@__proxy.child(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def index_page
|
||||||
|
return <<-PAGE
|
||||||
|
<html><head>
|
||||||
|
<title>%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; }
|
||||||
|
</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>
|
||||||
|
PAGE
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
29
lib/redmine_dmsf/webdav/index_resource.rb
Normal file
29
lib/redmine_dmsf/webdav/index_resource.rb
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
module RedmineDmsf
|
||||||
|
module Webdav
|
||||||
|
class IndexResource < BaseResource
|
||||||
|
|
||||||
|
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|
|
||||||
|
child p.identifier
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
#Index resource ALWAYS exists
|
||||||
|
def exist?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(request, response)
|
||||||
|
html_display
|
||||||
|
OK
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
35
lib/redmine_dmsf/webdav/project_resource.rb
Normal file
35
lib/redmine_dmsf/webdav/project_resource.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
module RedmineDmsf
|
||||||
|
module Webdav
|
||||||
|
class ProjectResource < BaseResource
|
||||||
|
|
||||||
|
def name
|
||||||
|
@project.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def exist?
|
||||||
|
!@Project.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection?
|
||||||
|
exist?
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_modified
|
||||||
|
@project.updated_on unless @project.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
@project.identifier unless @project.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def long_name
|
||||||
|
@project.name unless @project.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
"Project" #l(:field_project)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,17 +0,0 @@
|
|||||||
module RedmineDmsf
|
|
||||||
module Webdav
|
|
||||||
class ResourceFactory < DAV4Rack::Resource
|
|
||||||
|
|
||||||
def initialize(public_path, path, request, response, options)
|
|
||||||
super(public_path, path, request, response, options)
|
|
||||||
if (path == "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def authenticate(username, password)
|
|
||||||
User.try_to_login(username, password) ? true : false
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
76
lib/redmine_dmsf/webdav/resource_proxy.rb
Normal file
76
lib/redmine_dmsf/webdav/resource_proxy.rb
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
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)
|
||||||
|
if (pinfo.length == 0) #If this is the base_path, we're at root
|
||||||
|
@resource_c = IndexResource.new(public_path, path, request, response, options)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
@resource_c.accessor= self unless @resource_c.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def authenticate(username, password)
|
||||||
|
User.current = User.try_to_login(username, password) || nil
|
||||||
|
!User.current.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def children
|
||||||
|
@resource_c.children
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection?
|
||||||
|
@resource_c.collection?
|
||||||
|
end
|
||||||
|
|
||||||
|
def exist?
|
||||||
|
@resource_c.exist?
|
||||||
|
end
|
||||||
|
|
||||||
|
def creation_date
|
||||||
|
@resource_c.creation_date
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_modified
|
||||||
|
@resource_c.last_modified
|
||||||
|
end
|
||||||
|
|
||||||
|
def last_modified=(time)
|
||||||
|
@resource_c.last_modified=(time)
|
||||||
|
end
|
||||||
|
|
||||||
|
def etag
|
||||||
|
@resource_c.etag
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
@resource_c.content_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_length
|
||||||
|
@resource_c.content_length
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(request, response)
|
||||||
|
@resource_c.get(request, response)
|
||||||
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
@resource_c.name
|
||||||
|
end
|
||||||
|
|
||||||
|
def long_name
|
||||||
|
@resource_c.long_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user