railsdav 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/railsdav/renderer.rb +25 -10
- data/lib/railsdav/routing_extensions.rb +21 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9214f02f0ddee87b623b108da44fa372465f909
|
4
|
+
data.tar.gz: c73f172965f4594434f2913ad64213042f9f54a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6fb995d3fb0853b5abfa31d81328e7d4075988c583658bc5d03474080672702dc6399581cad8e08ae27d9283106723716ac63624af83536678532372c1ff17d
|
7
|
+
data.tar.gz: 605323afd1e7029366a719e56ac2867bbecf9086d3b3babcd82c1324e4033095aeb9ac97b8d207af55180664048eadbda3c3cad4cda7dee52149e84bf48f84c3
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# RailsDAV
|
2
2
|
|
3
|
-
Make your Rails 4 resources accessible via WebDAV.
|
3
|
+
Make your Rails 3/4 resources accessible via WebDAV.
|
4
4
|
|
5
|
-
This gem provides basic Rails 3 extensions for making your business
|
5
|
+
This gem provides basic Rails 3/4 extensions for making your business
|
6
6
|
resources accessible via WebDAV. This gem does by no means by no means
|
7
7
|
implement the full WebDAV semantics, but it suffices to access your
|
8
8
|
app with client(-libs) such as Konqueror, cadaver, davfs2 or NetDrive.
|
9
9
|
|
10
10
|
## Compatibility
|
11
11
|
|
12
|
-
Definitely works with Rails 3.0.9 and
|
12
|
+
Definitely works with Rails 3.0.9, 3.2.13 and 4.2.4, but should also work
|
13
13
|
with versions in between. This is due to some hacking done "under the
|
14
14
|
hood" in the Rails routing implementation as well as a simple method
|
15
15
|
override in ActionController.
|
@@ -23,7 +23,7 @@ Ensure that your project has the
|
|
23
23
|
[Rails ActionPack XML Params Parser gem](https://github.com/rails/actionpack-xml_parser)
|
24
24
|
installed, and then just add the following to your Gemfile:
|
25
25
|
|
26
|
-
gem 'railsdav'
|
26
|
+
gem 'railsdav'
|
27
27
|
|
28
28
|
and then run:
|
29
29
|
|
@@ -182,6 +182,8 @@ is_webdav_request? checks whether an Incoming request is issued by a WebDAV clie
|
|
182
182
|
|
183
183
|
## Changelog
|
184
184
|
|
185
|
+
* 0.1.0: Rails 4.2 compatibility
|
186
|
+
* 0.0.9: Add missing file to gemspec
|
185
187
|
* 0.0.8: Merge Contributions from naserca, orospakr, and rutgerg
|
186
188
|
* 0.0.7: Fix metadata class attribute inheritance problem
|
187
189
|
* 0.0.6: Fix update_all for Rails 3.2
|
data/lib/railsdav/renderer.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'builder'
|
4
4
|
|
5
|
+
if Rails.version > '4.0'
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_support/core_ext/hash/conversions'
|
8
|
+
end
|
9
|
+
|
10
|
+
|
5
11
|
module Railsdav
|
6
12
|
class Renderer
|
7
13
|
autoload :ResourceDescriptor, 'railsdav/renderer/resource_descriptor'
|
@@ -29,9 +35,9 @@ module Railsdav
|
|
29
35
|
def initialize(controller)
|
30
36
|
@controller = controller
|
31
37
|
@request = controller.request
|
32
|
-
|
38
|
+
# @depth = (@request.headers['Depth'].to_i > 0) ? 1 : 0 # depth "infinite" is not yet supported
|
33
39
|
@depth = (@request.headers['Depth'].to_i)
|
34
|
-
Rails.logger.debug "Depth
|
40
|
+
Rails.logger.debug "Depth:#{@request.headers['Depth']}"
|
35
41
|
end
|
36
42
|
|
37
43
|
# Render the requested response_type.
|
@@ -118,15 +124,22 @@ module Railsdav
|
|
118
124
|
|
119
125
|
render do |dav|
|
120
126
|
propstat_for response_collector.resource
|
121
|
-
propstat_for response_collector.subresources if @depth
|
127
|
+
propstat_for response_collector.subresources if @depth >= 0
|
122
128
|
end
|
123
129
|
end
|
124
130
|
|
125
131
|
private
|
126
132
|
|
127
133
|
def propstat_for(*resources)
|
128
|
-
params = @controller.params
|
129
|
-
params[:propfind]
|
134
|
+
params = @controller.params.dup
|
135
|
+
if params[:propfind]
|
136
|
+
# OK
|
137
|
+
elsif @controller.request.body.size > 0 # rails version without automatic XML body params parsing, so do it by hand here:
|
138
|
+
@controller.request.body.rewind
|
139
|
+
params.merge! Hash.from_xml(@controller.request.body.read)
|
140
|
+
else
|
141
|
+
params[:propfind] ||= {:prop => []}
|
142
|
+
end
|
130
143
|
|
131
144
|
if params[:propfind].has_key? 'allprop'
|
132
145
|
requested_properties = nil # fill it later, see below.
|
@@ -185,25 +198,27 @@ module Railsdav
|
|
185
198
|
|
186
199
|
# all of our built-in properties are in the DAV namespace
|
187
200
|
# anyway:
|
188
|
-
gathered_namespaces = {
|
201
|
+
gathered_namespaces = {}
|
189
202
|
@namespace_counter ||= 1
|
190
|
-
|
203
|
+
|
191
204
|
namespaced_requested_properties = {}
|
192
205
|
|
206
|
+
Rails.logger.debug requested_properties.inspect
|
193
207
|
requested_properties.each do |prop_name, opts|
|
194
208
|
if prop_name.to_s.include?(":")
|
195
209
|
# see first paragraph of big comment above
|
196
210
|
Rails.logger.warn("DAV propfind prop request contains a namespace prefix; we do NOT handle these properly yet!")
|
197
211
|
end
|
198
|
-
|
212
|
+
|
213
|
+
if (!opts.nil?) and opts["xmlns"]
|
199
214
|
gathered_namespaces["xmlns:lp#{@namespace_counter}"] = opts["xmlns"]
|
200
215
|
opts.delete("xmlns")
|
201
216
|
namespaced_requested_properties["lp#{@namespace_counter}:#{prop_name}"] = opts
|
202
217
|
@namespace_counter +=1
|
203
218
|
else
|
204
219
|
# just copy it through; however, we'll assume it's in the
|
205
|
-
# DAV namespace (which we hardcoded to the `
|
206
|
-
namespaced_requested_properties["
|
220
|
+
# DAV namespace (which we hardcoded to the `D` prefix).
|
221
|
+
namespaced_requested_properties["D:#{prop_name}"] = opts
|
207
222
|
end
|
208
223
|
end
|
209
224
|
|
@@ -4,10 +4,12 @@
|
|
4
4
|
# userinfo is not a standard webdav verb, bur davfs2 uses it
|
5
5
|
# and we want to be prepared to ignore it gracefully (e.g.
|
6
6
|
# by sending a :not_implemented response)
|
7
|
-
|
8
|
-
verbs
|
9
|
-
|
10
|
-
|
7
|
+
if Rails.version < '3.2'
|
8
|
+
verbs = %w(propfind proppatch mkcol copy move lock unlock userinfo)
|
9
|
+
verbs.each do |method|
|
10
|
+
ActionDispatch::Request::HTTP_METHODS << method.upcase
|
11
|
+
ActionDispatch::Request::HTTP_METHOD_LOOKUP[method.upcase] = method.to_sym
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
# Extend routing s.t. webdav_resource and webdav_resources can be used,
|
@@ -50,11 +52,11 @@ class ActionDispatch::Routing::Mapper
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
if Rails.version >= '4.2'
|
56
|
+
def resource_scope? #:nodoc:
|
57
|
+
@scope.resource_scope?
|
58
|
+
end
|
59
|
+
elsif Rails.version < '3.2'
|
58
60
|
# Rails versions after 3.1 expect two arguments here, the first being :resource, :resources,
|
59
61
|
# :webdav_resource etc.so we don't need the inferring logic anymore in newer versions.
|
60
62
|
def resource_scope(resource)
|
@@ -74,14 +76,24 @@ class ActionDispatch::Routing::Mapper
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
79
|
+
else
|
80
|
+
def resource_scope?
|
81
|
+
[:webdav_resource, :webdav_resources, :resource, :resources].include?(@scope[:scope_level])
|
82
|
+
end
|
77
83
|
end
|
78
84
|
|
79
85
|
def dav_options_response(*allowed_http_verbs)
|
86
|
+
Rails.logger.info "responding to OPTIONS with Allow: #{allowed_http_verbs.flatten.map{|s| s.to_s.upcase}.join(' ')}"
|
80
87
|
proc { [200, {'Allow' => allowed_http_verbs.flatten.map{|s| s.to_s.upcase}.join(' '), 'DAV' => '1'}, [' ']] }
|
81
88
|
end
|
82
89
|
|
83
90
|
def dav_match(*args)
|
84
91
|
get *args
|
92
|
+
if args.last.is_a? Hash
|
93
|
+
# prevents `Invalid route name, already in use`
|
94
|
+
args.last.delete(:as)
|
95
|
+
args.last.delete('as')
|
96
|
+
end
|
85
97
|
dav_propfind *args
|
86
98
|
end
|
87
99
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railsdav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Kerkhof
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides basic Rails 3/Rails 4 extensions for making your business resources
|
14
14
|
accessible via WebDAV. This gem does by no means by no means implement the full
|