13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/async/caldav/handlers/proppatch.rb', line 13
def call(path:, body:, storage:, **)
col_path = path.ensure_trailing_slash
col = storage.get_collection(col_path.to_s)
return [404, { 'content-type' => 'text/plain' }, ['Not Found']] unless col
updates = {}
is_remove = body&.match?(/<[^>]*remove[^>]*>/m)
dn = Protocol::Caldav::Xml.(body, 'displayname')
desc = Protocol::Caldav::Xml.(body, 'calendar-description')
color = Protocol::Caldav::Xml.(body, 'calendar-color')
if is_remove
updates[:displayname] = nil if body.match?(/displayname/i) && !dn
updates[:description] = nil if body.match?(/calendar-description/i) && !desc
updates[:color] = nil if body.match?(/calendar-color/i) && !color
end
updates[:displayname] = dn if dn
updates[:description] = desc if desc
updates[:color] = color if color
storage.update_collection(col_path.to_s, updates)
response_xml = <<~XML
<d:response>
<d:href>#{Protocol::Caldav::Xml.escape(col_path.to_s)}</d:href>
<d:propstat>
<d:prop/>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
</d:response>
XML
xml = Protocol::Caldav::Multistatus.new([response_xml]).to_xml
[207, Protocol::Caldav::Constants::DAV_HEADERS, [xml]]
end
|