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
|
# 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)
xml = Protocol::Caldav::Multistatus.new.to_xml do |x|
Protocol::Caldav::XmlBuilder.response(x, href: col_path.to_s) do
x.tag!("d:propstat") do
x.tag!("d:prop")
x.tag!("d:status", "HTTP/1.1 200 OK")
end
end
end
[207, Protocol::Caldav::Constants::DAV_HEADERS, [xml]]
end
|