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
@@ -1,9 +1,16 @@
1
- module Calligraphy::XML
2
- class Node
3
- attr_accessor :children, :name, :namespace, :text
1
+ # frozen_string_literal: true
2
+
3
+ module Calligraphy
4
+ module XML
5
+ # Simple XML node, used to store resource properties in Resource methods
6
+ # and later to create XML response bodies.
7
+ class Node
8
+ attr_accessor :children, :name, :namespace, :text
9
+
10
+ #:nodoc:
11
+ def initialize(node = nil)
12
+ return if node.nil?
4
13
 
5
- def initialize(node=nil)
6
- unless node.nil?
7
14
  @name = node.name
8
15
  @text = node.text unless node.text.empty?
9
16
 
@@ -11,11 +18,18 @@ module Calligraphy::XML
11
18
  @namespace = Calligraphy::XML::Namespace.new node.namespace
12
19
  end
13
20
 
14
- if node.children&.length > 0
15
- @children = node.children.map do |child|
16
- Calligraphy::XML::Node.new child
17
- end
18
- end
21
+ return unless node_has_children node
22
+
23
+ @children = []
24
+ node.children.each { |x| @children.push Calligraphy::XML::Node.new x }
25
+ end
26
+
27
+ private
28
+
29
+ def node_has_children(node)
30
+ return false if node.children.nil?
31
+
32
+ node.children.length.positive?
19
33
  end
20
34
  end
21
35
  end
@@ -1,18 +1,29 @@
1
- module Calligraphy::XML
2
- module Utils
3
- def xml_for(body:, node:)
4
- xml = Nokogiri::XML body
5
- return :bad_request unless xml.errors.empty?
1
+ # frozen_string_literal: true
6
2
 
7
- namespace = nil
8
- xml.root.namespace_definitions.each do |n|
9
- namespace = "#{n.prefix}|" if n&.href == Calligraphy::DAV_NS && !n.prefix.nil?
3
+ module Calligraphy
4
+ module XML
5
+ # Miscellaneous XML convenience methods.
6
+ module Utils
7
+ # Returns the XML for a given XML body and node/CSS selector.
8
+ def xml_for(body:, node:)
9
+ xml = Nokogiri::XML body
10
+ return :bad_request unless xml.errors.empty?
11
+
12
+ namespace = nil
13
+ xml.root.namespace_definitions.each do |n|
14
+ namespace = "#{n.prefix}|" if dav_namespace n
15
+ end
16
+
17
+ node = node.split(' ').map! { |n| namespace + n }.join(' ') if namespace
18
+
19
+ xml.css(node).children
10
20
  end
11
- namespace
12
21
 
13
- node = node.split(' ').map! { |n| namespace + n }.join(' ') if namespace
22
+ private
14
23
 
15
- xml.css(node).children
24
+ def dav_namespace(namespace)
25
+ namespace&.href == Calligraphy::DAV_NS && !namespace.prefix.nil?
26
+ end
16
27
  end
17
28
  end
18
29
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Calligraphy
4
+ module XML
5
+ # Methods to help build WebDAV elements and properties.
6
+ module WebDavElements
7
+ DAV_NS_TAGS = %w[
8
+ activelock allprop collection creationdate depth displayname error
9
+ exclusive getcontentlanguage getcontentlength getcontenttype getetag
10
+ getlastmodified href include location lockdiscovery lockentry lockinfo
11
+ lockroot lockscope locktoken locktype multistatus owner prop
12
+ propertyupdate propfind propname propstat remove response
13
+ responsedescription resourcetype set shared status supportedlock
14
+ timeout write
15
+ ].freeze
16
+
17
+ DAV_NS_METHODS = %w[resourcetype supportedlock timeout].freeze
18
+
19
+ # Build an XML response for a LOCK request.
20
+ def lock_response(activelock_properties)
21
+ build :prop do |xml|
22
+ xml.lockdiscovery do
23
+ activelock_properties.each do |properties|
24
+ xml.activelock do
25
+ iterate_and_drilldown xml, properties
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ # Build an XML response for a PROPFIND request.
33
+ def propfind_response(path, properties)
34
+ multistatus do |xml|
35
+ href xml, path
36
+ propstat xml, properties[:found], :ok
37
+ propstat xml, properties[:not_found], :not_found
38
+ end
39
+ end
40
+
41
+ # Build an XML response for a PROPPATCH request.
42
+ def proppatch_response(path, actions)
43
+ multistatus do |xml|
44
+ href xml, path
45
+ propstat xml, actions[:set]
46
+ propstat xml, actions[:remove]
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def resourcetype(xml, property)
53
+ xml[@dav_ns].resourcetype do
54
+ self_closing_tag xml, property.text if property.text == 'collection'
55
+ end
56
+ end
57
+
58
+ def supportedlock(xml, property)
59
+ children = JSON.parse property.text, symbolize_names: true
60
+
61
+ xml[@dav_ns].supportedlock do
62
+ children.each do |child|
63
+ xml[@dav_ns].lockentry do
64
+ lockscope xml, child[:lockentry][:lockscope]
65
+ locktype xml, child[:lockentry][:locktype]
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def lockscope(xml, scope)
72
+ xml[@dav_ns].lockscope do
73
+ self_closing_tag xml, scope
74
+ end
75
+ end
76
+
77
+ def locktype(xml, type)
78
+ xml[@dav_ns].locktype do
79
+ self_closing_tag xml, type
80
+ end
81
+ end
82
+
83
+ # NOTE: `xml[@dav_ns].send timeout` results in Timeout being called, so
84
+ # we have this timeout method for convenience.
85
+ def timeout(xml, property)
86
+ xml[@dav_ns].timeout do
87
+ xml.text property.text
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/base'
2
4
 
