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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/lib/calligraphy.rb +23 -17
  4. data/lib/calligraphy/rails/mapper.rb +150 -142
  5. data/lib/calligraphy/rails/web_dav_methods.rb +67 -0
  6. data/lib/calligraphy/rails/web_dav_preconditions.rb +114 -0
  7. data/lib/calligraphy/rails/web_dav_requests_controller.rb +72 -180
  8. data/lib/calligraphy/resource/file_resource.rb +377 -194
  9. data/lib/calligraphy/resource/resource.rb +192 -32
  10. data/lib/calligraphy/utils.rb +23 -6
  11. data/lib/calligraphy/version.rb +3 -1
  12. data/lib/calligraphy/{copy.rb → web_dav_request/copy.rb} +13 -8
  13. data/lib/calligraphy/{delete.rb → web_dav_request/delete.rb} +6 -2
  14. data/lib/calligraphy/web_dav_request/get.rb +18 -0
  15. data/lib/calligraphy/web_dav_request/lock.rb +89 -0
  16. data/lib/calligraphy/{mkcol.rb → web_dav_request/mkcol.rb} +7 -2
  17. data/lib/calligraphy/web_dav_request/move.rb +56 -0
  18. data/lib/calligraphy/web_dav_request/propfind.rb +24 -0
  19. data/lib/calligraphy/web_dav_request/proppatch.rb +29 -0
  20. data/lib/calligraphy/web_dav_request/put.rb +16 -0
  21. data/lib/calligraphy/{unlock.rb → web_dav_request/unlock.rb} +6 -1
  22. data/lib/calligraphy/web_dav_request/web_dav_request.rb +43 -0
  23. data/lib/calligraphy/xml/builder.rb +83 -117
  24. data/lib/calligraphy/xml/namespace.rb +12 -6
  25. data/lib/calligraphy/xml/node.rb +24 -10
  26. data/lib/calligraphy/xml/utils.rb +22 -11
  27. data/lib/calligraphy/xml/web_dav_elements.rb +92 -0
  28. data/lib/generators/calligraphy/install_generator.rb +4 -0
  29. data/lib/generators/templates/calligraphy.rb +2 -0
  30. metadata +109 -22
  31. data/lib/calligraphy/get.rb +0 -12
  32. data/lib/calligraphy/lock.rb +0 -52
  33. data/lib/calligraphy/move.rb +0 -31
  34. data/lib/calligraphy/propfind.rb +0 -18
  35. data/lib/calligraphy/proppatch.rb +0 -20
  36. data/lib/calligraphy/put.rb +0 -12
  37. data/lib/calligraphy/web_dav_request.rb +0 -31
  38. data/spec/spec_helper.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3ed31ae5c1825d0054f391bd8692cde22743e792
4
- data.tar.gz: aa169279219e512a0be3d368852a9291eb1d702b
2
+ SHA256:
3
+ metadata.gz: d786f30edd4065ba7373c353c73337f67e4f0bca62645fc6a367af6878fcf252
4
+ data.tar.gz: 9e3fb9d9f5f2c84f4541aa1063fdf0a7a9da6bb210fd69c574dc75092ee79f48
5
5
  SHA512:
6
- metadata.gz: dce3ce028df7fde58126f2799efd90daf3609517abbbcd92e37a7fa1062f83d034cc15e67292b31d496e6e366af9580f1e55a2dbc36f40dc537db3f742b6f32a
7
- data.tar.gz: dd3ef30ce3a48d51a871f440eff8b40974a5e9b5292f6fb5f80699d8823e8872355c3c099405378633e2daba10d232b788112c35235fbb43ce9594449883d389
6
+ metadata.gz: b31d99b9de262e75ed85f73eeaffd2d0da9141aa0039cfbd51bd008c39a8c2897cdb050f33479d70e1d9259f160866918ddc115ca6cd90b4a057b96b20fbbcf2
7
+ data.tar.gz: 4274cbea8768e3021dda2bcc3fe0983bcdaa16fc5dcb4b0d4c34cabf01d3a4ab1f85c49b1a8ca4bc9f623f15dd00d9e3d8f9df6b4c60332284078ec8eed75151
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Calligraphy
1
+ # Calligraphy [![Build Status](https://travis-ci.org/eanlain/calligraphy.svg?branch=master)](https://travis-ci.org/eanlain/calligraphy) [![Gem Version](https://badge.fury.io/rb/calligraphy.svg)](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
 
