tilia-dav 3.1.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (499) hide show
  1. checksums.yaml +7 -0
  2. data/.database.travis.yml +6 -0
  3. data/.gitignore +25 -0
  4. data/.rubocop.yml +35 -0
  5. data/.simplecov +4 -0
  6. data/.travis.yml +10 -0
  7. data/CHANGELOG.sabre.md +2084 -0
  8. data/CONTRIBUTING.md +25 -0
  9. data/Gemfile +25 -0
  10. data/Gemfile.lock +103 -0
  11. data/LICENSE +27 -0
  12. data/LICENSE.sabre +27 -0
  13. data/README.md +40 -0
  14. data/Rakefile +18 -0
  15. data/database.sample.yml +6 -0
  16. data/examples/minimal.rb +25 -0
  17. data/lib/tilia/cal_dav.rb +27 -0
  18. data/lib/tilia/cal_dav/backend.rb +17 -0
  19. data/lib/tilia/cal_dav/backend/abstract_backend.rb +194 -0
  20. data/lib/tilia/cal_dav/backend/backend_interface.rb +250 -0
  21. data/lib/tilia/cal_dav/backend/notification_support.rb +38 -0
  22. data/lib/tilia/cal_dav/backend/scheduling_support.rb +57 -0
  23. data/lib/tilia/cal_dav/backend/sequel.rb +1118 -0
  24. data/lib/tilia/cal_dav/backend/sharing_support.rb +239 -0
  25. data/lib/tilia/cal_dav/backend/subscription_support.rb +79 -0
  26. data/lib/tilia/cal_dav/backend/sync_support.rb +75 -0
  27. data/lib/tilia/cal_dav/calendar.rb +426 -0
  28. data/lib/tilia/cal_dav/calendar_home.rb +335 -0
  29. data/lib/tilia/cal_dav/calendar_object.rb +219 -0
  30. data/lib/tilia/cal_dav/calendar_query_validator.rb +294 -0
  31. data/lib/tilia/cal_dav/calendar_root.rb +57 -0
  32. data/lib/tilia/cal_dav/exception.rb +7 -0
  33. data/lib/tilia/cal_dav/exception/invalid_component_type.rb +21 -0
  34. data/lib/tilia/cal_dav/i_calendar.rb +11 -0
  35. data/lib/tilia/cal_dav/i_calendar_object.rb +13 -0
  36. data/lib/tilia/cal_dav/i_calendar_object_container.rb +32 -0
  37. data/lib/tilia/cal_dav/i_shareable_calendar.rb +40 -0
  38. data/lib/tilia/cal_dav/i_shared_calendar.rb +28 -0
  39. data/lib/tilia/cal_dav/ics_export_plugin.rb +327 -0
  40. data/lib/tilia/cal_dav/notifications.rb +12 -0
  41. data/lib/tilia/cal_dav/notifications/collection.rb +131 -0
  42. data/lib/tilia/cal_dav/notifications/i_collection.rb +17 -0
  43. data/lib/tilia/cal_dav/notifications/i_node.rb +30 -0
  44. data/lib/tilia/cal_dav/notifications/node.rb +142 -0
  45. data/lib/tilia/cal_dav/notifications/plugin.rb +138 -0
  46. data/lib/tilia/cal_dav/plugin.rb +891 -0
  47. data/lib/tilia/cal_dav/principal.rb +12 -0
  48. data/lib/tilia/cal_dav/principal/collection.rb +21 -0
  49. data/lib/tilia/cal_dav/principal/i_proxy_read.rb +13 -0
  50. data/lib/tilia/cal_dav/principal/i_proxy_write.rb +13 -0
  51. data/lib/tilia/cal_dav/principal/proxy_read.rb +127 -0
  52. data/lib/tilia/cal_dav/principal/proxy_write.rb +127 -0
  53. data/lib/tilia/cal_dav/principal/user.rb +96 -0
  54. data/lib/tilia/cal_dav/schedule.rb +14 -0
  55. data/lib/tilia/cal_dav/schedule/i_inbox.rb +12 -0
  56. data/lib/tilia/cal_dav/schedule/i_mip_plugin.rb +156 -0
  57. data/lib/tilia/cal_dav/schedule/i_outbox.rb +12 -0
  58. data/lib/tilia/cal_dav/schedule/i_scheduling_object.rb +10 -0
  59. data/lib/tilia/cal_dav/schedule/inbox.rb +211 -0
  60. data/lib/tilia/cal_dav/schedule/outbox.rb +143 -0
  61. data/lib/tilia/cal_dav/schedule/plugin.rb +851 -0
  62. data/lib/tilia/cal_dav/schedule/scheduling_object.rb +126 -0
  63. data/lib/tilia/cal_dav/shareable_calendar.rb +54 -0
  64. data/lib/tilia/cal_dav/shared_calendar.rb +120 -0
  65. data/lib/tilia/cal_dav/sharing_plugin.rb +359 -0
  66. data/lib/tilia/cal_dav/subscriptions.rb +9 -0
  67. data/lib/tilia/cal_dav/subscriptions/i_subscription.rb +37 -0
  68. data/lib/tilia/cal_dav/subscriptions/plugin.rb +83 -0
  69. data/lib/tilia/cal_dav/subscriptions/subscription.rb +205 -0
  70. data/lib/tilia/cal_dav/xml.rb +10 -0
  71. data/lib/tilia/cal_dav/xml/filter.rb +12 -0
  72. data/lib/tilia/cal_dav/xml/filter/calendar_data.rb +64 -0
  73. data/lib/tilia/cal_dav/xml/filter/comp_filter.rb +79 -0
  74. data/lib/tilia/cal_dav/xml/filter/param_filter.rb +66 -0
  75. data/lib/tilia/cal_dav/xml/filter/prop_filter.rb +80 -0
  76. data/lib/tilia/cal_dav/xml/notification.rb +13 -0
  77. data/lib/tilia/cal_dav/xml/notification/invite.rb +253 -0
  78. data/lib/tilia/cal_dav/xml/notification/invite_reply.rb +167 -0
  79. data/lib/tilia/cal_dav/xml/notification/notification_interface.rb +41 -0
  80. data/lib/tilia/cal_dav/xml/notification/system_status.rb +139 -0
  81. data/lib/tilia/cal_dav/xml/property.rb +15 -0
  82. data/lib/tilia/cal_dav/xml/property/allowed_sharing_modes.rb +64 -0
  83. data/lib/tilia/cal_dav/xml/property/email_address_set.rb +60 -0
  84. data/lib/tilia/cal_dav/xml/property/invite.rb +207 -0
  85. data/lib/tilia/cal_dav/xml/property/schedule_calendar_transp.rb +108 -0
  86. data/lib/tilia/cal_dav/xml/property/supported_calendar_component_set.rb +100 -0
  87. data/lib/tilia/cal_dav/xml/property/supported_calendar_data.rb +50 -0
  88. data/lib/tilia/cal_dav/xml/property/supported_collation_set.rb +47 -0
  89. data/lib/tilia/cal_dav/xml/request.rb +14 -0
  90. data/lib/tilia/cal_dav/xml/request/calendar_multi_get_report.rb +99 -0
  91. data/lib/tilia/cal_dav/xml/request/calendar_query_report.rb +112 -0
  92. data/lib/tilia/cal_dav/xml/request/free_busy_query_report.rb +70 -0
  93. data/lib/tilia/cal_dav/xml/request/invite_reply.rb +110 -0
  94. data/lib/tilia/cal_dav/xml/request/mk_calendar.rb +67 -0
  95. data/lib/tilia/cal_dav/xml/request/share.rb +93 -0
  96. data/lib/tilia/card_dav.rb +17 -0
  97. data/lib/tilia/card_dav/address_book.rb +338 -0
  98. data/lib/tilia/card_dav/address_book_home.rb +192 -0
  99. data/lib/tilia/card_dav/address_book_root.rb +58 -0
  100. data/lib/tilia/card_dav/backend.rb +12 -0
  101. data/lib/tilia/card_dav/backend/abstract_backend.rb +30 -0
  102. data/lib/tilia/card_dav/backend/backend_interface.rb +175 -0
  103. data/lib/tilia/card_dav/backend/sequel.rb +476 -0
  104. data/lib/tilia/card_dav/backend/sync_support.rb +80 -0
  105. data/lib/tilia/card_dav/card.rb +193 -0
  106. data/lib/tilia/card_dav/i_address_book.rb +10 -0
  107. data/lib/tilia/card_dav/i_card.rb +11 -0
  108. data/lib/tilia/card_dav/i_directory.rb +14 -0
  109. data/lib/tilia/card_dav/plugin.rb +724 -0
  110. data/lib/tilia/card_dav/vcf_export_plugin.rb +122 -0
  111. data/lib/tilia/card_dav/xml.rb +9 -0
  112. data/lib/tilia/card_dav/xml/filter.rb +11 -0
  113. data/lib/tilia/card_dav/xml/filter/address_data.rb +50 -0
  114. data/lib/tilia/card_dav/xml/filter/param_filter.rb +71 -0
  115. data/lib/tilia/card_dav/xml/filter/prop_filter.rb +77 -0
  116. data/lib/tilia/card_dav/xml/property.rb +10 -0
  117. data/lib/tilia/card_dav/xml/property/supported_address_data.rb +67 -0
  118. data/lib/tilia/card_dav/xml/property/supported_collation_set.rb +38 -0
  119. data/lib/tilia/card_dav/xml/request.rb +10 -0
  120. data/lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb +91 -0
  121. data/lib/tilia/card_dav/xml/request/address_book_query_report.rb +156 -0
  122. data/lib/tilia/dav.rb +94 -0
  123. data/lib/tilia/dav/auth.rb +8 -0
  124. data/lib/tilia/dav/auth/backend.rb +15 -0
  125. data/lib/tilia/dav/auth/backend/abstract_basic.rb +119 -0
  126. data/lib/tilia/dav/auth/backend/abstract_digest.rb +132 -0
  127. data/lib/tilia/dav/auth/backend/apache.rb +85 -0
  128. data/lib/tilia/dav/auth/backend/backend_interface.rb +61 -0
  129. data/lib/tilia/dav/auth/backend/basic_call_back.rb +46 -0
  130. data/lib/tilia/dav/auth/backend/file.rb +61 -0
  131. data/lib/tilia/dav/auth/backend/sequel.rb +46 -0
  132. data/lib/tilia/dav/auth/plugin.rb +157 -0
  133. data/lib/tilia/dav/browser.rb +12 -0
  134. data/lib/tilia/dav/browser/assets/favicon.ico +0 -0
  135. data/lib/tilia/dav/browser/assets/openiconic/ICON-LICENSE +21 -0
  136. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.css +510 -0
  137. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.eot +0 -0
  138. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.otf +0 -0
  139. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.svg +543 -0
  140. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.ttf +0 -0
  141. data/lib/tilia/dav/browser/assets/openiconic/open-iconic.woff +0 -0
  142. data/lib/tilia/dav/browser/assets/sabredav.css +228 -0
  143. data/lib/tilia/dav/browser/assets/sabredav.png +0 -0
  144. data/lib/tilia/dav/browser/guess_content_type.rb +80 -0
  145. data/lib/tilia/dav/browser/html_output.rb +27 -0
  146. data/lib/tilia/dav/browser/html_output_helper.rb +86 -0
  147. data/lib/tilia/dav/browser/map_get_to_prop_find.rb +41 -0
  148. data/lib/tilia/dav/browser/plugin.rb +693 -0
  149. data/lib/tilia/dav/browser/prop_find_all.rb +95 -0
  150. data/lib/tilia/dav/client.rb +341 -0
  151. data/lib/tilia/dav/collection.rb +79 -0
  152. data/lib/tilia/dav/core_plugin.rb +824 -0
  153. data/lib/tilia/dav/exception.rb +59 -0
  154. data/lib/tilia/dav/exception/bad_request.rb +18 -0
  155. data/lib/tilia/dav/exception/conflict.rb +18 -0
  156. data/lib/tilia/dav/exception/conflicting_lock.rb +26 -0
  157. data/lib/tilia/dav/exception/forbidden.rb +18 -0
  158. data/lib/tilia/dav/exception/insufficient_storage.rb +18 -0
  159. data/lib/tilia/dav/exception/invalid_resource_type.rb +23 -0
  160. data/lib/tilia/dav/exception/invalid_sync_token.rb +26 -0
  161. data/lib/tilia/dav/exception/length_required.rb +18 -0
  162. data/lib/tilia/dav/exception/lock_token_matches_request_uri.rb +25 -0
  163. data/lib/tilia/dav/exception/locked.rb +48 -0
  164. data/lib/tilia/dav/exception/method_not_allowed.rb +29 -0
  165. data/lib/tilia/dav/exception/not_authenticated.rb +18 -0
  166. data/lib/tilia/dav/exception/not_found.rb +18 -0
  167. data/lib/tilia/dav/exception/not_implemented.rb +18 -0
  168. data/lib/tilia/dav/exception/payment_required.rb +18 -0
  169. data/lib/tilia/dav/exception/precondition_failed.rb +47 -0
  170. data/lib/tilia/dav/exception/report_not_supported.rb +21 -0
  171. data/lib/tilia/dav/exception/requested_range_not_satisfiable.rb +18 -0
  172. data/lib/tilia/dav/exception/service_unavailable.rb +18 -0
  173. data/lib/tilia/dav/exception/too_many_matches.rb +21 -0
  174. data/lib/tilia/dav/exception/unsupported_media_type.rb +18 -0
  175. data/lib/tilia/dav/file.rb +58 -0
  176. data/lib/tilia/dav/fs.rb +9 -0
  177. data/lib/tilia/dav/fs/directory.rb +119 -0
  178. data/lib/tilia/dav/fs/file.rb +69 -0
  179. data/lib/tilia/dav/fs/node.rb +57 -0
  180. data/lib/tilia/dav/fs_ext.rb +8 -0
  181. data/lib/tilia/dav/fs_ext/directory.rb +175 -0
  182. data/lib/tilia/dav/fs_ext/file.rb +118 -0
  183. data/lib/tilia/dav/i_collection.rb +65 -0
  184. data/lib/tilia/dav/i_extended_collection.rb +36 -0
  185. data/lib/tilia/dav/i_file.rb +70 -0
  186. data/lib/tilia/dav/i_move_target.rb +37 -0
  187. data/lib/tilia/dav/i_multi_get.rb +29 -0
  188. data/lib/tilia/dav/i_node.rb +33 -0
  189. data/lib/tilia/dav/i_properties.rb +39 -0
  190. data/lib/tilia/dav/i_quota.rb +19 -0
  191. data/lib/tilia/dav/locks.rb +9 -0
  192. data/lib/tilia/dav/locks/backend.rb +12 -0
  193. data/lib/tilia/dav/locks/backend/abstract_backend.rb +16 -0
  194. data/lib/tilia/dav/locks/backend/backend_interface.rb +41 -0
  195. data/lib/tilia/dav/locks/backend/file.rb +146 -0
  196. data/lib/tilia/dav/locks/backend/sequel.rb +154 -0
  197. data/lib/tilia/dav/locks/lock_info.rb +60 -0
  198. data/lib/tilia/dav/locks/plugin.rb +467 -0
  199. data/lib/tilia/dav/mk_col.rb +47 -0
  200. data/lib/tilia/dav/mount.rb +7 -0
  201. data/lib/tilia/dav/mount/plugin.rb +62 -0
  202. data/lib/tilia/dav/node.rb +36 -0
  203. data/lib/tilia/dav/partial_update.rb +8 -0
  204. data/lib/tilia/dav/partial_update/i_patch_support.rb +40 -0
  205. data/lib/tilia/dav/partial_update/plugin.rb +179 -0
  206. data/lib/tilia/dav/prop_find.rb +262 -0
  207. data/lib/tilia/dav/prop_patch.rb +278 -0
  208. data/lib/tilia/dav/property_storage.rb +8 -0
  209. data/lib/tilia/dav/property_storage/backend.rb +10 -0
  210. data/lib/tilia/dav/property_storage/backend/backend_interface.rb +69 -0
  211. data/lib/tilia/dav/property_storage/backend/sequel.rb +192 -0
  212. data/lib/tilia/dav/property_storage/plugin.rb +131 -0
  213. data/lib/tilia/dav/server.rb +1388 -0
  214. data/lib/tilia/dav/server_plugin.rb +81 -0
  215. data/lib/tilia/dav/simple_collection.rb +71 -0
  216. data/lib/tilia/dav/simple_file.rb +82 -0
  217. data/lib/tilia/dav/string_util.rb +68 -0
  218. data/lib/tilia/dav/sync.rb +8 -0
  219. data/lib/tilia/dav/sync/i_sync_collection.rb +80 -0
  220. data/lib/tilia/dav/sync/plugin.rb +225 -0
  221. data/lib/tilia/dav/temporary_file_filter_plugin.rb +248 -0
  222. data/lib/tilia/dav/tree.rb +270 -0
  223. data/lib/tilia/dav/uuid_util.rb +45 -0
  224. data/lib/tilia/dav/version.rb +9 -0
  225. data/lib/tilia/dav/xml.rb +11 -0
  226. data/lib/tilia/dav/xml/element.rb +10 -0
  227. data/lib/tilia/dav/xml/element/prop.rb +92 -0
  228. data/lib/tilia/dav/xml/element/response.rb +188 -0
  229. data/lib/tilia/dav/xml/property.rb +16 -0
  230. data/lib/tilia/dav/xml/property/complex.rb +76 -0
  231. data/lib/tilia/dav/xml/property/get_last_modified.rb +79 -0
  232. data/lib/tilia/dav/xml/property/href.rb +137 -0
  233. data/lib/tilia/dav/xml/property/lock_discovery.rb +89 -0
  234. data/lib/tilia/dav/xml/property/resource_type.rb +96 -0
  235. data/lib/tilia/dav/xml/property/supported_lock.rb +48 -0
  236. data/lib/tilia/dav/xml/property/supported_method_set.rb +101 -0
  237. data/lib/tilia/dav/xml/property/supported_report_set.rb +118 -0
  238. data/lib/tilia/dav/xml/request.rb +13 -0
  239. data/lib/tilia/dav/xml/request/lock.rb +67 -0
  240. data/lib/tilia/dav/xml/request/mk_col.rb +69 -0
  241. data/lib/tilia/dav/xml/request/prop_find.rb +70 -0
  242. data/lib/tilia/dav/xml/request/prop_patch.rb +101 -0
  243. data/lib/tilia/dav/xml/request/sync_collection_report.rb +102 -0
  244. data/lib/tilia/dav/xml/response.rb +9 -0
  245. data/lib/tilia/dav/xml/response/multi_status.rb +108 -0
  246. data/lib/tilia/dav/xml/service.rb +42 -0
  247. data/lib/tilia/dav_acl.rb +16 -0
  248. data/lib/tilia/dav_acl/abstract_principal_collection.rb +143 -0
  249. data/lib/tilia/dav_acl/exception.rb +11 -0
  250. data/lib/tilia/dav_acl/exception/ace_conflict.rb +21 -0
  251. data/lib/tilia/dav_acl/exception/need_privileges.rb +65 -0
  252. data/lib/tilia/dav_acl/exception/no_abstract.rb +21 -0
  253. data/lib/tilia/dav_acl/exception/not_recognized_principal.rb +21 -0
  254. data/lib/tilia/dav_acl/exception/not_supported_privilege.rb +21 -0
  255. data/lib/tilia/dav_acl/fs.rb +9 -0
  256. data/lib/tilia/dav_acl/fs/collection.rb +108 -0
  257. data/lib/tilia/dav_acl/fs/file.rb +87 -0
  258. data/lib/tilia/dav_acl/fs/home_collection.rb +148 -0
  259. data/lib/tilia/dav_acl/i_acl.rb +61 -0
  260. data/lib/tilia/dav_acl/i_principal.rb +63 -0
  261. data/lib/tilia/dav_acl/i_principal_collection.rb +52 -0
  262. data/lib/tilia/dav_acl/plugin.rb +1109 -0
  263. data/lib/tilia/dav_acl/principal.rb +213 -0
  264. data/lib/tilia/dav_acl/principal_backend.rb +11 -0
  265. data/lib/tilia/dav_acl/principal_backend/abstract_backend.rb +42 -0
  266. data/lib/tilia/dav_acl/principal_backend/backend_interface.rb +127 -0
  267. data/lib/tilia/dav_acl/principal_backend/create_principal_support.rb +27 -0
  268. data/lib/tilia/dav_acl/principal_backend/sequel.rb +313 -0
  269. data/lib/tilia/dav_acl/principal_collection.rb +117 -0
  270. data/lib/tilia/dav_acl/xml.rb +8 -0
  271. data/lib/tilia/dav_acl/xml/property.rb +13 -0
  272. data/lib/tilia/dav_acl/xml/property/acl.rb +222 -0
  273. data/lib/tilia/dav_acl/xml/property/acl_restrictions.rb +40 -0
  274. data/lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb +125 -0
  275. data/lib/tilia/dav_acl/xml/property/principal.rb +149 -0
  276. data/lib/tilia/dav_acl/xml/property/supported_privilege_set.rb +135 -0
  277. data/lib/tilia/dav_acl/xml/request.rb +11 -0
  278. data/lib/tilia/dav_acl/xml/request/expand_property_report.rb +86 -0
  279. data/lib/tilia/dav_acl/xml/request/principal_property_search_report.rb +111 -0
  280. data/lib/tilia/dav_acl/xml/request/principal_search_property_set_report.rb +49 -0
  281. data/test/cal_dav/backend/abstract_sequel_test.rb +817 -0
  282. data/test/cal_dav/backend/abstract_test.rb +163 -0
  283. data/test/cal_dav/backend/mock.rb +169 -0
  284. data/test/cal_dav/backend/mock_scheduling.rb +84 -0
  285. data/test/cal_dav/backend/mock_sharing.rb +124 -0
  286. data/test/cal_dav/backend/mock_subscription_support.rb +123 -0
  287. data/test/cal_dav/backend/sequel_my_sql_test.rb +102 -0
  288. data/test/cal_dav/backend/sequel_sqlite_test.rb +105 -0
  289. data/test/cal_dav/calendar_home_notifications_test.rb +41 -0
  290. data/test/cal_dav/calendar_home_shared_calendars_test.rb +64 -0
  291. data/test/cal_dav/calendar_home_subscriptions_test.rb +67 -0
  292. data/test/cal_dav/calendar_home_test.rb +144 -0
  293. data/test/cal_dav/calendar_object_test.rb +317 -0
  294. data/test/cal_dav/calendar_query_v_alarm_test.rb +114 -0
  295. data/test/cal_dav/calendar_query_validator_test.rb +820 -0
  296. data/test/cal_dav/calendar_test.rb +203 -0
  297. data/test/cal_dav/expand_events_double_events_test.rb +94 -0
  298. data/test/cal_dav/expand_events_dtstar_tand_dten_dby_day_test.rb +94 -0
  299. data/test/cal_dav/expand_events_dtstar_tand_dtend_test.rb +100 -0
  300. data/test/cal_dav/expand_events_floating_time_test.rb +211 -0
  301. data/test/cal_dav/free_busy_report_test.rb +156 -0
  302. data/test/cal_dav/get_events_by_timerange_test.rb +74 -0
  303. data/test/cal_dav/ics_export_plugin_test.rb +638 -0
  304. data/test/cal_dav/issue166_test.rb +59 -0
  305. data/test/cal_dav/issue172_test.rb +139 -0
  306. data/test/cal_dav/issue203_test.rb +130 -0
  307. data/test/cal_dav/issue205_test.rb +89 -0
  308. data/test/cal_dav/issue211_test.rb +84 -0
  309. data/test/cal_dav/issue220_test.rb +94 -0
  310. data/test/cal_dav/issue228_test.rb +74 -0
  311. data/test/cal_dav/j_cal_transform_test.rb +244 -0
  312. data/test/cal_dav/notifications/collection_test.rb +67 -0
  313. data/test/cal_dav/notifications/node_test.rb +73 -0
  314. data/test/cal_dav/notifications/plugin_test.rb +144 -0
  315. data/test/cal_dav/plugin_test.rb +1049 -0
  316. data/test/cal_dav/principal/collection_test.rb +19 -0
  317. data/test/cal_dav/principal/proxy_read_test.rb +67 -0
  318. data/test/cal_dav/principal/proxy_write_test.rb +29 -0
  319. data/test/cal_dav/principal/user_test.rb +91 -0
  320. data/test/cal_dav/schedule/deliver_new_event_test.rb +81 -0
  321. data/test/cal_dav/schedule/free_busy_request_test.rb +565 -0
  322. data/test/cal_dav/schedule/i_mip/mock_plugin.rb +40 -0
  323. data/test/cal_dav/schedule/i_mip_plugin_test.rb +196 -0
  324. data/test/cal_dav/schedule/inbox_test.rb +150 -0
  325. data/test/cal_dav/schedule/outbox_post_test.rb +124 -0
  326. data/test/cal_dav/schedule/outbox_test.rb +76 -0
  327. data/test/cal_dav/schedule/plugin_basic_test.rb +39 -0
  328. data/test/cal_dav/schedule/plugin_properties_test.rb +96 -0
  329. data/test/cal_dav/schedule/plugin_properties_with_shared_calendar_test.rb +69 -0
  330. data/test/cal_dav/schedule/schedule_deliver_test.rb +605 -0
  331. data/test/cal_dav/schedule/scheduling_object_test.rb +327 -0
  332. data/test/cal_dav/shareable_calendar_test.rb +58 -0
  333. data/test/cal_dav/shared_calendar_test.rb +189 -0
  334. data/test/cal_dav/sharing_plugin_test.rb +373 -0
  335. data/test/cal_dav/subscriptions/create_subscription_test.rb +115 -0
  336. data/test/cal_dav/subscriptions/plugin_test.rb +46 -0
  337. data/test/cal_dav/subscriptions/subscription_test.rb +119 -0
  338. data/test/cal_dav/test_util.rb +164 -0
  339. data/test/cal_dav/validate_i_cal_test.rb +219 -0
  340. data/test/cal_dav/xml/notification/invite_reply_test.rb +136 -0
  341. data/test/cal_dav/xml/notification/invite_test.rb +225 -0
  342. data/test/cal_dav/xml/notification/system_status_test.rb +63 -0
  343. data/test/cal_dav/xml/property/allowed_sharing_modes_test.rb +34 -0
  344. data/test/cal_dav/xml/property/email_address_set_test.rb +35 -0
  345. data/test/cal_dav/xml/property/invite_test.rb +173 -0
  346. data/test/cal_dav/xml/property/schedule_calendar_transp_test.rb +96 -0
  347. data/test/cal_dav/xml/property/supported_calendar_component_set_test.rb +76 -0
  348. data/test/cal_dav/xml/property/supported_calendar_data_test.rb +32 -0
  349. data/test/cal_dav/xml/property/supported_collation_set_test.rb +33 -0
  350. data/test/cal_dav/xml/request/calendar_query_report_test.rb +339 -0
  351. data/test/cal_dav/xml/request/invite_reply_test.rb +68 -0
  352. data/test/cal_dav/xml/request/share_test.rb +79 -0
  353. data/test/card_dav/abstract_plugin_test.rb +24 -0
  354. data/test/card_dav/address_book_home_test.rb +128 -0
  355. data/test/card_dav/address_book_query_test.rb +303 -0
  356. data/test/card_dav/address_book_root_test.rb +26 -0
  357. data/test/card_dav/address_book_test.rb +166 -0
  358. data/test/card_dav/backend/abstract_sequel_test.rb +302 -0
  359. data/test/card_dav/backend/mock.rb +122 -0
  360. data/test/card_dav/backend/sequel_my_sql_test.rb +56 -0
  361. data/test/card_dav/backend/sequel_sqlite_test.rb +59 -0
  362. data/test/card_dav/card_test.rb +164 -0
  363. data/test/card_dav/i_directory_test.rb +22 -0
  364. data/test/card_dav/multi_get_test.rb +97 -0
  365. data/test/card_dav/plugin_test.rb +87 -0
  366. data/test/card_dav/sogo_strip_content_type_test.rb +63 -0
  367. data/test/card_dav/test_util.rb +51 -0
  368. data/test/card_dav/validate_filter_test.rb +210 -0
  369. data/test/card_dav/validate_v_card_test.rb +143 -0
  370. data/test/card_dav/vcf_export_test.rb +66 -0
  371. data/test/card_dav/xml/property/supported_address_data_test.rb +34 -0
  372. data/test/card_dav/xml/property/supported_collation_set_test.rb +34 -0
  373. data/test/card_dav/xml/request/address_book_query_report_test.rb +276 -0
  374. data/test/dav/abstract_server.rb +36 -0
  375. data/test/dav/auth/backend/abstract_basic_test.rb +74 -0
  376. data/test/dav/auth/backend/abstract_digest_test.rb +114 -0
  377. data/test/dav/auth/backend/abstract_sequel_test.rb +25 -0
  378. data/test/dav/auth/backend/apache_test.rb +60 -0
  379. data/test/dav/auth/backend/basic_call_back_test.rb +33 -0
  380. data/test/dav/auth/backend/file_test.rb +43 -0
  381. data/test/dav/auth/backend/mock.rb +73 -0
  382. data/test/dav/auth/backend/sequel_my_sql_test.rb +32 -0
  383. data/test/dav/auth/backend/sequel_sqlite_test.rb +21 -0
  384. data/test/dav/auth/plugin_test.rb +92 -0
  385. data/test/dav/basic_node_test.rb +143 -0
  386. data/test/dav/browser/guess_content_type_test.rb +44 -0
  387. data/test/dav/browser/map_get_to_prop_find_test.rb +37 -0
  388. data/test/dav/browser/plugin_test.rb +165 -0
  389. data/test/dav/browser/prop_find_all_test.rb +59 -0
  390. data/test/dav/client_mock.rb +24 -0
  391. data/test/dav/client_test.rb +231 -0
  392. data/test/dav/copy_test.rb +33 -0
  393. data/test/dav/exception/locked_test.rb +61 -0
  394. data/test/dav/exception/payment_required_test.rb +14 -0
  395. data/test/dav/exception/service_unavailable_test.rb +14 -0
  396. data/test/dav/exception/too_many_matches_test.rb +31 -0
  397. data/test/dav/exception_test.rb +24 -0
  398. data/test/dav/fs_ext/file_test.rb +72 -0
  399. data/test/dav/fs_ext/server_test.rb +251 -0
  400. data/test/dav/get_if_conditions_test.rb +299 -0
  401. data/test/dav/http_delete_test.rb +110 -0
  402. data/test/dav/http_get_test.rb +130 -0
  403. data/test/dav/http_head_test.rb +80 -0
  404. data/test/dav/http_move_test.rb +105 -0
  405. data/test/dav/http_prefer_parsing_test.rb +186 -0
  406. data/test/dav/http_put_test.rb +271 -0
  407. data/test/dav/issue33_test.rb +90 -0
  408. data/test/dav/locks/backend/abstract_test.rb +160 -0
  409. data/test/dav/locks/backend/file_test.rb +24 -0
  410. data/test/dav/locks/backend/mock.rb +82 -0
  411. data/test/dav/locks/backend/sequel_my_sql_test.rb +32 -0
  412. data/test/dav/locks/backend/sequel_test.rb +19 -0
  413. data/test/dav/locks/ms_word_test.rb +119 -0
  414. data/test/dav/locks/plugin2_test.rb +61 -0
  415. data/test/dav/locks/plugin_test.rb +896 -0
  416. data/test/dav/mock/collection.rb +113 -0
  417. data/test/dav/mock/file.rb +100 -0
  418. data/test/dav/mock/properties_collection.rb +80 -0
  419. data/test/dav/mock/streaming_file.rb +66 -0
  420. data/test/dav/mount/plugin_test.rb +48 -0
  421. data/test/dav/object_tree_test.rb +65 -0
  422. data/test/dav/partial_update/file_mock.rb +92 -0
  423. data/test/dav/partial_update/plugin_test.rb +125 -0
  424. data/test/dav/partial_update/specification_test.rb +77 -0
  425. data/test/dav/prop_find_test.rb +87 -0
  426. data/test/dav/prop_patch_test.rb +367 -0
  427. data/test/dav/property_storage/backend/abstract_sequel_test.rb +147 -0
  428. data/test/dav/property_storage/backend/mock.rb +96 -0
  429. data/test/dav/property_storage/backend/sequel_mysql_test.rb +32 -0
  430. data/test/dav/property_storage/backend/sequel_sqlite_test.rb +31 -0
  431. data/test/dav/property_storage/plugin_test.rb +90 -0
  432. data/test/dav/server_copy_move_test.rb +164 -0
  433. data/test/dav/server_events_test.rb +105 -0
  434. data/test/dav/server_mkcol_test.rb +337 -0
  435. data/test/dav/server_mock.rb +10 -0
  436. data/test/dav/server_plugin_test.rb +85 -0
  437. data/test/dav/server_precondition_test.rb +253 -0
  438. data/test/dav/server_props_infinite_depth_test.rb +144 -0
  439. data/test/dav/server_props_test.rb +182 -0
  440. data/test/dav/server_range_test.rb +262 -0
  441. data/test/dav/server_simple_test.rb +388 -0
  442. data/test/dav/server_update_properties_test.rb +93 -0
  443. data/test/dav/simple_file_test.rb +17 -0
  444. data/test/dav/string_util_test.rb +92 -0
  445. data/test/dav/sync/mock_sync_collection.rb +141 -0
  446. data/test/dav/sync/plugin_test.rb +491 -0
  447. data/test/dav/sync_token_property_test.rb +105 -0
  448. data/test/dav/temporary_file_filter_test.rb +179 -0
  449. data/test/dav/test_plugin.rb +24 -0
  450. data/test/dav/tree_test.rb +201 -0
  451. data/test/dav/uuid_util_test.rb +14 -0
  452. data/test/dav/xml/element/prop_test.rb +121 -0
  453. data/test/dav/xml/element/response_test.rb +202 -0
  454. data/test/dav/xml/property/href_test.rb +112 -0
  455. data/test/dav/xml/property/last_modified_test.rb +52 -0
  456. data/test/dav/xml/property/lock_discovery_test.rb +79 -0
  457. data/test/dav/xml/property/supported_method_set_test.rb +54 -0
  458. data/test/dav/xml/property/supported_report_set_test.rb +109 -0
  459. data/test/dav/xml/request/prop_find_test.rb +45 -0
  460. data/test/dav/xml/request/prop_patch_test.rb +47 -0
  461. data/test/dav/xml/request/sync_collection_test.rb +89 -0
  462. data/test/dav/xml/xml_tester.rb +35 -0
  463. data/test/dav_acl/acl_method_test.rb +299 -0
  464. data/test/dav_acl/allow_access_test.rb +94 -0
  465. data/test/dav_acl/block_access_test.rb +161 -0
  466. data/test/dav_acl/exception/ace_conflict_test.rb +33 -0
  467. data/test/dav_acl/exception/need_privileges_exception_test.rb +43 -0
  468. data/test/dav_acl/exception/no_abstract_test.rb +33 -0
  469. data/test/dav_acl/exception/not_recognized_principal_test.rb +33 -0
  470. data/test/dav_acl/exception/not_supported_privilege_test.rb +33 -0
  471. data/test/dav_acl/expand_properties_test.rb +265 -0
  472. data/test/dav_acl/fs/collection_test.rb +39 -0
  473. data/test/dav_acl/fs/file_test.rb +47 -0
  474. data/test/dav_acl/fs/home_collection_test.rb +82 -0
  475. data/test/dav_acl/mock_acl_node.rb +27 -0
  476. data/test/dav_acl/mock_principal.rb +27 -0
  477. data/test/dav_acl/plugin_admin_test.rb +60 -0
  478. data/test/dav_acl/plugin_properties_test.rb +346 -0
  479. data/test/dav_acl/plugin_update_properties_test.rb +82 -0
  480. data/test/dav_acl/principal_backend/abstract_sequel_test.rb +159 -0
  481. data/test/dav_acl/principal_backend/mock.rb +150 -0
  482. data/test/dav_acl/principal_backend/sequel_my_sql_test.rb +43 -0
  483. data/test/dav_acl/principal_backend/sequel_sqlite_test.rb +31 -0
  484. data/test/dav_acl/principal_collection_test.rb +44 -0
  485. data/test/dav_acl/principal_property_search_test.rb +354 -0
  486. data/test/dav_acl/principal_search_property_set_test.rb +125 -0
  487. data/test/dav_acl/principal_test.rb +181 -0
  488. data/test/dav_acl/simple_plugin_test.rb +320 -0
  489. data/test/dav_acl/xml/property/acl_restrictions_test.rb +28 -0
  490. data/test/dav_acl/xml/property/acl_test.rb +325 -0
  491. data/test/dav_acl/xml/property/current_user_privilege_set_test.rb +77 -0
  492. data/test/dav_acl/xml/property/principal_test.rb +158 -0
  493. data/test/dav_acl/xml/property/supported_privilege_set_test.rb +109 -0
  494. data/test/dav_server_test.rb +225 -0
  495. data/test/http/response_mock.rb +16 -0
  496. data/test/http/sapi_mock.rb +29 -0
  497. data/test/test_helper.rb +176 -0
  498. data/tilia-dav.gemspec +28 -0
  499. metadata +726 -0