3
5
  module Calligraphy
4
6
  module Generators
7
+ # Generator used to copy Calligraphy initializer over to your application.
5
8
  class InstallGenerator < ::Rails::Generators::Base
6
9
  source_root File.expand_path('../../templates', __FILE__)
7
10
 
8
11
  desc 'Creates a Calligraphy initializer for your application'
9
12
 
13
+ #:nodoc:
10
14
  def copy_initializer
11
15
  template 'calligraphy.rb', 'config/initializers/calligraphy.rb'
12
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Calligraphy.configure do |config|
2
4
  # The HTTP actions Calligraphy uses to create mappings between WebDAV
3
5
  # HTTP verbs and URLs and WebDAV controller actions.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calligraphy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Robins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-17 00:00:00.000000000 Z
11
+ date: 2018-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,21 +27,104 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: puma
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.11.0
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.11.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.11.0
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.11.0
27
53
  - !ruby/object:Gem::Dependency
28
- name: rspec
54
+ name: rake
29
55
  requirement: !ruby/object:Gem::Requirement
30
56
  requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 12.3.0
31
60
  - - ">="
32
61
  - !ruby/object:Gem::Version
33
- version: '0'
62
+ version: 12.3.0
34
63
  type: :development
35
64
  prerelease: false
36
65
  version_requirements: !ruby/object:Gem::Requirement
37
66
  requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 12.3.0
38
70
  - - ">="
39
71
  - !ruby/object:Gem::Version
40
- version: '0'
41
- description: WebDAV framework and extension for Rails 5
72
+ version: 12.3.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: rspec-rails
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 3.7.2
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.7.2
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.7.2
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.7.2
93
+ - !ruby/object:Gem::Dependency
94
+ name: rubocop
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: 0.52.1
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: 0.52.1
107
+ - !ruby/object:Gem::Dependency
108
+ name: sqlite3
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: 1.3.13
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 1.3.13
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.13
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 1.3.13
127
+ description:
42
128
  email: brandon@onebnottwo.com
43
129
  executables: []
44
130
  extensions: []
@@ -47,30 +133,32 @@ files:
47
133
  - LICENSE
48
134
  - README.md
49
135
  - lib/calligraphy.rb
50
- - lib/calligraphy/copy.rb
51
- - lib/calligraphy/delete.rb
52
- - lib/calligraphy/get.rb
53
- - lib/calligraphy/lock.rb
54
- - lib/calligraphy/mkcol.rb
55
- - lib/calligraphy/move.rb
56
- - lib/calligraphy/propfind.rb
57
- - lib/calligraphy/proppatch.rb
58
- - lib/calligraphy/put.rb
59
136
  - lib/calligraphy/rails/mapper.rb
137
+ - lib/calligraphy/rails/web_dav_methods.rb
138
+ - lib/calligraphy/rails/web_dav_preconditions.rb
60
139
  - lib/calligraphy/rails/web_dav_requests_controller.rb
61
140
  - lib/calligraphy/resource/file_resource.rb
