calligraphy 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/calligraphy.rb +23 -17
- data/lib/calligraphy/rails/mapper.rb +150 -142
- data/lib/calligraphy/rails/web_dav_methods.rb +67 -0
- data/lib/calligraphy/rails/web_dav_preconditions.rb +114 -0
- data/lib/calligraphy/rails/web_dav_requests_controller.rb +72 -180
- data/lib/calligraphy/resource/file_resource.rb +377 -194
- data/lib/calligraphy/resource/resource.rb +192 -32
- data/lib/calligraphy/utils.rb +23 -6
- data/lib/calligraphy/version.rb +3 -1
- data/lib/calligraphy/{copy.rb → web_dav_request/copy.rb} +13 -8
- data/lib/calligraphy/{delete.rb → web_dav_request/delete.rb} +6 -2
- data/lib/calligraphy/web_dav_request/get.rb +18 -0
- data/lib/calligraphy/web_dav_request/lock.rb +89 -0
- data/lib/calligraphy/{mkcol.rb → web_dav_request/mkcol.rb} +7 -2
- data/lib/calligraphy/web_dav_request/move.rb +56 -0
- data/lib/calligraphy/web_dav_request/propfind.rb +24 -0
- data/lib/calligraphy/web_dav_request/proppatch.rb +29 -0
- data/lib/calligraphy/web_dav_request/put.rb +16 -0
- data/lib/calligraphy/{unlock.rb → web_dav_request/unlock.rb} +6 -1
- data/lib/calligraphy/web_dav_request/web_dav_request.rb +43 -0
- data/lib/calligraphy/xml/builder.rb +83 -117
- data/lib/calligraphy/xml/namespace.rb +12 -6
- data/lib/calligraphy/xml/node.rb +24 -10
- data/lib/calligraphy/xml/utils.rb +22 -11
- data/lib/calligraphy/xml/web_dav_elements.rb +92 -0
- data/lib/generators/calligraphy/install_generator.rb +4 -0
- data/lib/generators/templates/calligraphy.rb +2 -0
- metadata +109 -22
- data/lib/calligraphy/get.rb +0 -12
- data/lib/calligraphy/lock.rb +0 -52
- data/lib/calligraphy/move.rb +0 -31
- data/lib/calligraphy/propfind.rb +0 -18
- data/lib/calligraphy/proppatch.rb +0 -20
- data/lib/calligraphy/put.rb +0 -12
- data/lib/calligraphy/web_dav_request.rb +0 -31
- data/spec/spec_helper.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d786f30edd4065ba7373c353c73337f67e4f0bca62645fc6a367af6878fcf252
|
4
|
+
data.tar.gz: 9e3fb9d9f5f2c84f4541aa1063fdf0a7a9da6bb210fd69c574dc75092ee79f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b31d99b9de262e75ed85f73eeaffd2d0da9141aa0039cfbd51bd008c39a8c2897cdb050f33479d70e1d9259f160866918ddc115ca6cd90b4a057b96b20fbbcf2
|
7
|
+
data.tar.gz: 4274cbea8768e3021dda2bcc3fe0983bcdaa16fc5dcb4b0d4c34cabf01d3a4ab1f85c49b1a8ca4bc9f623f15dd00d9e3d8f9df6b4c60332284078ec8eed75151
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Calligraphy
|
1
|
+
# Calligraphy [](https://travis-ci.org/eanlain/calligraphy) [](https://badge.fury.io/rb/calligraphy)
|
2
2
|
|
3
3
|
Calligraphy is a Web Distributed Authoring and Versioning (WebDAV) solution for Rails that:
|
4
4
|
|
data/lib/calligraphy.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'calligraphy/rails/mapper'
|
4
|
+
require 'calligraphy/rails/web_dav_methods'
|
5
|
+
require 'calligraphy/rails/web_dav_preconditions'
|
2
6
|
require 'calligraphy/rails/web_dav_requests_controller'
|
3
7
|
|
8
|
+
require 'calligraphy/xml/web_dav_elements'
|
4
9
|
require 'calligraphy/xml/builder'
|
5
10
|
require 'calligraphy/xml/namespace'
|
6
11
|
require 'calligraphy/xml/node'
|
@@ -10,18 +15,19 @@ require 'calligraphy/utils'
|
|
10
15
|
require 'calligraphy/resource/resource'
|
11
16
|
require 'calligraphy/resource/file_resource'
|
12
17
|
|
13
|
-
require 'calligraphy/web_dav_request'
|
14
|
-
require 'calligraphy/copy'
|
15
|
-
require 'calligraphy/delete'
|
16
|
-
require 'calligraphy/get'
|
17
|
-
require 'calligraphy/lock'
|
18
|
-
require 'calligraphy/mkcol'
|
19
|
-
require 'calligraphy/move'
|
20
|
-
require 'calligraphy/propfind'
|
21
|
-
require 'calligraphy/proppatch'
|
22
|
-
require 'calligraphy/put'
|
23
|
-
require 'calligraphy/unlock'
|
18
|
+
require 'calligraphy/web_dav_request/web_dav_request'
|
19
|
+
require 'calligraphy/web_dav_request/copy'
|
20
|
+
require 'calligraphy/web_dav_request/delete'
|
21
|
+
require 'calligraphy/web_dav_request/get'
|
22
|
+
require 'calligraphy/web_dav_request/lock'
|
23
|
+
require 'calligraphy/web_dav_request/mkcol'
|
24
|
+
require 'calligraphy/web_dav_request/move'
|
25
|
+
require 'calligraphy/web_dav_request/propfind'
|
26
|
+
require 'calligraphy/web_dav_request/proppatch'
|
27
|
+
require 'calligraphy/web_dav_request/put'
|
28
|
+
require 'calligraphy/web_dav_request/unlock'
|
24
29
|
|
30
|
+
#:nodoc:
|
25
31
|
module Calligraphy
|
26
32
|
# Constants used throughout Calligraphy.
|
27
33
|
DAV_NS = 'DAV:'
|
@@ -37,17 +43,17 @@ module Calligraphy
|
|
37
43
|
|
38
44
|
# HTTP methods allowed by the WebDavRequests controller.
|
39
45
|
mattr_accessor :allowed_http_methods
|
40
|
-
@@allowed_http_methods = %w
|
46
|
+
@@allowed_http_methods = %w[
|
41
47
|
options get put delete copy move
|
42
48
|
mkcol propfind proppatch lock unlock
|
43
|
-
|
49
|
+
]
|
44
50
|
|
45
51
|
# Proc responsible for returning the user's password, API key,
|
46
52
|
# or HA1 digest hash so that Rails can check user credentials.
|
47
53
|
# Should be overridden to handle your particular application's
|
48
54
|
# user and/or authentication setup.
|
49
55
|
mattr_accessor :digest_password_procedure
|
50
|
-
@@digest_password_procedure =
|
56
|
+
@@digest_password_procedure = proc { |_username| 'changeme!' }
|
51
57
|
|
52
58
|
# If Digest Authentication is enabled by default.
|
53
59
|
mattr_accessor :enable_digest_authentication
|
@@ -59,15 +65,15 @@ module Calligraphy
|
|
59
65
|
|
60
66
|
# Maximum lock lifetime in seconds.
|
61
67
|
mattr_accessor :lock_timeout_period
|
62
|
-
@@lock_timeout_period =
|
68
|
+
@@lock_timeout_period = 86_400
|
63
69
|
|
64
70
|
# The HTTP actions Calligraphy uses to create mappings between WebDAV
|
65
71
|
# HTTP verbs and URLs and WebDAV controller actions.
|
66
72
|
mattr_accessor :web_dav_actions
|
67
|
-
@@web_dav_actions = %i
|
73
|
+
@@web_dav_actions = %i[
|
68
74
|
options get put delete copy move
|
69
75
|
mkcol propfind proppatch lock unlock
|
70
|
-
|
76
|
+
]
|
71
77
|
|
72
78
|
# Default way to set up Calligraphy.
|
73
79
|
# Run `rails generate calligraphy:install` to generate a
|
@@ -1,166 +1,174 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionDispatch
|
4
|
+
module Routing
|
5
|
+
class Mapper
|
6
|
+
#:nodoc:
|
7
|
+
module HttpHelpers
|
8
|
+
# Define a Calligraphy route that only recognizes HTTP COPY.
|
9
|
+
# copy 'bacon', to: 'food#bacon'
|
10
|
+
def copy(*args, &block)
|
11
|
+
args = web_dav_args args
|
12
|
+
map_method :copy, args, &block
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
# Define a Calligraphy route that only recognizes HTTP HEAD.
|
16
|
+
# head 'bacon', to: 'food#bacon'
|
17
|
+
def head(*args, &block)
|
18
|
+
args = web_dav_args args
|
19
|
+
map_method :head, args, &block
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
# Define a Calligraphy route that only recognizes HTTP LOCK.
|
23
|
+
# lock 'bacon', to: 'food#bacon'
|
24
|
+
def lock(*args, &block)
|
25
|
+
args = web_dav_args args
|
26
|
+
map_method :lock, args, &block
|
27
|
+
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
# Define a Calligraphy route that only recognizes HTTP MKCOL.
|
30
|
+
# mkcol 'bacon', to: 'food#bacon'
|
31
|
+
def mkcol(*args, &block)
|
32
|
+
args = web_dav_args args
|
33
|
+
map_method :mkcol, args, &block
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
# Define a Calligraphy route that only recognizes HTTP MOVE.
|
37
|
+
# move 'bacon', to: 'food#bacon'
|
38
|
+
def move(*args, &block)
|
39
|
+
args = web_dav_args args
|
40
|
+
map_method :move, args, &block
|
41
|
+
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
# Define a Calligraphy route that only recognizes HTTP OPTIONS.
|
44
|
+
# options 'bacon', to: 'food#bacon'
|
45
|
+
def options(*args, &block)
|
46
|
+
args = web_dav_args args
|
47
|
+
map_method :options, args, &block
|
48
|
+
end
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
# Define a Calligraphy route that only recognizes HTTP PROPFIND.
|
51
|
+
# propfind 'bacon', to: 'food#bacon'
|
52
|
+
def propfind(*args, &block)
|
53
|
+
args = web_dav_args args
|
54
|
+
map_method :propfind, args, &block
|
55
|
+
end
|
52
56
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
# Define a Calligraphy route that only recognizes HTTP PROPPATCH.
|
58
|
+
# proppatch 'bacon', to: 'food#bacon'
|
59
|
+
def proppatch(*args, &block)
|
60
|
+
args = web_dav_args args
|
61
|
+
map_method :proppatch, args, &block
|
62
|
+
end
|
59
63
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
# Define a Calligraphy route that only recognizes HTTP UNLOCK.
|
65
|
+
# unlock 'bacon', to: 'food#bacon'
|
66
|
+
def unlock(*args, &block)
|
67
|
+
args = web_dav_args args
|
68
|
+
map_method :unlock, args, &block
|
69
|
+
end
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
# Define a Calligraphy route that only recognizes HTTP DELETE.
|
72
|
+
# web_dav_delete 'broccoli', to: 'food#broccoli'
|
73
|
+
def web_dav_delete(*args, &block)
|
74
|
+
args = web_dav_args args
|
75
|
+
map_method :delete, args, &block
|
76
|
+
end
|
73
77
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
# Define a Calligraphy route that only recognizes HTTP GET.
|
79
|
+
# web_dav_get 'bacon', to: 'food#bacon'
|
80
|
+
def web_dav_get(*args, &block)
|
81
|
+
args = web_dav_args args
|
82
|
+
map_method :get, args, &block
|
83
|
+
end
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
# Define a Calligraphy route that only recognizes HTTP PUT.
|
86
|
+
# web_dav_put 'bacon', to: 'food#bacon'
|
87
|
+
def web_dav_put(*args, &block)
|
88
|
+
args = web_dav_args args
|
89
|
+
map_method :put, args, &block
|
90
|
+
end
|
87
91
|
|
88
|
-
|
92
|
+
private
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
def web_dav_args(args)
|
95
|
+
options = {
|
96
|
+
controller: 'calligraphy/rails/web_dav_requests',
|
97
|
+
action: 'invoke_method'
|
98
|
+
}
|
99
|
+
[args[0], options]
|
100
|
+
end
|
96
101
|
end
|
97
|
-
end
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
#:nodoc:
|
104
|
+
module Resources
|
105
|
+
#:nodoc:
|
106
|
+
class Resource
|
107
|
+
# Returns the available WebDAV HTTP verbs based on Calligraphy
|
108
|
+
# configuration and Rails routing options.
|
109
|
+
def web_dav_actions
|
110
|
+
if @only
|
111
|
+
Array(@only).map(&:to_sym)
|
112
|
+
elsif @except
|
113
|
+
Calligraphy.web_dav_actions - Array(@except).map(&:to_sym)
|
114
|
+
else
|
115
|
+
Calligraphy.web_dav_actions
|
116
|
+
end
|
108
117
|
end
|
109
118
|
end
|
110
|
-
end
|
111
119
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
120
|
+
# With Calligraphy, a resourceful route provides mappings between WebDAV
|
121
|
+
# HTTP verbs and URLs and WebDAV controller actions. A single entry in
|
122
|
+
# the routing file, such as:
|
123
|
+
#
|
124
|
+
# calligraphy_resource :photos
|
125
|
+
#
|
126
|
+
# creates eleven different routes in your application, all mapping to
|
127
|
+
# the WebDavRequests controller:
|
128
|
+
#
|
129
|
+
# OPTIONS /photos/*resource
|
130
|
+
# GET /photos/*resource
|
131
|
+
# PUT /photos/*resource
|
132
|
+
# DELETE /photos/*resource
|
133
|
+
# COPY /photos/*resource
|
134
|
+
# MOVE /photos/*resource
|
135
|
+
# MKCOL /photos/*resource
|
136
|
+
# PROPFIND /photos/*resource
|
137
|
+
# PROPPATCH /photos/*resource
|
138
|
+
# LOCK /photos/*resource
|
139
|
+
# UNLOCK /photos/*resource
|
140
|
+
def calligraphy_resource(*resources, &block)
|
141
|
+
options = resources.extract_options!.dup
|
142
|
+
|
143
|
+
if apply_common_behavior_for :calligraphy_resource, resources, options, &block
|
144
|
+
return self
|
145
|
+
end
|
146
|
+
|
147
|
+
with_scope_level(:resource) do
|
148
|
+
options = apply_action_options options
|
149
|
+
|
150
|
+
resource_scope(SingletonResource.new(resources.pop, api_only?, @scope[:shallow], options)) do
|
151
|
+
yield if block_given?
|
152
|
+
|
153
|
+
concerns(options[:concerns]) if options[:concerns]
|
154
|
+
|
155
|
+
set_mappings_for_web_dav_resources
|
156
|
+
end
|
149
157
|
end
|
150
158
|
end
|
151
|
-
end
|
152
159
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
160
|
+
private
|
161
|
+
|
162
|
+
def set_mappings_for_web_dav_resources
|
163
|
+
parent_resource.web_dav_actions.each do |action|
|
164
|
+
# Rails already defines GET, PUT, and DELETE actions which we don't
|
165
|
+
# want to override. Instead, we map WebDAV GET, PUT, and DELETE
|
166
|
+
# HTTP actions to 'web_dav_' prefixed methods.
|
167
|
+
if %i[get put delete].include? action
|
168
|
+
send "web_dav_#{action}", '*resource'
|
169
|
+
else
|
170
|
+
send action, '*resource'
|
171
|
+
end
|
164
172
|
end
|
165
173
|
end
|
166
174
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Calligraphy
|
4
|
+
module Rails
|
5
|
+
# Provides methods to direct the execution of WebDAV actions.
|
6
|
+
module WebDavMethods
|
7
|
+
private
|
8
|
+
|
9
|
+
def web_dav_request
|
10
|
+
{
|
11
|
+
headers: request.headers,
|
12
|
+
request: request,
|
13
|
+
resource: @resource,
|
14
|
+
response: response
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
response.headers['DAV'] = @resource.dav_compliance
|
20
|
+
|
21
|
+
:ok
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(head: false)
|
25
|
+
fresh_when(@resource, etag: @resource.etag) if @resource.readable?
|
26
|
+
|
27
|
+
Calligraphy::Get.new(web_dav_request).execute(head: head)
|
28
|
+
end
|
29
|
+
|
30
|
+
def put
|
31
|
+
Calligraphy::Put.new(web_dav_request).execute
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete
|
35
|
+
Calligraphy::Delete.new(web_dav_request).execute
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy
|
39
|
+
Calligraphy::Copy.new(web_dav_request).execute
|
40
|
+
end
|
41
|
+
|
42
|
+
def move
|
43
|
+
Calligraphy::Move.new(web_dav_request).execute
|
44
|
+
end
|
45
|
+
|
46
|
+
def mkcol
|
47
|
+
Calligraphy::Mkcol.new(web_dav_request).execute
|
48
|
+
end
|
49
|
+
|
50
|
+
def propfind
|
51
|
+
Calligraphy::Propfind.new(web_dav_request).execute
|
52
|
+
end
|
53
|
+
|
54
|
+
def proppatch
|
55
|
+
Calligraphy::Proppatch.new(web_dav_request).execute
|
56
|
+
end
|
57
|
+
|
58
|
+
def lock
|
59
|
+
Calligraphy::Lock.new(web_dav_request).execute
|
60
|
+
end
|
61
|
+
|
62
|
+
def unlock
|
63
|
+
Calligraphy::Unlock.new(web_dav_request).execute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|