@@ -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 = Proc.new { |username| 'changeme!' }
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 = 86400
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
- module ActionDispatch::Routing
2
- class Mapper
3
- module HttpHelpers
4
- # Define a Calligraphy route that only recognizes HTTP COPY.
5
- # copy 'bacon', to: 'food#bacon'
6
- def copy(*args, &block)
7
- args = set_web_dav_args args
8
- map_method :copy, args, &block
9
- end
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
- # Define a Calligraphy route that only recognizes HTTP HEAD.
12
- # head 'bacon', to: 'food#bacon'
13
- def head(*args, &block)
14
- args = set_web_dav_args args
15
- map_method :head, args, &block
16
- end
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
- # Define a Calligraphy route that only recognizes HTTP LOCK.
19
- # lock 'bacon', to: 'food#bacon'
20
- def lock(*args, &block)
21
- args = set_web_dav_args args
22
- map_method :lock, args, &block
23
- end
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
- # Define a Calligraphy route that only recognizes HTTP MKCOL.
26
- # mkcol 'bacon', to: 'food#bacon'
27
- def mkcol(*args, &block)
28
- args = set_web_dav_args args
29
- map_method :mkcol, args, &block
30
- end
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
- # Define a Calligraphy route that only recognizes HTTP MOVE.
33
- # move 'bacon', to: 'food#bacon'
34
- def move(*args, &block)
35
- args = set_web_dav_args args
36
- map_method :move, args, &block
37
- end
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
- # Define a Calligraphy route that only recognizes HTTP OPTIONS.
40
- # options 'bacon', to: 'food#bacon'
41
- def options(*args, &block)
42
- args = set_web_dav_args args
43
- map_method :options, args, &block
44
- end
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
- # Define a Calligraphy route that only recognizes HTTP PROPFIND.
47
- # propfind 'bacon', to: 'food#bacon'
48
- def propfind(*args, &block)
49
- args = set_web_dav_args args
50
- map_method :propfind, args, &block
51
- end
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
- # Define a Calligraphy route that only recognizes HTTP PROPPATCH.
54
- # proppatch 'bacon', to: 'food#bacon'
55
- def proppatch(*args, &block)
56
- args = set_web_dav_args args
57
- map_method :proppatch, args, &block
58
- end
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
- # Define a Calligraphy route that only recognizes HTTP UNLOCK.
61
- # unlock 'bacon', to: 'food#bacon'
62
- def unlock(*args, &block)
63
- args = set_web_dav_args args
64
- map_method :unlock, args, &block
65
- end
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
- # Define a Calligraphy route that only recognizes HTTP DELETE.
68
- # web_dav_delete 'broccoli', to: 'food#broccoli'
69
- def web_dav_delete(*args, &block)
70
- args = set_web_dav_args args
71
- map_method :delete, args, &block
72
- end
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
- # Define a Calligraphy route that only recognizes HTTP GET.
75
- # web_dav_get 'bacon', to: 'food#bacon'
76
- def web_dav_get(*args, &block)
77
- args = set_web_dav_args args
78
- map_method :get, args, &block
79
- end
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
- # Define a Calligraphy route that only recognizes HTTP PUT.
82
- # web_dav_put 'bacon', to: 'food#bacon'
83
- def web_dav_put(*args, &block)
84
- args = set_web_dav_args args
85
- map_method :put, args, &block
86
- end
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
- private
92
+ private
89
93
 
90
- def set_web_dav_args(args)
91
- options = {
92
- controller: 'calligraphy/rails/web_dav_requests',
93
- action: 'invoke_method'
94
- }
95
- [args[0], options]
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
- module Resources
100
- class Resource
101
- def web_dav_actions
102
- if @only
103
- Array(@only).map(&:to_sym)
104
- elsif @except
105
- Calligraphy.web_dav_actions - Array(@except).map(&:to_sym)
106
- else
107
- Calligraphy.web_dav_actions
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
- # With Calligraphy, a resourceful route provides mappings between WebDAV
113
- # HTTP verbs and URLs and WebDAV controller actions. A single entry in
114
- # the routing file, such as:
115
- #
116
- # calligraphy_resource :photos
117
- #
118
- # creates eleven different routes in your application, all mapping to the
119
- # WebDavRequests controller:
120
- #
121
- # OPTIONS /photos/*resource
122
- # GET /photos/*resource
123
- # PUT /photos/*resource
124
- # DELETE /photos/*resource
125
- # COPY /photos/*resource
126
- # MOVE /photos/*resource
127
- # MKCOL /photos/*resource
128
- # PROPFIND /photos/*resource
129
- # PROPPATCH /photos/*resource
130
- # LOCK /photos/*resource
131
- # UNLOCK /photos/*resource
132
- def calligraphy_resource(*resources, &block)
133
- options = resources.extract_options!.dup
134
-
135
- if apply_common_behavior_for :calligraphy_resource, resources, options, &block
136
- return self
137
- end
138
-
139
- with_scope_level(:resource) do
140
- options = apply_action_options options
141
- singleton_resoure = ActionDispatch::Routing::Mapper::SingletonResource
142
-
143
- resource_scope(singleton_resoure.new resources.pop, api_only?, @scope[:shallow], options) do
144
- yield if block_given?
145
-
146
- concerns(options[:concerns]) if options[:concerns]
147
-
148
- set_mappings_for_web_dav_resources
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
- private
154
-
155
- def set_mappings_for_web_dav_resources
156
- parent_resource.web_dav_actions.each do |action|
157
- # Rails already defines GET, PUT, and DELETE actions which we don't
158
- # want to override. Instead, we map WebDAV GET, PUT, and DELETE
159
- # HTTP actions to 'web_dav_' prefixed methods.
160
- if [:get, :put, :delete].include? action
161
- send "web_dav_#{action.to_s}", '*resource'
162
- else
163
- send action, '*resource'
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