62
141
  - lib/calligraphy/resource/resource.rb
63
- - lib/calligraphy/unlock.rb
64
142
  - lib/calligraphy/utils.rb
65
143
  - lib/calligraphy/version.rb
66
- - lib/calligraphy/web_dav_request.rb
144
+ - lib/calligraphy/web_dav_request/copy.rb
145
+ - lib/calligraphy/web_dav_request/delete.rb
146
+ - lib/calligraphy/web_dav_request/get.rb
147
+ - lib/calligraphy/web_dav_request/lock.rb
148
+ - lib/calligraphy/web_dav_request/mkcol.rb
149
+ - lib/calligraphy/web_dav_request/move.rb
150
+ - lib/calligraphy/web_dav_request/propfind.rb
151
+ - lib/calligraphy/web_dav_request/proppatch.rb
152
+ - lib/calligraphy/web_dav_request/put.rb
153
+ - lib/calligraphy/web_dav_request/unlock.rb
154
+ - lib/calligraphy/web_dav_request/web_dav_request.rb
67
155
  - lib/calligraphy/xml/builder.rb
68
156
  - lib/calligraphy/xml/namespace.rb
69
157
  - lib/calligraphy/xml/node.rb
70
158
  - lib/calligraphy/xml/utils.rb
159
+ - lib/calligraphy/xml/web_dav_elements.rb
71
160
  - lib/generators/calligraphy/install_generator.rb
72
161
  - lib/generators/templates/calligraphy.rb
73
- - spec/spec_helper.rb
74
162
  homepage: http://www.github.com/eanlain/calligraphy
75
163
  licenses:
76
164
  - MIT
@@ -83,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
171
  requirements:
84
172
  - - ">="
85
173
  - !ruby/object:Gem::Version
86
- version: '0'
174
+ version: 2.3.0
87
175
  required_rubygems_version: !ruby/object:Gem::Requirement
88
176
  requirements:
89
177
  - - ">="
@@ -91,9 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
179
  version: '0'
92
180
  requirements: []
93
181
  rubyforge_project:
94
- rubygems_version: 2.6.14
182
+ rubygems_version: 2.7.3
95
183
  signing_key:
96
184
  specification_version: 4
97
185
  summary: WebDAV framework and extension for Rails 5
98
- test_files:
99
- - spec/spec_helper.rb
186
+ test_files: []
@@ -1,12 +0,0 @@
1
- module Calligraphy
2
- class Get < WebDavRequest
3
- def request(head: false)
4
- if @resource.readable?
5
- return :ok if head
6
- return :ok, @resource.read
7
- else
8
- return :not_found
9
- end
10
- end
11
- end
12
- end
@@ -1,52 +0,0 @@
1
- module Calligraphy
2
- class Lock < WebDavRequest
3
- include Calligraphy::XML::Utils
4
-
5
- def request
6
- if @resource.request_body.blank? && !@resource.locked_to_user?(@headers)
7
- lock_properties = @resource.refresh_lock
8
- elsif (@resource.locked? && @resource.lock_is_exclusive?) ||
9
- (@resource.locked_to_user?(@headers) && !xml_contains_shared_lock?)
10
- return :locked
11
- else
12
- resource_exists_beforehand = @resource.exists?
13
-
14
- xml = xml_for body: body, node: 'lockinfo'
15
- return :bad_request if xml == :bad_request
16
-
17
- lock_properties = @resource.lock xml, @headers['Depth']
18
- end
19
-
20
- builder = xml_builder
21
- xml_res = builder.lock_res lock_properties
22
-
23
- lock_token = lock_properties[-1]
24
- .select { |x| x.name == 'locktoken' }[0]
25
- .children[0]
26
- .text
27
-
28
- response.headers['Lock-Token'] = "<#{lock_token}>"
29
- set_xml_content_type
30
-
31
- if resource_exists_beforehand
32
- return :ok, xml_res
33
- else
34
- return :created, xml_res
35
- end
36
- end
37
-
38
- private
39
-
40
- def xml_contains_shared_lock?
41
- lock_type = nil
42
- xml = xml_for body: body, node: 'lockinfo'
43
- xml.each do |node|
44
- next unless node.is_a? Nokogiri::XML::Element
45
-
46
- lock_type = node.children[0].name if node.name == 'lockscope'
47
- end
48
-
49
- lock_type == 'shared'
50
- end
51
- end
52
- end