@@ -0,0 +1,851 @@
1
+ module Tilia
2
+ module CalDav
3
+ module Schedule
4
+ # CalDAV scheduling plugin.
5
+ # =================
6
+ #
7
+ # This plugin provides the functionality added by the "Scheduling Extensions
8
+ # to CalDAV" standard, as defined in RFC6638.
9
+ #
10
+ # calendar-auto-schedule largely works by intercepting a users request to
11
+ # update their local calendar. If a user creates a new event with attendees,
12
+ # this plugin is supposed to grab the information from that event, and notify
13
+ # the attendees of this.
14
+ #
15
+ # There's 3 possible transports for this:
16
+ # * local delivery
17
+ # * delivery through email (iMip)
18
+ # * server-to-server delivery (iSchedule)
19
+ #
20
+ # iMip is simply, because we just need to add the iTip message as an email
21
+ # attachment. Local delivery is harder, because we both need to add this same
22
+ # message to a local DAV inbox, as well as live-update the relevant events.
23
+ #
24
+ # iSchedule is something for later.
25
+ class Plugin < Dav::ServerPlugin
26
+ # This is the official CalDAV namespace
27
+ NS_CALDAV = 'urn:ietf:params:xml:ns:caldav'
28
+
29
+ # @!attribute [r] server
30
+ # @!visibility private
31
+ # Reference to main Server object.
32
+ #
33
+ # @var Server
34
+
35
+ # Returns a list of features for the DAV: HTTP header.
36
+ #
37
+ # @return array
38
+ def features
39
+ ['calendar-auto-schedule', 'calendar-availability']
40
+ end
41
+
42
+ # Returns the name of the plugin.
43
+ #
44
+ # Using this name other plugins will be able to access other plugins
45
+ # using Server::getPlugin
46
+ #
47
+ # @return string
48
+ def plugin_name
49
+ 'caldav-schedule'
50
+ end
51
+
52
+ # Initializes the plugin
53
+ #
54
+ # @param Server server
55
+ # @return void
56
+ def setup(server)
57
+ @server = server
58
+ @server.on('method:POST', method(:http_post))
59
+ @server.on('propFind', method(:prop_find))
60
+ @server.on('propPatch', method(:prop_patch))
61
+ @server.on('calendarObjectChange', method(:calendar_object_change))
62
+ @server.on('beforeUnbind', method(:before_unbind))
63
+ @server.on('schedule', method(:schedule_local_delivery))
64
+
65
+ ns = "{#{NS_CALDAV}}"
66
+
67
+ # This information ensures that the {DAV:}resourcetype property has
68
+ # the correct values.
69
+ @server.resource_type_mapping[IOutbox] = ns + 'schedule-outbox'
70
+ @server.resource_type_mapping[IInbox] = ns + 'schedule-inbox'
71
+
72
+ # Properties we protect are made read-only by the server.
73
+ @server.protected_properties += [
74
+ ns + 'schedule-inbox-URL',
75
+ ns + 'schedule-outbox-URL',
76
+ ns + 'calendar-user-address-set',
77
+ ns + 'calendar-user-type',
78
+ ns + 'schedule-default-calendar-URL'
79
+ ]
80
+ end
81
+
82
+ # Use this method to tell the server this plugin defines additional
83
+ # HTTP methods.
84
+ #
85
+ # This method is passed a uri. It should only return HTTP methods that are
86
+ # available for the specified uri.
87
+ #
88
+ # @param string uri
89
+ # @return array
90
+ def http_methods(uri)
91
+ begin
92
+ node = @server.tree.node_for_path(uri)
93
+ rescue Dav::Exception::NotFound
94
+ return []
95
+ end
96
+
97
+ return ['POST'] if node.is_a?(IOutbox)
98
+
99
+ []
100
+ end
101
+
102
+ # This method handles POST request for the outbox.
103
+ #
104
+ # @param RequestInterface request
105
+ # @param ResponseInterface response
106
+ # @return bool
107
+ def http_post(request, response)
108
+ # Checking if this is a text/calendar content type
109
+ content_type = request.header('Content-Type') || ''
110
+
111
+ return true if content_type.index('text/calendar') != 0
112
+
113
+ path = request.path
114
+
115
+ # Checking if we're talking to an outbox
116
+ begin
117
+ node = @server.tree.node_for_path(path)
118
+ rescue Dav::Exception::NotFound
119
+ return true
120
+ end
121
+
122
+ return true unless node.is_a?(IOutbox)
123
+
124
+ @server.transaction_type = 'post-caldav-outbox'
125
+ outbox_request(node, request, response)
126
+
127
+ # Returning false breaks the event chain and tells the server we've
128
+ # handled the request.
129
+ false
130
+ end
131
+
132
+ # This method handler is invoked during fetching of properties.
133
+ #
134
+ # We use this event to add calendar-auto-schedule-specific properties.
135
+ #
136
+ # @param PropFind prop_find
137
+ # @param INode node
138
+ # @return void
139
+ def prop_find(prop_find, node)
140
+ if node.is_a?(DavAcl::IPrincipal)
141
+ caldav_plugin = @server.plugin('caldav')
142
+ principal_url = node.principal_url
143
+
144
+ # schedule-outbox-URL property
145
+ prop_find.handle(
146
+ "{#{NS_CALDAV}}schedule-outbox-URL",
147
+ lambda do
148
+ calendar_home_path = caldav_plugin.calendar_home_for_principal(principal_url)
149
+ outbox_path = calendar_home_path + '/outbox/'
150
+
151
+ return Dav::Xml::Property::Href.new(outbox_path)
152
+ end
153
+ )
154
+
155
+ # schedule-inbox-URL property
156
+ prop_find.handle(
157
+ "{#{NS_CALDAV}}schedule-inbox-URL",
158
+ lambda do
159
+ calendar_home_path = caldav_plugin.calendar_home_for_principal(principal_url)
160
+ inbox_path = calendar_home_path + '/inbox/'
161
+
162
+ return Dav::Xml::Property::Href.new(inbox_path)
163
+ end
164
+ )
165
+
166
+ prop_find.handle(
167
+ "{#{NS_CALDAV}}schedule-default-calendar-URL",
168
+ lambda do
169
+ # We don't support customizing this property yet, so in the
170
+ # meantime we just grab the first calendar in the home-set.
171
+ calendar_home_path = caldav_plugin.calendar_home_for_principal(principal_url)
172
+
173
+ sccs = "{#{NS_CALDAV}}supported-calendar-component-set"
174
+
175
+ result = @server.properties_for_path(
176
+ calendar_home_path,
177
+ [
178
+ '{DAV:}resourcetype',
179
+ sccs
180
+ ],
181
+ 1
182
+ )
183
+
184
+ result.each do |child|
185
+ if !child[200].key?('{DAV:}resourcetype') ||
186
+ !child[200]['{DAV:}resourcetype'].is("{#{NS_CALDAV}}calendar") ||
187
+ child[200]['{DAV:}resourcetype'].is('{http://calendarserver.org/ns/}shared')
188
+ # Node is either not a calendar or a shared instance.
189
+ next
190
+ end
191
+
192
+ if !child[200].key?(sccs) ||
193
+ child[200][sccs].value.include?('VEVENT')
194
+ # Either there is no supported-calendar-component-set
195
+ # (which is fine) or we found one that supports VEVENT.
196
+ return Dav::Xml::Property::Href.new(child['href'])
197
+ end
198
+ end
199
+ end
200
+ )
201
+
202
+ # The server currently reports every principal to be of type
203
+ # 'INDIVIDUAL'
204
+ prop_find.handle(
205
+ "{#{NS_CALDAV}}calendar-user-type",
206
+ -> { 'INDIVIDUAL' }
207
+ )
208
+ end
209
+
210
+ # Mapping the old property to the new property.
211
+ prop_find.handle(
212
+ '{http://calendarserver.org/ns/}calendar-availability',
213
+ lambda do
214
+ # In case it wasn't clear, the only difference is that we map the
215
+ # old property to a different namespace.
216
+ avail_prop = "{#{NS_CALDAV}}calendar-availability"
217
+ sub_prop_find = Dav::PropFind.new(
218
+ prop_find.path,
219
+ [avail_prop]
220
+ )
221
+
222
+ @server.properties_by_node(
223
+ sub_prop_find,
224
+ node
225
+ )
226
+
227
+ prop_find.set(
228
+ '{http://calendarserver.org/ns/}calendar-availability',
229
+ sub_prop_find.get(avail_prop),
230
+ sub_prop_find.status(avail_prop)
231
+ )
232
+ nil
233
+ end
234
+ )
235
+ end
236
+
237
+ # This method is called during property updates.
238
+ #
239
+ # @param string path
240
+ # @param PropPatch prop_patch
241
+ # @return void
242
+ def prop_patch(path, prop_patch)
243
+ # Mapping the old property to the new property.
244
+ prop_patch.handle(
245
+ '{http://calendarserver.org/ns/}calendar-availability',
246
+ lambda do |value|
247
+ avail_prop = "{#{NS_CALDAV}}calendar-availability"
248
+ sub_prop_patch = Dav::PropPatch.new(avail_prop => value)
249
+ @server.emit('propPatch', [path, sub_prop_patch])
250
+ sub_prop_patch.commit
251
+
252
+ return sub_prop_patch.result[avail_prop]
253
+ end
254
+ )
255
+ end
256
+
257
+ # This method is triggered whenever there was a calendar object gets
258
+ # created or updated.
259
+ #
260
+ # @param RequestInterface request HTTP request
261
+ # @param ResponseInterface response HTTP Response
262
+ # @param VCalendar v_cal Parsed iCalendar object
263
+ # @param mixed calendar_path Path to calendar collection
264
+ # @param mixed modified The iCalendar object has been touched.
265
+ # @param mixed is_new Whether this was a new item or we're updating one
266
+ # @return void
267
+ def calendar_object_change(request, _response, v_cal, calendar_path, modified, is_new)
268
+ return nil unless schedule_reply(@server.http_request)
269
+
270
+ calendar_node = @server.tree.node_for_path(calendar_path)
271
+
272
+ addresses = addresses_for_principal(calendar_node.owner)
273
+
274
+ if !is_new
275
+ node = @server.tree.node_for_path(request.path)
276
+ old_obj = VObject::Reader.read(node.get)
277
+ else
278
+ old_obj = nil
279
+ end
280
+
281
+ process_i_calendar_change(old_obj, v_cal, addresses, [], modified)
282
+
283
+ if old_obj
284
+ # Destroy circular references so PHP will GC the object.
285
+ old_obj.destroy
286
+ end
287
+ end
288
+
289
+ # This method is responsible for delivering the ITip message.
290
+ #
291
+ # @param ITip\Message itip_message
292
+ # @return void
293
+ def deliver(i_tip_message)
294
+ @server.emit('schedule', [i_tip_message])
295
+
296
+ unless i_tip_message.schedule_status
297
+ i_tip_message.schedule_status = '5.2;There was no system capable of delivering the scheduling message'
298
+ end
299
+
300
+ # In case the change was considered 'insignificant', we are going to
301
+ # remove any error statuses, if any. See ticket #525.
302
+ base_code = i_tip_message.schedule_status.split('.').first
303
+
304
+ if !i_tip_message.significant_change && ['3', '5'].include?(base_code)
305
+ i_tip_message.schedule_status = nil
306
+ end
307
+ end
308
+
309
+ # This method is triggered before a file gets deleted.
310
+ #
311
+ # We use this event to make sure that when this happens, attendees get
312
+ # cancellations, and organizers get 'DECLINED' statuses.
313
+ #
314
+ # @param string path
315
+ # @return void
316
+ def before_unbind(path)
317
+ # FIXME: We shouldn't trigger this functionality when we're issuing a
318
+ # MOVE. This is a hack.
319
+ return nil if @server.http_request.method == 'MOVE'
320
+
321
+ node = @server.tree.node_for_path(path)
322
+
323
+ return if !node.is_a?(ICalendarObject) || node.is_a?(ISchedulingObject)
324
+
325
+ return unless schedule_reply(@server.http_request)
326
+
327
+ addresses = addresses_for_principal(node.owner)
328
+
329
+ broker = VObject::ITip::Broker.new
330
+ messages = broker.parse_event(nil, addresses, node.get)
331
+
332
+ messages.each do |message|
333
+ deliver(message)
334
+ end
335
+ end
336
+
337
+ # Event handler for the 'schedule' event.
338
+ #
339
+ # This handler attempts to look at local accounts to deliver the
340
+ # scheduling object.
341
+ #
342
+ # @param ITip\Message i_tip_message
343
+ # @return void
344
+ def schedule_local_delivery(i_tip_message)
345
+ acl_plugin = @server.plugin('acl')
346
+
347
+ # Local delivery is not available if the ACL plugin is not loaded.
348
+ return nil unless acl_plugin
349
+
350
+ caldav_ns = "{#{NS_CALDAV}}"
351
+
352
+ principal_uri = acl_plugin.principal_by_uri(i_tip_message.recipient)
353
+ if principal_uri.blank?
354
+ i_tip_message.schedule_status = '3.7;Could not find principal.'
355
+ return
356
+ end
357
+
358
+ # We found a principal URL, now we need to find its inbox.
359
+ # Unfortunately we may not have sufficient privileges to find this, so
360
+ # we are temporarily turning off ACL to let this come through.
361
+ #
362
+ # Once we support PHP 5.5, this should be wrapped in a try..finally
363
+ # block so we can ensure that this privilege gets added again after.
364
+ @server.remove_listener('propFind', acl_plugin.method(:prop_find))
365
+
366
+ result = @server.properties(
367
+ principal_uri,
368
+ [
369
+ '{DAV:}principal-URL',
370
+ caldav_ns + 'calendar-home-set',
371
+ caldav_ns + 'schedule-inbox-URL',
372
+ caldav_ns + 'schedule-default-calendar-URL',
373
+ '{http://sabredav.org/ns}email-address'
374
+ ]
375
+ )
376
+
377
+ # Re-registering the ACL event
378
+ @server.on('propFind', acl_plugin.method(:prop_find), 20)
379
+
380
+ unless result.key?(caldav_ns + 'schedule-inbox-URL')
381
+ i_tip_message.schedule_status = '5.2;Could not find local inbox'
382
+ return
383
+ end
384
+ unless result.key?(caldav_ns + 'calendar-home-set')
385
+ i_tip_message.schedule_status = '5.2;Could not locate a calendar-home-set'
386
+ return
387
+ end
388
+ unless result.key?(caldav_ns + 'schedule-default-calendar-URL')
389
+ i_tip_message.schedule_status = '5.2;Could not find a schedule-default-calendar-URL property'
390
+ return
391
+ end
392
+
393
+ calendar_path = result[caldav_ns + 'schedule-default-calendar-URL'].href
394
+ home_path = result[caldav_ns + 'calendar-home-set'].href
395
+ inbox_path = result[caldav_ns + 'schedule-inbox-URL'].href
396
+
397
+ if i_tip_message.method == 'REPLY'
398
+ privilege = 'schedule-deliver-reply'
399
+ else
400
+ privilege = 'schedule-deliver-invite'
401
+ end
402
+
403
+ unless acl_plugin.check_privileges(inbox_path, caldav_ns + privilege, DavAcl::Plugin::R_PARENT, false)
404
+ i_tip_message.schedule_status = "3.8;organizer did not have the #{privilege} privilege on the attendees inbox"
405
+ return
406
+ end
407
+
408
+ # Next, we're going to find out if the item already exits in one of
409
+ # the users' calendars.
410
+ uid = i_tip_message.uid
411
+
412
+ new_file_name = 'tiliadav-' + Dav::UuidUtil.uuid + '.ics'
413
+
414
+ home = @server.tree.node_for_path(home_path)
415
+ inbox = @server.tree.node_for_path(inbox_path)
416
+
417
+ current_object = nil
418
+ object_node = nil
419
+ is_new_node = false
420
+
421
+ result = home.calendar_object_by_uid(uid)
422
+ if result
423
+ # There was an existing object, we need to update probably.
424
+ object_path = home_path + '/' + result
425
+ object_node = @server.tree.node_for_path(object_path)
426
+ old_i_calendar_data = object_node.get
427
+ current_object = VObject::Reader.read(old_i_calendar_data)
428
+ else
429
+ is_new_node = true
430
+ end
431
+
432
+ broker = VObject::ITip::Broker.new
433
+ new_object = broker.process_message(i_tip_message, current_object)
434
+
435
+ inbox.create_file(new_file_name, i_tip_message.message.serialize)
436
+
437
+ unless new_object
438
+ # We received an iTip message referring to a UID that we don't
439
+ # have in any calendars yet, and processMessage did not give us a
440
+ # calendarobject back.
441
+ #
442
+ # The implication is that processMessage did not understand the
443
+ # iTip message.
444
+ i_tip_message.schedule_status = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.'
445
+ return
446
+ end
447
+
448
+ # Note that we are bypassing ACL on purpose by calling this directly.
449
+ # We may need to look a bit deeper into this later. Supporting ACL
450
+ # here would be nice.
451
+ if is_new_node
452
+ calendar = @server.tree.node_for_path(calendar_path)
453
+ calendar.create_file(new_file_name, new_object.serialize)
454
+ else
455
+ # If the message was a reply, we may have to inform other
456
+ # attendees of this attendees status. Therefore we're shooting off
457
+ # another itipMessage.
458
+ if i_tip_message.method == 'REPLY'
459
+ process_i_calendar_change(
460
+ old_i_calendar_data,
461
+ new_object,
462
+ [i_tip_message.recipient],
463
+ [i_tip_message.sender]
464
+ )
465
+ end
466
+ object_node.put(new_object.serialize)
467
+ end
468
+ i_tip_message.schedule_status = '1.2;Message delivered locally'
469
+ end
470
+
471
+ protected
472
+
473
+ # This method looks at an old iCalendar object, a new iCalendar object and
474
+ # starts sending scheduling messages based on the changes.
475
+ #
476
+ # A list of addresses needs to be specified, so the system knows who made
477
+ # the update, because the behavior may be different based on if it's an
478
+ # attendee or an organizer.
479
+ #
480
+ # This method may update new_object to add any status changes.
481
+ #
482
+ # @param VCalendar|string old_object
483
+ # @param VCalendar new_object
484
+ # @param array addresses
485
+ # @param array ignore Any addresses to not send messages to.
486
+ # @param bool modified A marker to indicate that the original object
487
+ # modified by this process.
488
+ # @return void
489
+ def process_i_calendar_change(old_object, new_object, addresses, ignore = [], modified = Box.new(false))
490
+ broker = VObject::ITip::Broker.new
491
+ messages = broker.parse_event(new_object, addresses, old_object)
492
+
493
+ modified.value = true if messages.any?
494
+
495
+ messages.each do |message|
496
+ next if ignore.include?(message.recipient)
497
+
498
+ deliver(message)
499
+
500
+ if new_object['VEVENT'].key?('ORGANIZER') && new_object['VEVENT']['ORGANIZER'].normalized_value == message.recipient
501
+ new_object['VEVENT']['ORGANIZER']['SCHEDULE-STATUS'] = message.schedule_status if message.schedule_status
502
+ new_object['VEVENT']['ORGANIZER'].delete('SCHEDULE-FORCE-SEND')
503
+ else
504
+ if new_object['VEVENT'].key?('ATTENDEE')
505
+ new_object['VEVENT']['ATTENDEE'].each do |attendee|
506
+ next unless attendee.normalized_value == message.recipient
507
+
508
+ attendee['SCHEDULE-STATUS'] = message.schedule_status if message.schedule_status
509
+ attendee.delete('SCHEDULE-FORCE-SEND')
510
+ break
511
+ end
512
+ end
513
+ end
514
+ end
515
+ end
516
+
517
+ # Returns a list of addresses that are associated with a principal.
518
+ #
519
+ # @param string principal
520
+ # @return array
521
+ def addresses_for_principal(principal)
522
+ cuas = "{#{NS_CALDAV}}calendar-user-address-set"
523
+
524
+ properties = @server.properties(
525
+ principal,
526
+ [cuas]
527
+ )
528
+
529
+ # If we can't find this information, we'll stop processing
530
+ return [] unless properties.key?(cuas)
531
+
532
+ addresses = properties[cuas].hrefs
533
+ addresses
534
+ end
535
+
536
+ public
537
+
538
+ # This method handles POST requests to the schedule-outbox.
539
+ #
540
+ # Currently, two types of requests are support:
541
+ # * FREEBUSY requests from RFC 6638
542
+ # * Simple iTIP messages from draft-desruisseaux-caldav-sched-04
543
+ #
544
+ # The latter is from an expired early draft of the CalDAV scheduling
545
+ # extensions, but iCal depends on a feature from that spec, so we
546
+ # implement it.
547
+ #
548
+ # @param IOutbox outbox_node
549
+ # @param RequestInterface request
550
+ # @param ResponseInterface response
551
+ # @return void
552
+ def outbox_request(outbox_node, request, response)
553
+ outbox_path = request.path
554
+
555
+ # Parsing the request body
556
+ begin
557
+ v_object = VObject::Reader.read(request.body)
558
+ rescue VObject::ParseException => e
559
+ raise Dav::Exception::BadRequest, "The request body must be a valid iCalendar object. Parse error: #{e.message}"
560
+ end
561
+
562
+ # The incoming iCalendar object must have a METHOD property, and a
563
+ # component. The combination of both determines what type of request
564
+ # this is.
565
+ component_type = nil
566
+ v_object.components.each do |component|
567
+ if component.name != 'VTIMEZONE'
568
+ component_type = component.name
569
+ break
570
+ end
571
+ end
572
+
573
+ fail Dav::Exception::BadRequest, 'We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component' unless component_type
574
+
575
+ # Validating the METHOD
576
+ method = v_object['METHOD'].to_s.upcase
577
+ fail Dav::Exception::BadRequest, 'A METHOD property must be specified in iTIP messages' if method.blank?
578
+
579
+ # So we support one type of request:
580
+ #
581
+ # REQUEST with a VFREEBUSY component
582
+ acl = @server.plugin('acl')
583
+
584
+ if component_type == 'VFREEBUSY' && method == 'REQUEST'
585
+ acl && acl.check_privileges(outbox_path, "{#{NS_CALDAV}}schedule-query-freebusy")
586
+ handle_free_busy_request(outbox_node, v_object, request, response)
587
+
588
+ # Destroy circular references so PHP can GC the object.
589
+ v_object.destroy
590
+ v_object = nil
591
+ else
592
+ fail Dav::Exception::NotImplemented, 'We only support VFREEBUSY (REQUEST) on this endpoint'
593
+ end
594
+ end
595
+
596
+ protected
597
+
598
+ # This method is responsible for parsing a free-busy query request and
599
+ # returning it's result.
600
+ #
601
+ # @param IOutbox outbox
602
+ # @param VObject\Component v_object
603
+ # @param RequestInterface request
604
+ # @param ResponseInterface response
605
+ # @return string
606
+ def handle_free_busy_request(outbox, v_object, _request, response)
607
+ v_free_busy = v_object['VFREEBUSY']
608
+ organizer = v_free_busy['ORGANIZER'].to_s
609
+
610
+ # Validating if the organizer matches the owner of the inbox.
611
+ owner = outbox.owner
612
+
613
+ caldav_ns = "{#{NS_CALDAV}}"
614
+
615
+ uas = caldav_ns + 'calendar-user-address-set'
616
+ props = @server.properties(owner, [uas])
617
+
618
+ if !props.key?(uas) || !props[uas].hrefs.include?(organizer)
619
+ fail Dav::Exception::Forbidden, 'The organizer in the request did not match any of the addresses for the owner of this inbox'
620
+ end
621
+
622
+ unless v_free_busy.key?('ATTENDEE')
623
+ fail Dav::Exception::BadRequest, 'You must at least specify 1 attendee'
624
+ end
625
+
626
+ attendees = []
627
+ v_free_busy['ATTENDEE'].each do |attendee|
628
+ attendees << attendee.to_s
629
+ end
630
+
631
+ unless v_free_busy.key?('DTSTART') && v_free_busy.key?('DTEND')
632
+ fail Dav::Exception::BadRequest, 'DTSTART and DTEND must both be specified'
633
+ end
634
+
635
+ start_range = v_free_busy['DTSTART'].date_time
636
+ end_range = v_free_busy['DTEND'].date_time
637
+
638
+ results = []
639
+ attendees.each do |attendee|
640
+ results << free_busy_for_email(attendee, start_range, end_range, v_object)
641
+ end
642
+
643
+ dom = LibXML::XML::Document.new
644
+
645
+ schedule_response = LibXML::XML::Node.new('cal:schedule-response')
646
+ @server.xml.namespace_map.each do |namespace, prefix|
647
+ schedule_response['xmlns:' + prefix] = namespace
648
+ end
649
+
650
+ dom.root = schedule_response
651
+
652
+ results.each do |result|
653
+ xresponse = LibXML::XML::Node.new('cal:response')
654
+
655
+ recipient = LibXML::XML::Node.new('cal:recipient')
656
+ recipient_href = LibXML::XML::Node.new('d:href', result['href'])
657
+
658
+ recipient << recipient_href
659
+ xresponse << recipient
660
+
661
+ req_status = LibXML::XML::Node.new('cal:request-status', result['request-status'])
662
+ xresponse << req_status
663
+
664
+ if result.key?('calendar-data')
665
+ calendardata = LibXML::XML::Node.new('cal:calendar-data', result['calendar-data'].serialize.gsub("\r\n", "\n"))
666
+ xresponse << calendardata
667
+ end
668
+
669
+ schedule_response << xresponse
670
+ end
671
+
672
+ response.status = 200
673
+ response.update_header('Content-Type', 'application/xml')
674
+ response.body = dom.to_s
675
+ end
676
+
677
+ # Returns free-busy information for a specific address. The returned
678
+ # data is an array containing the following properties:
679
+ #
680
+ # calendar-data : A VFREEBUSY VObject
681
+ # request-status : an iTip status code.
682
+ # href: The principal's email address, as requested
683
+ #
684
+ # The following request status codes may be returned:
685
+ # * 2.0;description
686
+ # * 3.7;description
687
+ #
688
+ # @param string email address
689
+ # @param DateTimeInterface start
690
+ # @param DateTimeInterface end
691
+ # @param VObject\Component request
692
+ # @return array
693
+ def free_busy_for_email(email, start, ending, request)
694
+ caldav_ns = "{#{NS_CALDAV}}"
695
+
696
+ acl_plugin = @server.plugin('acl')
697
+ email = email[7..-1] if email[0, 7] == 'mailto:'
698
+
699
+ result = acl_plugin.principal_search(
700
+ { '{http://sabredav.org/ns}email-address' => email },
701
+ [
702
+ '{DAV:}principal-URL',
703
+ caldav_ns + 'calendar-home-set',
704
+ caldav_ns + 'schedule-inbox-URL',
705
+ '{http://sabredav.org/ns}email-address'
706
+ ]
707
+ )
708
+
709
+ if result.empty?
710
+ return {
711
+ 'request-status' => '3.7;Could not find principal',
712
+ 'href' => 'mailto:' + email
713
+ }
714
+ end
715
+
716
+ unless result[0][200].key?(caldav_ns + 'calendar-home-set')
717
+ return {
718
+ 'request-status' => '3.7;No calendar-home-set property found',
719
+ 'href' => 'mailto:' + email
720
+ }
721
+ end
722
+
723
+ unless result[0][200].key?(caldav_ns + 'schedule-inbox-URL')
724
+ return {
725
+ 'request-status' => '3.7;No schedule-inbox-URL property found',
726
+ 'href' => 'mailto:' + email
727
+ }
728
+ end
729
+
730
+ home_set = result[0][200][caldav_ns + 'calendar-home-set'].href
731
+ inbox_url = result[0][200][caldav_ns + 'schedule-inbox-URL'].href
732
+
733
+ # Grabbing the calendar list
734
+ objects = []
735
+ calendar_time_zone = ActiveSupport::TimeZone.new('UTC')
736
+
737
+ @server.tree.node_for_path(home_set).children.each do |node|
738
+ next unless node.is_a?(ICalendar)
739
+
740
+ sct = caldav_ns + 'schedule-calendar-transp'
741
+ ctz = caldav_ns + 'calendar-timezone'
742
+ props = node.properties([sct, ctz])
743
+
744
+ if props.key?(sct) && props[sct].value == Xml::Property::ScheduleCalendarTransp::TRANSPARENT
745
+ # If a calendar is marked as 'transparent', it means we must
746
+ # ignore it for free-busy purposes.
747
+ next
748
+ end
749
+
750
+ acl_plugin.check_privileges(home_set + node.name, caldav_ns + 'read-free-busy')
751
+
752
+ if props.key?(ctz)
753
+ vtimezone_obj = VObject::Reader.read(props[ctz])
754
+ calendar_time_zone = vtimezone_obj['VTIMEZONE'].time_zone
755
+
756
+ # Destroy circular references so PHP can garbage collect the object.
757
+ vtimezone_obj.destroy
758
+ end
759
+
760
+ # Getting the list of object uris within the time-range
761
+ urls = node.calendar_query(
762
+ 'name' => 'VCALENDAR',
763
+ 'comp-filters' => [
764
+ {
765
+ 'name' => 'VEVENT',
766
+ 'comp-filters' => [],
767
+ 'prop-filters' => [],
768
+ 'is-not-defined' => false,
769
+ 'time-range' => {
770
+ 'start' => start,
771
+ 'end' => ending
772
+ }
773
+ }
774
+ ],
775
+ 'prop-filters' => [],
776
+ 'is-not-defined' => false,
777
+ 'time-range' => nil
778
+ )
779
+
780
+ cal_objects = urls.map { |url| node.child(url).get }
781
+
782
+ objects += cal_objects
783
+ end
784
+
785
+ inbox_props = @server.properties(
786
+ inbox_url,
787
+ caldav_ns + 'calendar-availability'
788
+ )
789
+
790
+ vcalendar = VObject::Component::VCalendar.new
791
+ vcalendar['METHOD'] = 'REPLY'
792
+
793
+ generator = VObject::FreeBusyGenerator.new
794
+ generator.objects = objects
795
+ generator.time_range = start..ending
796
+ generator.base_object = vcalendar
797
+ generator.time_zone = calendar_time_zone
798
+
799
+ if inbox_props.any?
800
+ generator.v_availability = VObject::Reader.read(
801
+ inbox_props[caldav_ns + 'calendar-availability']
802
+ )
803
+ end
804
+
805
+ result = generator.result
806
+
807
+ vcalendar['VFREEBUSY']['ATTENDEE'] = 'mailto:' + email
808
+ vcalendar['VFREEBUSY']['UID'] = request['VFREEBUSY']['UID'].to_s
809
+ vcalendar['VFREEBUSY']['ORGANIZER'] = request['VFREEBUSY']['ORGANIZER'].deep_dup
810
+
811
+ {
812
+ 'calendar-data' => result,
813
+ 'request-status' => '2.0;Success',
814
+ 'href' => 'mailto:' + email
815
+ }
816
+ end
817
+
818
+ private
819
+
820
+ # This method checks the 'Schedule-Reply' header
821
+ # and returns false if it's 'F', otherwise true.
822
+ #
823
+ # @param RequestInterface request
824
+ # @return bool
825
+ def schedule_reply(request)
826
+ schedule_reply = request.header('Schedule-Reply')
827
+ schedule_reply != 'F'
828
+ end
829
+
830
+ public
831
+
832
+ # Returns a bunch of meta-data about the plugin.
833
+ #
834
+ # Providing this information is optional, and is mainly displayed by the
835
+ # Browser plugin.
836
+ #
837
+ # The description key in the returned array may contain html and will not
838
+ # be sanitized.
839
+ #
840
+ # @return array
841
+ def plugin_info
842
+ {
843
+ 'name' => plugin_name,
844
+ 'description' => 'Adds calendar-auto-schedule, as defined in rf6868',
845
+ 'link' => 'http://sabre.io/dav/scheduling/'
846
+ }
847
+ end
848
+ end
849
+ end
850
+ end
851
+ end