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,61 @@
1
+ module Tilia
2
+ module DavAcl
3
+ # ACL-enabled node
4
+ #
5
+ # If you want to add WebDAV ACL to a node, you must implement this class
6
+ module IAcl
7
+ include Dav::INode
8
+
9
+ # Returns the owner principal
10
+ #
11
+ # This must be a url to a principal, or null if there's no owner
12
+ #
13
+ # @return string|null
14
+ def owner
15
+ end
16
+
17
+ # Returns a group principal
18
+ #
19
+ # This must be a url to a principal, or null if there's no owner
20
+ #
21
+ # @return string|null
22
+ def group
23
+ end
24
+
25
+ # Returns a list of ACE's for this node.
26
+ #
27
+ # Each ACE has the following properties:
28
+ # * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
29
+ # currently the only supported privileges
30
+ # * 'principal', a url to the principal who owns the node
31
+ # * 'protected' (optional), indicating that this ACE is not allowed to
32
+ # be updated.
33
+ #
34
+ # @return array
35
+ def acl
36
+ end
37
+
38
+ # Updates the ACL
39
+ #
40
+ # This method will receive a list of new ACE's as an array argument.
41
+ #
42
+ # @param array acl
43
+ # @return void
44
+ def acl=(acl)
45
+ end
46
+
47
+ # Returns the list of supported privileges for this node.
48
+ #
49
+ # The returned data structure is a list of nested privileges.
50
+ # See Tilia::DavAcl::Plugin::getDefaultSupportedPrivilegeSet for a simple
51
+ # standard structure.
52
+ #
53
+ # If null is returned from this method, the default privilege set is used,
54
+ # which is fine for most common usecases.
55
+ #
56
+ # @return array|null
57
+ def supported_privilege_set
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,63 @@
1
+ module Tilia
2
+ module DavAcl
3
+ # IPrincipal interface
4
+ #
5
+ # Implement this interface to define your own principals
6
+ module IPrincipal
7
+ include Dav::INode
8
+
9
+ # Returns a list of alternative urls for a principal
10
+ #
11
+ # This can for example be an email address, or ldap url.
12
+ #
13
+ # @return array
14
+ def alternate_uri_set
15
+ end
16
+
17
+ # Returns the full principal url
18
+ #
19
+ # @return string
20
+ def principal_url
21
+ end
22
+
23
+ # Returns the list of group members
24
+ #
25
+ # If this principal is a group, this function should return
26
+ # all member principal uri's for the group.
27
+ #
28
+ # @return array
29
+ def group_member_set
30
+ end
31
+
32
+ # Returns the list of groups this principal is member of
33
+ #
34
+ # If this principal is a member of a (list of) groups, this function
35
+ # should return a list of principal uri's for it's members.
36
+ #
37
+ # @return array
38
+ def group_membership
39
+ end
40
+
41
+ # Sets a list of group members
42
+ #
43
+ # If this principal is a group, this method sets all the group members.
44
+ # The list of members is always overwritten, never appended to.
45
+ #
46
+ # This method should throw an exception if the members could not be set.
47
+ #
48
+ # @param array principals
49
+ # @return void
50
+ def group_member_set=(principals)
51
+ end
52
+
53
+ # Returns the displayname
54
+ #
55
+ # This should be a human readable name for the principal.
56
+ # If none is available, return the nodename.
57
+ #
58
+ # @return string
59
+ def display_name
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,52 @@
1
+ module Tilia
2
+ module DavAcl
3
+ # Principal Collection interface.
4
+ #
5
+ # Implement this interface to ensure that your principal collection can be
6
+ # searched using the principal-property-search REPORT.
7
+ module IPrincipalCollection
8
+ include Dav::ICollection
9
+
10
+ # This method is used to search for principals matching a set of
11
+ # properties.
12
+ #
13
+ # This search is specifically used by RFC3744's principal-property-search
14
+ # REPORT. You should at least allow searching on
15
+ # http://sabredav.org/ns}email-address.
16
+ #
17
+ # The actual search should be a unicode-non-case-sensitive search. The
18
+ # keys in searchProperties are the WebDAV property names, while the values
19
+ # are the property values to search on.
20
+ #
21
+ # By default, if multiple properties are submitted to this method, the
22
+ # various properties should be combined with 'AND'. If test is set to
23
+ # 'anyof', it should be combined using 'OR'.
24
+ #
25
+ # This method should simply return a list of 'child names', which may be
26
+ # used to call self.child in the future.
27
+ #
28
+ # @param array search_properties
29
+ # @param string test
30
+ # @return array
31
+ def search_principals(search_properties, test = 'allof')
32
+ end
33
+
34
+ # Finds a principal by its URI.
35
+ #
36
+ # This method may receive any type of uri, but mailto: addresses will be
37
+ # the most common.
38
+ #
39
+ # Implementation of this API is optional. It is currently used by the
40
+ # CalDAV system to find principals based on their email addresses. If this
41
+ # API is not implemented, some features may not work correctly.
42
+ #
43
+ # This method must return a relative principal path, or null, if the
44
+ # principal was not found or you refuse to find it.
45
+ #
46
+ # @param string uri
47
+ # @return string
48
+ def find_by_uri(uri)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,1109 @@
1
+ module Tilia
2
+ module DavAcl
3
+ # SabreDAV ACL Plugin
4
+ #
5
+ # This plugin provides functionality to enforce ACL permissions.
6
+ # ACL is defined in RFC3744.
7
+ #
8
+ # In addition it also provides support for the {DAV:}current-user-principal
9
+ # property, defined in RFC5397 and the {DAV:}expand-property report, as
10
+ # defined in RFC3253.
11
+ class Plugin < Dav::ServerPlugin
12
+ # Recursion constants
13
+ #
14
+ # This only checks the base node
15
+ R_PARENT = 1
16
+
17
+ # Recursion constants
18
+ #
19
+ # This checks every node in the tree
20
+ R_RECURSIVE = 2
21
+
22
+ # Recursion constants
23
+ #
24
+ # This checks every parentnode in the tree, but not leaf-nodes.
25
+ R_RECURSIVEPARENTS = 3
26
+
27
+ protected
28
+
29
+ # Reference to server object.
30
+ #
31
+ # @var Sabre\DAV\Server
32
+ attr_accessor :server
33
+
34
+ public
35
+
36
+ # List of urls containing principal collections.
37
+ # Modify this if your principals are located elsewhere.
38
+ #
39
+ # @var array
40
+ attr_accessor :principal_collection_set
41
+
42
+ # By default ACL is only enforced for nodes that have ACL support (the
43
+ # ones that implement IACL). For any other node, access is
44
+ # always granted.
45
+ #
46
+ # To override this behaviour you can turn this setting off. This is useful
47
+ # if you plan to fully support ACL in the entire tree.
48
+ #
49
+ # @var bool
50
+ attr_accessor :allow_access_to_nodes_without_acl
51
+
52
+ # By default nodes that are inaccessible by the user, can still be seen
53
+ # in directory listings (PROPFIND on parent with Depth: 1)
54
+ #
55
+ # In certain cases it's desirable to hide inaccessible nodes. Setting this
56
+ # to true will cause these nodes to be hidden from directory listings.
57
+ #
58
+ # @var bool
59
+ attr_accessor :hide_nodes_from_listings
60
+
61
+ # This list of properties are the properties a client can search on using
62
+ # the {DAV:}principal-property-search report.
63
+ #
64
+ # The keys are the property names, values are descriptions.
65
+ #
66
+ # @var array
67
+ attr_accessor :principal_search_property_set
68
+
69
+ # Any principal uri's added here, will automatically be added to the list
70
+ # of ACL's. They will effectively receive {DAV:}all privileges, as a
71
+ # protected privilege.
72
+ #
73
+ # @var array
74
+ attr_accessor :admin_principals
75
+
76
+ # Returns a list of features added by this plugin.
77
+ #
78
+ # This list is used in the response of a HTTP OPTIONS request.
79
+ #
80
+ # @return array
81
+ def features
82
+ ['access-control', 'calendarserver-principal-property-search']
83
+ end
84
+
85
+ # Returns a list of available methods for a given url
86
+ #
87
+ # @param string uri
88
+ # @return array
89
+ def methods(_uri)
90
+ ['ACL']
91
+ end
92
+
93
+ # Returns a plugin name.
94
+ #
95
+ # Using this name other plugins will be able to access other plugins
96
+ # using Sabre\DAV\Server::getPlugin
97
+ #
98
+ # @return string
99
+ def plugin_name
100
+ 'acl'
101
+ end
102
+
103
+ # Returns a list of reports this plugin supports.
104
+ #
105
+ # This will be used in the {DAV:}supported-report-set property.
106
+ # Note that you still need to subscribe to the 'report' event to actually
107
+ # implement them
108
+ #
109
+ # @param string uri
110
+ # @return array
111
+ def supported_report_set(_uri)
112
+ [
113
+ '{DAV:}expand-property',
114
+ '{DAV:}principal-property-search',
115
+ '{DAV:}principal-search-property-set'
116
+ ]
117
+ end
118
+
119
+ # Checks if the current user has the specified privilege(s).
120
+ #
121
+ # You can specify a single privilege, or a list of privileges.
122
+ # This method will throw an exception if the privilege is not available
123
+ # and return true otherwise.
124
+ #
125
+ # @param string uri
126
+ # @param array|string privileges
127
+ # @param int recursion
128
+ # @param bool throw_exceptions if set to false, this method won't throw exceptions.
129
+ # @throws Tilia::DavAcl::Exception\NeedPrivileges
130
+ # @return bool
131
+ def check_privileges(uri, privileges, _recursion = R_PARENT, throw_exceptions = true)
132
+ privileges = [privileges] unless privileges.is_a?(Array)
133
+
134
+ acl = current_user_privilege_set(uri)
135
+
136
+ if acl.nil?
137
+ if @allow_access_to_nodes_without_acl
138
+ return true
139
+ else
140
+ if throw_exceptions
141
+ fail Exception::NeedPrivileges.new(uri, privileges)
142
+ else
143
+ return false
144
+ end
145
+ end
146
+ end
147
+
148
+ failed = []
149
+ privileges.each do |priv|
150
+ failed << priv unless acl.include?(priv)
151
+ end
152
+
153
+ if failed.any?
154
+ if throw_exceptions
155
+ fail Exception::NeedPrivileges.new(uri, failed)
156
+ else
157
+ return false
158
+ end
159
+ end
160
+
161
+ true
162
+ end
163
+
164
+ # Returns the standard users' principal.
165
+ #
166
+ # This is one authorative principal url for the current user.
167
+ # This method will return null if the user wasn't logged in.
168
+ #
169
+ # @return string|null
170
+ def current_user_principal
171
+ auth_plugin = @server.plugin('auth')
172
+ return nil if auth_plugin.nil?
173
+
174
+ # @var auth_plugin Sabre\DAV\Auth\Plugin
175
+ auth_plugin.current_principal
176
+ end
177
+
178
+ # Returns a list of principals that's associated to the current
179
+ # user, either directly or through group membership.
180
+ #
181
+ # @return array
182
+ def current_user_principals
183
+ current_user = current_user_principal
184
+
185
+ return [] if current_user.nil?
186
+
187
+ [current_user] + principal_membership(current_user)
188
+ end
189
+
190
+ protected
191
+
192
+ # This array holds a cache for all the principals that are associated with
193
+ # a single principal.
194
+ #
195
+ # @var array
196
+ attr_accessor :principal_membership_cache
197
+
198
+ public
199
+
200
+ # Returns all the principal groups the specified principal is a member of.
201
+ #
202
+ # @param string principal
203
+ # @return array
204
+ def principal_membership(main_principal)
205
+ # First check our cache
206
+ return @principal_membership_cache[main_principal] if @principal_membership_cache.key?(main_principal)
207
+
208
+ check = [main_principal]
209
+ principals = []
210
+
211
+ while check.size > 0
212
+ principal = check.shift
213
+
214
+ node = @server.tree.node_for_path(principal)
215
+ next unless node.is_a?(IPrincipal)
216
+ node.group_membership.each do |group_member|
217
+ unless principals.include?(group_member)
218
+ check << group_member
219
+ principals << group_member
220
+ end
221
+ end
222
+ end
223
+
224
+ # Store the result in the cache
225
+ @principal_membership_cache[main_principal] = principals
226
+
227
+ principals
228
+ end
229
+
230
+ # Returns the supported privilege structure for this ACL plugin.
231
+ #
232
+ # See RFC3744 for more details. Currently we default on a simple,
233
+ # standard structure.
234
+ #
235
+ # You can either get the list of privileges by a uri (path) or by
236
+ # specifying a Node.
237
+ #
238
+ # @param string|INode node
239
+ # @return array
240
+ def supported_privilege_set(node)
241
+ node = @server.tree.node_for_path(node) if node.is_a?(String)
242
+
243
+ if node.is_a?(IAcl)
244
+ result = node.supported_privilege_set
245
+
246
+ return result if result && result.any?
247
+ end
248
+
249
+ self.class.default_supported_privilege_set
250
+ end
251
+
252
+ # Returns a fairly standard set of privileges, which may be useful for
253
+ # other systems to use as a basis.
254
+ #
255
+ # @return array
256
+ def self.default_supported_privilege_set
257
+ {
258
+ 'privilege' => '{DAV:}all',
259
+ 'abstract' => true,
260
+ 'aggregates' => [
261
+ {
262
+ 'privilege' => '{DAV:}read',
263
+ 'aggregates' => [
264
+ {
265
+ 'privilege' => '{DAV:}read-acl',
266
+ 'abstract' => false
267
+ },
268
+ {
269
+ 'privilege' => '{DAV:}read-current-user-privilege-set',
270
+ 'abstract' => false
271
+ }
272
+ ]
273
+ }, # {DAV:}read
274
+ {
275
+ 'privilege' => '{DAV:}write',
276
+ 'aggregates' => [
277
+ {
278
+ 'privilege' => '{DAV:}write-acl',
279
+ 'abstract' => false
280
+ },
281
+ {
282
+ 'privilege' => '{DAV:}write-properties',
283
+ 'abstract' => false
284
+ },
285
+ {
286
+ 'privilege' => '{DAV:}write-content',
287
+ 'abstract' => false
288
+ },
289
+ {
290
+ 'privilege' => '{DAV:}bind',
291
+ 'abstract' => false
292
+ },
293
+ {
294
+ 'privilege' => '{DAV:}unbind',
295
+ 'abstract' => false
296
+ },
297
+ {
298
+ 'privilege' => '{DAV:}unlock',
299
+ 'abstract' => false
300
+ }
301
+ ]
302
+ }, # {DAV:}write
303
+ ]
304
+ } # {DAV:}all
305
+ end
306
+
307
+ # Returns the supported privilege set as a flat list
308
+ #
309
+ # This is much easier to parse.
310
+ #
311
+ # The returned list will be index by privilege name.
312
+ # The value is a struct containing the following properties:
313
+ # - aggregates
314
+ # - abstract
315
+ # - concrete
316
+ #
317
+ # @param string|INode node
318
+ # @return array
319
+ def flat_privilege_set(node)
320
+ privs = supported_privilege_set(node)
321
+
322
+ fps_traverse = lambda do |priv, concrete, flat|
323
+ my_priv = {
324
+ 'privilege' => priv['privilege'],
325
+ 'abstract' => priv.key?('abstract') && priv['abstract'],
326
+ 'aggregates' => [],
327
+ 'concrete' => priv['abstract'] ? concrete : priv['privilege']
328
+ }
329
+
330
+ if priv.key?('aggregates')
331
+ priv['aggregates'].each do |sub_priv|
332
+ my_priv['aggregates'] << sub_priv['privilege']
333
+ end
334
+ end
335
+
336
+ flat[priv['privilege']] = my_priv
337
+
338
+ if priv.key?('aggregates')
339
+ priv['aggregates'].each do |sub_priv|
340
+ fps_traverse.call(sub_priv, my_priv['concrete'], flat)
341
+ end
342
+ end
343
+ end
344
+
345
+ flat = {}
346
+ fps_traverse.call(privs, nil, flat)
347
+
348
+ flat
349
+ end
350
+
351
+ # Returns the full ACL list.
352
+ #
353
+ # Either a uri or a INode may be passed.
354
+ #
355
+ # null will be returned if the node doesn't support ACLs.
356
+ #
357
+ # @param string|DAV\INode node
358
+ # @return array
359
+ def acl(node)
360
+ node = @server.tree.node_for_path(node) if node.is_a?(String)
361
+
362
+ return nil unless node.is_a?(IAcl)
363
+
364
+ acl = node.acl
365
+ @admin_principals.each do |admin_principal|
366
+ acl << {
367
+ 'principal' => admin_principal,
368
+ 'privilege' => '{DAV:}all',
369
+ 'protected' => true
370
+ }
371
+ end
372
+
373
+ acl
374
+ end
375
+
376
+ # Returns a list of privileges the current user has
377
+ # on a particular node.
378
+ #
379
+ # Either a uri or a DAV\INode may be passed.
380
+ #
381
+ # null will be returned if the node doesn't support ACLs.
382
+ #
383
+ # @param string|DAV\INode node
384
+ # @return array
385
+ def current_user_privilege_set(node)
386
+ node = @server.tree.node_for_path(node) if node.is_a?(String)
387
+
388
+ acl = acl(node)
389
+
390
+ return nil if acl.nil?
391
+
392
+ principals = current_user_principals
393
+
394
+ collected = []
395
+
396
+ acl.each do |ace|
397
+ principal = ace['principal']
398
+
399
+ case principal
400
+ when '{DAV:}owner'
401
+ owner = node.owner
402
+ collected << ace if owner && principals.include?(owner)
403
+ # 'all' matches for every user
404
+
405
+ # 'authenticated' matched for every user that's logged in.
406
+ # Since it's not possible to use ACL while not being logged
407
+ # in, this is also always true.
408
+ when '{DAV:}all', '{DAV:}authenticated'
409
+ collected << ace
410
+ # 'unauthenticated' can never occur either, so we simply
411
+ # ignore these.
412
+ when '{DAV:}unauthenticated'
413
+ # noop
414
+ else
415
+ collected << ace if principals.include?(ace['principal'])
416
+ end
417
+ end
418
+
419
+ # Now we deduct all aggregated privileges.
420
+ flat = flat_privilege_set(node)
421
+
422
+ collected2 = []
423
+ while collected.size > 0
424
+ current = collected.pop
425
+ collected2 << current['privilege']
426
+
427
+ flat[current['privilege']]['aggregates'].each do |sub_priv|
428
+ collected2 << sub_priv
429
+ collected << flat[sub_priv]
430
+ end
431
+ end
432
+
433
+ collected2.uniq
434
+ end
435
+
436
+ # Returns a principal based on its uri.
437
+ #
438
+ # Returns null if the principal could not be found.
439
+ #
440
+ # @param string uri
441
+ # @return null|string
442
+ def principal_by_uri(uri)
443
+ result = nil
444
+ collections = @principal_collection_set
445
+ collections.each do |collection|
446
+ principal_collection = @server.tree.node_for_path(collection)
447
+ unless principal_collection.is_a?(IPrincipalCollection)
448
+ # Not a principal collection, we're simply going to ignore
449
+ # this.
450
+ next
451
+ end
452
+
453
+ result = principal_collection.find_by_uri(uri)
454
+ return result unless result.blank?
455
+ end
456
+
457
+ nil
458
+ end
459
+
460
+ # Principal property search
461
+ #
462
+ # This method can search for principals matching certain values in
463
+ # properties.
464
+ #
465
+ # This method will return a list of properties for the matched properties.
466
+ #
467
+ # @param array search_properties The properties to search on. This is a
468
+ # key-value list. The keys are property
469
+ # names, and the values the strings to
470
+ # match them on.
471
+ # @param array requested_properties This is the list of properties to
472
+ # return for every match.
473
+ # @param string collection_uri The principal collection to search on.
474
+ # If this is ommitted, the standard
475
+ # principal collection-set will be used.
476
+ # @param string test "allof" to use AND to search the
477
+ # properties. 'anyof' for OR.
478
+ # @return array This method returns an array structure similar to
479
+ # Sabre\DAV\Server::getPropertiesForPath. Returned
480
+ # properties are index by a HTTP status code.
481
+ def principal_search(search_properties, requested_properties, collection_uri = nil, test = 'allof')
482
+ if collection_uri
483
+ uris = [collection_uri]
484
+ else
485
+ uris = @principal_collection_set
486
+ end
487
+
488
+ lookup_results = []
489
+ uris.each do |uri|
490
+ principal_collection = @server.tree.node_for_path(uri)
491
+ unless principal_collection.is_a?(IPrincipalCollection)
492
+ # Not a principal collection, we're simply going to ignore
493
+ # this.
494
+ next
495
+ end
496
+
497
+ results = principal_collection.search_principals(search_properties, test)
498
+ results.each do |result|
499
+ lookup_results << uri.gsub(%r{/+$}, '') + '/' + result
500
+ end
501
+ end
502
+
503
+ matches = []
504
+
505
+ lookup_results.each do |lookup_result|
506
+ matches << @server.properties_for_path(lookup_result, requested_properties, 0).first
507
+ end
508
+
509
+ matches
510
+ end
511
+
512
+ # Sets up the plugin
513
+ #
514
+ # This method is automatically called by the server class.
515
+ #
516
+ # @param DAV\Server server
517
+ # @return void
518
+ def setup(server)
519
+ @server = server
520
+ @server.on('propFind', method(:prop_find), 20)
521
+ @server.on('beforeMethod', method(:before_method), 20)
522
+ @server.on('beforeBind', method(:before_bind), 20)
523
+ @server.on('beforeUnbind', method(:before_unbind), 20)
524
+ @server.on('propPatch', method(:prop_patch))
525
+ @server.on('beforeUnlock', method(:before_unlock), 20)
526
+ @server.on('report', method(:report))
527
+ @server.on('method:ACL', method(:http_acl))
528
+ @server.on('onHTMLActionsPanel', method(:html_actions_panel))
529
+
530
+ @server.protected_properties += [
531
+ '{DAV:}alternate-URI-set',
532
+ '{DAV:}principal-URL',
533
+ '{DAV:}group-membership',
534
+ '{DAV:}principal-collection-set',
535
+ '{DAV:}current-user-principal',
536
+ '{DAV:}supported-privilege-set',
537
+ '{DAV:}current-user-privilege-set',
538
+ '{DAV:}acl',
539
+ '{DAV:}acl-restrictions',
540
+ '{DAV:}inherited-acl-set',
541
+ '{DAV:}owner',
542
+ '{DAV:}group'
543
+ ]
544
+
545
+ # Automatically mapping nodes implementing IPrincipal to the
546
+ # {DAV:}principal resourcetype.
547
+ @server.resource_type_mapping[Tilia::DavAcl::IPrincipal] = '{DAV:}principal'
548
+
549
+ # Mapping the group-member-set property to the HrefList property
550
+ # class.
551
+ @server.xml.element_map['{DAV:}group-member-set'] = Tilia::Dav::Xml::Property::Href
552
+ @server.xml.element_map['{DAV:}acl'] = Tilia::DavAcl::Xml::Property::Acl
553
+ @server.xml.element_map['{DAV:}expand-property'] = Tilia::DavAcl::Xml::Request::ExpandPropertyReport
554
+ @server.xml.element_map['{DAV:}principal-property-search'] = Tilia::DavAcl::Xml::Request::PrincipalPropertySearchReport
555
+ @server.xml.element_map['{DAV:}principal-search-property-set'] = Tilia::DavAcl::Xml::Request::PrincipalSearchPropertySetReport
556
+ end
557
+
558
+ # {{{ Event handlers
559
+
560
+ # Triggered before any method is handled
561
+ #
562
+ # @param RequestInterface request
563
+ # @param ResponseInterface response
564
+ # @return void
565
+ def before_method(request, _response)
566
+ method = request.method
567
+ path = request.path
568
+
569
+ exists = @server.tree.node_exists(path)
570
+
571
+ # If the node doesn't exists, none of these checks apply
572
+ return unless exists
573
+
574
+ case method
575
+ when 'GET', 'HEAD', 'OPTIONS'
576
+ # For these 3 we only need to know if the node is readable.
577
+ check_privileges(path, '{DAV:}read')
578
+ when 'PUT', 'LOCK', 'UNLOCK'
579
+ # This method requires the write-content priv if the node
580
+ # already exists, and bind on the parent if the node is being
581
+ # created.
582
+ # The bind privilege is handled in the beforeBind event.
583
+ check_privileges(path, '{DAV:}write-content')
584
+ when 'PROPPATCH'
585
+ check_privileges(path, '{DAV:}write-properties')
586
+ when 'ACL'
587
+ check_privileges(path, '{DAV:}write-acl')
588
+ when 'COPY', 'MOVE'
589
+ # Copy requires read privileges on the entire source tree.
590
+ # If the target exists write-content normally needs to be
591
+ # checked, however, we're deleting the node beforehand and
592
+ # creating a new one after, so this is handled by the
593
+ # beforeUnbind event.
594
+ #
595
+ # The creation of the new node is handled by the beforeBind
596
+ # event.
597
+ #
598
+ # If MOVE is used beforeUnbind will also be used to check if
599
+ # the sourcenode can be deleted.
600
+ check_privileges(path, '{DAV:}read', R_RECURSIVE)
601
+ end
602
+ end
603
+
604
+ # Triggered before a new node is created.
605
+ #
606
+ # This allows us to check permissions for any operation that creates a
607
+ # new node, such as PUT, MKCOL, MKCALENDAR, LOCK, COPY and MOVE.
608
+ #
609
+ # @param string uri
610
+ # @return void
611
+ def before_bind(uri)
612
+ parent_uri = Uri.split(uri)[0]
613
+ check_privileges(parent_uri, '{DAV:}bind')
614
+ end
615
+
616
+ # Triggered before a node is deleted
617
+ #
618
+ # This allows us to check permissions for any operation that will delete
619
+ # an existing node.
620
+ #
621
+ # @param string uri
622
+ # @return void
623
+ def before_unbind(uri)
624
+ parent_uri = Uri.split(uri)[0]
625
+ check_privileges(parent_uri, '{DAV:}unbind', R_RECURSIVEPARENTS)
626
+ end
627
+
628
+ # Triggered before a node is unlocked.
629
+ #
630
+ # @param string uri
631
+ # @param DAV\Locks\LockInfo lock
632
+ # @TODO: not yet implemented
633
+ # @return void
634
+ def before_unlock(uri, lock)
635
+ # noop
636
+ end
637
+
638
+ # Triggered before properties are looked up in specific nodes.
639
+ #
640
+ # @param DAV\PropFind prop_find
641
+ # @param DAV\INode node
642
+ # @param array requested_properties
643
+ # @param array returned_properties
644
+ # @TODO really should be broken into multiple methods, or even a class.
645
+ # @return bool
646
+ def prop_find(prop_find, node)
647
+ path = prop_find.path
648
+
649
+ # Checking the read permission
650
+ unless check_privileges(path, '{DAV:}read', R_PARENT, false)
651
+ # User is not allowed to read properties
652
+
653
+ # Returning false causes the property-fetching system to pretend
654
+ # that the node does not exist, and will cause it to be hidden
655
+ # from listings such as PROPFIND or the browser plugin.
656
+ return false if @hide_nodes_from_listings
657
+
658
+ # Otherwise we simply mark every property as 403.
659
+ prop_find.requested_properties.each do |requested_property|
660
+ prop_find.set(requested_property, nil, 403)
661
+ end
662
+
663
+ return true
664
+ end
665
+
666
+ # Adding principal properties
667
+ if node.is_a?(IPrincipal)
668
+ prop_find.handle(
669
+ '{DAV:}alternate-URI-set',
670
+ -> { Dav::Xml::Property::Href.new(node.alternate_uri_set) }
671
+ )
672
+ prop_find.handle(
673
+ '{DAV:}principal-URL',
674
+ -> { Dav::Xml::Property::Href.new("#{node.principal_url}/") }
675
+ )
676
+ prop_find.handle(
677
+ '{DAV:}group-member-set',
678
+ lambda do
679
+ members = node.group_member_set
680
+ members = members.map { |m| m.gsub(%r{/+$}, '') + '/' }
681
+ Dav::Xml::Property::Href.new(members)
682
+ end
683
+ )
684
+ prop_find.handle(
685
+ '{DAV:}group-membership',
686
+ lambda do
687
+ members = node.group_membership
688
+ members = members.map { |m| m.gsub(%r{/+$}, '') + '/' }
689
+ Dav::Xml::Property::Href.new(members)
690
+ end
691
+ )
692
+ prop_find.handle(
693
+ '{DAV:}displayname',
694
+ node.method(:displayname)
695
+ )
696
+ end
697
+
698
+ prop_find.handle(
699
+ '{DAV:}principal-collection-set',
700
+ lambda do
701
+ val = @principal_collection_set
702
+ # Ensuring all collections end with a slash
703
+ val = val.map { |v| v + '/' }
704
+ Dav::Xml::Property::Href.new(val)
705
+ end
706
+ )
707
+ prop_find.handle(
708
+ '{DAV:}current-user-principal',
709
+ lambda do
710
+ url = current_user_principal
711
+ if url
712
+ return Xml::Property::Principal.new(Xml::Property::Principal::HREF, url + '/')
713
+ else
714
+ return Xml::Property::Principal.new(Xml::Property::Principal::UNAUTHENTICATED)
715
+ end
716
+ end
717
+ )
718
+ prop_find.handle(
719
+ '{DAV:}supported-privilege-set',
720
+ lambda do
721
+ Xml::Property::SupportedPrivilegeSet.new(supported_privilege_set(node))
722
+ end
723
+ )
724
+ prop_find.handle(
725
+ '{DAV:}current-user-privilege-set',
726
+ lambda do
727
+ if !check_privileges(path, '{DAV:}read-current-user-privilege-set', R_PARENT, false)
728
+ prop_find.set('{DAV:}current-user-privilege-set', null, 403)
729
+ else
730
+ val = current_user_privilege_set(node)
731
+ if val.nil?
732
+ return nil
733
+ else
734
+ return Xml::Property::CurrentUserPrivilegeSet.new(val)
735
+ end
736
+ end
737
+ end
738
+ )
739
+ prop_find.handle(
740
+ '{DAV:}acl',
741
+ lambda do
742
+ # The ACL property contains all the permissions
743
+ if !check_privileges(path, '{DAV:}read-acl', R_PARENT, false)
744
+ prop_find.set('{DAV:}acl', nil, 403)
745
+ else
746
+ acl = acl(node)
747
+ if acl.nil?
748
+ return nil
749
+ else
750
+ return Xml::Property::Acl.new(acl)
751
+ end
752
+ end
753
+ end
754
+ )
755
+ prop_find.handle(
756
+ '{DAV:}acl-restrictions',
757
+ -> { Xml::Property::AclRestrictions.new }
758
+ )
759
+
760
+ # Adding ACL properties
761
+ if node.is_a?(IAcl)
762
+ prop_find.handle(
763
+ '{DAV:}owner',
764
+ -> { Dav::Xml::Property::Href.new(node.owner + '/') }
765
+ )
766
+ end
767
+ end
768
+
769
+ # This method intercepts PROPPATCH methods and make sure the
770
+ # group-member-set is updated correctly.
771
+ #
772
+ # @param string path
773
+ # @param DAV\PropPatch prop_patch
774
+ # @return void
775
+ def prop_patch(path, prop_patch)
776
+ prop_patch.handle(
777
+ '{DAV:}group-member-set',
778
+ lambda do |value|
779
+ if value.nil?
780
+ member_set = []
781
+ elsif value.is_a?(Dav::Xml::Property::Href)
782
+ member_set = value.hrefs.map { |h| @server.calculate_uri(h) }
783
+ else
784
+ fail Dav::Exception, 'The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null'
785
+ end
786
+
787
+ node = @server.tree.node_for_path(path)
788
+ unless node.is_a?(IPrincipal)
789
+ # Fail
790
+ return false
791
+ end
792
+
793
+ node.group_member_set = member_set
794
+ # We must also clear our cache, just in case
795
+
796
+ @principal_membership_cache = {}
797
+
798
+ return true
799
+ end
800
+ )
801
+ end
802
+
803
+ # This method handles HTTP REPORT requests
804
+ #
805
+ # @param string report_name
806
+ # @param mixed report
807
+ # @param mixed path
808
+ # @return bool
809
+ def report(report_name, report, _path)
810
+ case report_name
811
+ when '{DAV:}principal-property-search'
812
+ @server.transaction_type = 'report-principal-property-search'
813
+ principal_property_search_report(report)
814
+ return false
815
+ when '{DAV:}principal-search-property-set'
816
+ @server.transaction_type = 'report-principal-search-property-set'
817
+ principal_search_property_set_report(report)
818
+ return false
819
+ when '{DAV:}expand-property'
820
+ @server.transaction_type = 'report-expand-property'
821
+ expand_property_report(report)
822
+ return false
823
+ end
824
+ end
825
+
826
+ # This method is responsible for handling the 'ACL' event.
827
+ #
828
+ # @param RequestInterface request
829
+ # @param ResponseInterface response
830
+ # @return bool
831
+ def http_acl(request, response)
832
+ path = request.path
833
+ body = request.body_as_string
834
+
835
+ fail Dav::Exception::BadRequest, 'XML body expected in ACL request' if body.blank?
836
+
837
+ acl = @server.xml.expect('{DAV:}acl', body)
838
+ new_acl = acl.privileges
839
+
840
+ # Normalizing urls
841
+ new_acl.each_with_index do |new_ace, k|
842
+ new_acl[k]['principal'] = @server.calculate_uri(new_ace['principal'])
843
+ end
844
+ node = @server.tree.node_for_path(path)
845
+
846
+ fail Dav::Exception::MethodNotAllowed, 'This node does not support the ACL method' unless node.is_a?(IAcl)
847
+
848
+ old_acl = acl(node)
849
+
850
+ supported_privileges = flat_privilege_set(node)
851
+
852
+ # Checking if protected principals from the existing principal set are
853
+ # not overwritten.
854
+ old_acl.each do |old_ace|
855
+ next if !old_ace.key?('protected') || !old_ace['protected']
856
+
857
+ found = false
858
+ new_acl.each do |new_ace|
859
+ next unless new_ace['privilege'] == old_ace['privilege'] &&
860
+ new_ace['principal'] == old_ace['principal'] &&
861
+ new_ace['protected']
862
+ found = true
863
+ end
864
+
865
+ fail Exception::AceConflict, 'This resource contained a protected {DAV:}ace, but this privilege did not occur in the ACL request' unless found
866
+ end
867
+
868
+ new_acl.each do |new_ace|
869
+ # Do we recognize the privilege
870
+ fail Exception::NotSupportedPrivilege, "The privilege you specified (#{new_ace['privilege']}) is not recognized by this server" unless supported_privileges.key?(new_ace['privilege'])
871
+
872
+ fail Exception::NoAbstract, "The privilege you specified (#{new_ace['privilege']}) is an abstract privilege" if supported_privileges[new_ace['privilege']]['abstract']
873
+
874
+ # Looking up the principal
875
+ begin
876
+ principal = @server.tree.node_for_path(new_ace['principal'])
877
+ rescue Dav::Exception::NotFound => e
878
+ raise Exception::NotRecognizedPrincipal, "The specified principal (#{new_ace['principal']}) does not exist"
879
+ end
880
+
881
+ fail Exception::NotRecognizedPrincipal, "The specified uri (#{new_ace['principal']}) is not a principal" unless principal.is_a?(IPrincipal)
882
+ end
883
+ node.acl = new_acl
884
+
885
+ response.status = 200
886
+
887
+ # Breaking the event chain, because we handled this method.
888
+ false
889
+ end
890
+
891
+ # }}}
892
+
893
+ # Reports {{{
894
+
895
+ protected
896
+
897
+ # The expand-property report is defined in RFC3253 section 3-8.
898
+ #
899
+ # This report is very similar to a standard PROPFIND. The difference is
900
+ # that it has the additional ability to look at properties containing a
901
+ # {DAV:}href element, follow that property and grab additional elements
902
+ # there.
903
+ #
904
+ # Other rfc's, such as ACL rely on this report, so it made sense to put
905
+ # it in this plugin.
906
+ #
907
+ # @param Xml\Request\ExpandPropertyReport report
908
+ # @return void
909
+ def expand_property_report(report)
910
+ depth = @server.http_depth(0)
911
+ request_uri = @server.request_uri
912
+
913
+ result = expand_properties(request_uri, report.properties, depth)
914
+
915
+ xml = @server.xml.write(
916
+ '{DAV:}multistatus',
917
+ Dav::Xml::Response::MultiStatus.new(result),
918
+ @server.base_uri
919
+ )
920
+ @server.http_response.update_header('Content-Type', 'application/xml; charset=utf-8')
921
+ @server.http_response.status = 207
922
+ @server.http_response.body = xml
923
+ end
924
+
925
+ # This method expands all the properties and returns
926
+ # a list with property values
927
+ #
928
+ # @param array path
929
+ # @param array requested_properties the list of required properties
930
+ # @param int depth
931
+ # @return array
932
+ def expand_properties(path, requested_properties, depth)
933
+ found_properties = @server.properties_for_path(path, requested_properties.keys, depth)
934
+
935
+ result = []
936
+ found_properties.each do |node|
937
+ requested_properties.each do |property_name, child_requested_properties|
938
+ # We're only traversing if sub-properties were requested
939
+ next unless child_requested_properties
940
+ next if child_requested_properties.size == 0
941
+
942
+ # We only have to do the expansion if the property was found
943
+ # and it contains an href element.
944
+ next unless node[200].key?(property_name)
945
+
946
+ next unless node[200][property_name].is_a?(Dav::Xml::Property::Href)
947
+
948
+ child_hrefs = node[200][property_name].hrefs
949
+ child_props = []
950
+
951
+ child_hrefs.each do |href|
952
+ # Gathering the result of the children
953
+ child_props << {
954
+ 'name' => '{DAV:}response',
955
+ 'value' => expand_properties(href, child_requested_properties, 0)[0]
956
+ }
957
+ end
958
+
959
+ # Replacing the property with its expannded form.
960
+ node[200][property_name] = child_props
961
+ end
962
+
963
+ result << Dav::Xml::Element::Response.new(node['href'], node)
964
+ end
965
+
966
+ result
967
+ end
968
+
969
+ # principalSearchPropertySetReport
970
+ #
971
+ # This method responsible for handing the
972
+ # {DAV:}principal-search-property-set report. This report returns a list
973
+ # of properties the client may search on, using the
974
+ # {DAV:}principal-property-search report.
975
+ #
976
+ # @param Xml\Request\PrincipalSearchPropertySetReport report
977
+ # @return void
978
+ def principal_search_property_set_report(_report)
979
+ http_depth = @server.http_depth(0)
980
+
981
+ fail Dav::Exception::BadRequest, 'This report is only defined when Depth: 0' unless http_depth == 0
982
+
983
+ writer = @server.xml.writer
984
+ writer.open_memory
985
+ writer.start_document
986
+
987
+ writer.start_element('{DAV:}principal-search-property-set')
988
+
989
+ @principal_search_property_set.each do |property_name, description|
990
+ writer.start_element('{DAV:}principal-search-property')
991
+ writer.start_element('{DAV:}prop')
992
+
993
+ writer.write_element(property_name)
994
+
995
+ writer.end_element # prop
996
+
997
+ unless description.blank?
998
+ writer.write(
999
+ [ # Hash in Array!
1000
+ 'name' => '{DAV:}description',
1001
+ 'value' => description,
1002
+ 'attributes' => { 'xml:lang' => 'en' }
1003
+ ]
1004
+ )
1005
+ end
1006
+
1007
+ writer.end_element # principal-search-property
1008
+ end
1009
+
1010
+ writer.end_element # principal-search-property-set
1011
+
1012
+ @server.http_response.update_header('Content-Type', 'application/xml; charset=utf-8')
1013
+ @server.http_response.status = 200
1014
+ @server.http_response.body = writer.output_memory
1015
+ end
1016
+
1017
+ # principalPropertySearchReport
1018
+ #
1019
+ # This method is responsible for handing the
1020
+ # {DAV:}principal-property-search report. This report can be used for
1021
+ # clients to search for groups of principals, based on the value of one
1022
+ # or more properties.
1023
+ #
1024
+ # @param Xml\Request\PrincipalPropertySearchReport report
1025
+ # @return void
1026
+ def principal_property_search_report(report)
1027
+ uri = nil
1028
+
1029
+ uri = @server.http_request.path unless report.apply_to_principal_collection_set
1030
+
1031
+ fail Dav::Exception::BadRequest, 'Depth must be 0' unless @server.http_depth('0') == 0
1032
+
1033
+ result = principal_search(
1034
+ report.search_properties,
1035
+ report.properties,
1036
+ uri,
1037
+ report.test
1038
+ )
1039
+
1040
+ prefer = @server.http_prefer
1041
+
1042
+ @server.http_response.status = 207
1043
+ @server.http_response.update_header('Content-Type', 'application/xml; charset=utf-8')
1044
+ @server.http_response.update_header('Vary', 'Brief,Prefer')
1045
+ @server.http_response.body = @server.generate_multi_status(result, prefer['return'] == 'minimal')
1046
+ end
1047
+
1048
+ public
1049
+
1050
+ # }}}
1051
+
1052
+ # This method is used to generate HTML output for the
1053
+ # DAV\Browser\Plugin. This allows us to generate an interface users
1054
+ # can use to create new calendars.
1055
+ #
1056
+ # @param DAV\INode node
1057
+ # @param [Box] output
1058
+ # @return bool
1059
+ def html_actions_panel(node, output)
1060
+ return false unless node.is_a?(PrincipalCollection)
1061
+
1062
+ output.value << <<HTML
1063
+ <tr><td colspan="2"><form method="post" action="">
1064
+ <h3>Create new principal</h3>
1065
+ <input type="hidden" name="sabreAction" value="mkcol" />
1066
+ <input type="hidden" name="resourceType" value="{DAV:}principal" />
1067
+ <label>Name (uri):</label> <input type="text" name="name" /><br />
1068
+ <label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br />
1069
+ <label>Email address:</label> <input type="text" name="{http://sabredav*DOT*org/ns}email-address" /><br />
1070
+ <input type="submit" value="create" />
1071
+ </form>
1072
+ </td></tr>
1073
+ HTML
1074
+
1075
+ false
1076
+ end
1077
+
1078
+ # Returns a bunch of meta-data about the plugin.
1079
+ #
1080
+ # Providing this information is optional, and is mainly displayed by the
1081
+ # Browser plugin.
1082
+ #
1083
+ # The description key in the returned array may contain html and will not
1084
+ # be sanitized.
1085
+ #
1086
+ # @return array
1087
+ def plugin_info
1088
+ {
1089
+ 'name' => plugin_name,
1090
+ 'description' => 'Adds support for WebDAV ACL (rfc3744)',
1091
+ 'link' => 'http://sabre.io/dav/acl/'
1092
+ }
1093
+ end
1094
+
1095
+ # TODO: document
1096
+ def initialize
1097
+ @principal_collection_set = ['principals']
1098
+ @allow_access_to_nodes_without_acl = true
1099
+ @hide_nodes_from_listings = false
1100
+ @principal_search_property_set = {
1101
+ '{DAV:}displayname' => 'Display name',
1102
+ '{http://sabredav.org/ns}email-address' => 'Email address'
1103
+ }
1104
+ @admin_principals = []
1105
+ @principal_membership_cache = {}
1106
+ end
1107
+ end
1108
+ end
1109
+ end