Add support for supportedlock

This commit is contained in:
Brandon Robins
2017-12-26 14:47:01 -05:00
parent adc205fc16
commit d0f548d047
3 changed files with 34 additions and 6 deletions

View File

@@ -452,11 +452,11 @@ module Calligraphy
end end
def displayname def displayname
@name get_custom_property(:displayname) || @name
end end
def getcontentlanguage def getcontentlanguage
nil get_custom_property(:contentlanguage)
end end
def getcontentlength def getcontentlength
@@ -464,11 +464,12 @@ module Calligraphy
end end
def getcontenttype def getcontenttype
nil get_custom_property(:contenttype)
end end
def getetag def getetag
nil cache_key = ActiveSupport::Cache.expand_cache_key [@resource.etag, '']
"W/\"#{Digest::MD5.hexdigest(cache_key)}\""
end end
def getlastmodified def getlastmodified
@@ -480,11 +481,14 @@ module Calligraphy
end end
def resourcetype def resourcetype
'collection' 'collection' if collection?
end end
def supportedlock def supportedlock
nil exclusive_write = lockentry_hash('exclusive', 'write')
shared_write = lockentry_hash('shared', 'write')
JSON.generate [exclusive_write, shared_write]
end end
def get_custom_property(prop) def get_custom_property(prop)

View File

@@ -34,5 +34,9 @@ module Calligraphy
def extract_lock_token(if_header) def extract_lock_token(if_header)
if_header.scan(Calligraphy::LOCK_TOKEN_REGEX)&.flatten[0] if_header.scan(Calligraphy::LOCK_TOKEN_REGEX)&.flatten[0]
end end
def lockentry_hash(scope, type)
{ lockentry: { lockscope: scope, locktype: type } }
end
end end
end end

View File

@@ -101,6 +101,24 @@ module Calligraphy::XML
xml.status status_message status xml.status status_message status
end end
def supportedlock(xml, property)
children = JSON.parse property.text, symbolize_names: true
xml[@dav_ns].supportedlock do
children.each do |child|
xml[@dav_ns].lockentry do
xml[@dav_ns].lockscope do
xml.text child[:lockentry][:lockscope]
end
xml[@dav_ns].locktype do
xml.text child[:lockentry][:locktype]
end
end
end
end
end
# NOTE: `xml[@dav_ns].send timeout` results in Timeout being called, so # NOTE: `xml[@dav_ns].send timeout` results in Timeout being called, so
# we have this timeout method for convenience # we have this timeout method for convenience
def timeout(xml, property) def timeout(xml, property)
@@ -122,6 +140,8 @@ module Calligraphy::XML
end end
elsif property.name == 'resourcetype' elsif property.name == 'resourcetype'
resourcetype xml, property resourcetype xml, property
elsif property.name == 'supportedlock'
supportedlock xml, property
elsif property.name == 'timeout' elsif property.name == 'timeout'
timeout xml, property timeout xml, property
elsif SUPPORTED_NS_TAGS.include? property.name elsif SUPPORTED_NS_TAGS.include? property.name