tilia-dav 3.1.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.database.travis.yml +6 -0
- data/.gitignore +25 -0
- data/.rubocop.yml +35 -0
- data/.simplecov +4 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.sabre.md +2084 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +103 -0
- data/LICENSE +27 -0
- data/LICENSE.sabre +27 -0
- data/README.md +40 -0
- data/Rakefile +18 -0
- data/database.sample.yml +6 -0
- data/examples/minimal.rb +25 -0
- data/lib/tilia/cal_dav.rb +27 -0
- data/lib/tilia/cal_dav/backend.rb +17 -0
- data/lib/tilia/cal_dav/backend/abstract_backend.rb +194 -0
- data/lib/tilia/cal_dav/backend/backend_interface.rb +250 -0
- data/lib/tilia/cal_dav/backend/notification_support.rb +38 -0
- data/lib/tilia/cal_dav/backend/scheduling_support.rb +57 -0
- data/lib/tilia/cal_dav/backend/sequel.rb +1118 -0
- data/lib/tilia/cal_dav/backend/sharing_support.rb +239 -0
- data/lib/tilia/cal_dav/backend/subscription_support.rb +79 -0
- data/lib/tilia/cal_dav/backend/sync_support.rb +75 -0
- data/lib/tilia/cal_dav/calendar.rb +426 -0
- data/lib/tilia/cal_dav/calendar_home.rb +335 -0
- data/lib/tilia/cal_dav/calendar_object.rb +219 -0
- data/lib/tilia/cal_dav/calendar_query_validator.rb +294 -0
- data/lib/tilia/cal_dav/calendar_root.rb +57 -0
- data/lib/tilia/cal_dav/exception.rb +7 -0
- data/lib/tilia/cal_dav/exception/invalid_component_type.rb +21 -0
- data/lib/tilia/cal_dav/i_calendar.rb +11 -0
- data/lib/tilia/cal_dav/i_calendar_object.rb +13 -0
- data/lib/tilia/cal_dav/i_calendar_object_container.rb +32 -0
- data/lib/tilia/cal_dav/i_shareable_calendar.rb +40 -0
- data/lib/tilia/cal_dav/i_shared_calendar.rb +28 -0
- data/lib/tilia/cal_dav/ics_export_plugin.rb +327 -0
- data/lib/tilia/cal_dav/notifications.rb +12 -0
- data/lib/tilia/cal_dav/notifications/collection.rb +131 -0
- data/lib/tilia/cal_dav/notifications/i_collection.rb +17 -0
- data/lib/tilia/cal_dav/notifications/i_node.rb +30 -0
- data/lib/tilia/cal_dav/notifications/node.rb +142 -0
- data/lib/tilia/cal_dav/notifications/plugin.rb +138 -0
- data/lib/tilia/cal_dav/plugin.rb +891 -0
- data/lib/tilia/cal_dav/principal.rb +12 -0
- data/lib/tilia/cal_dav/principal/collection.rb +21 -0
- data/lib/tilia/cal_dav/principal/i_proxy_read.rb +13 -0
- data/lib/tilia/cal_dav/principal/i_proxy_write.rb +13 -0
- data/lib/tilia/cal_dav/principal/proxy_read.rb +127 -0
- data/lib/tilia/cal_dav/principal/proxy_write.rb +127 -0
- data/lib/tilia/cal_dav/principal/user.rb +96 -0
- data/lib/tilia/cal_dav/schedule.rb +14 -0
- data/lib/tilia/cal_dav/schedule/i_inbox.rb +12 -0
- data/lib/tilia/cal_dav/schedule/i_mip_plugin.rb +156 -0
- data/lib/tilia/cal_dav/schedule/i_outbox.rb +12 -0
- data/lib/tilia/cal_dav/schedule/i_scheduling_object.rb +10 -0
- data/lib/tilia/cal_dav/schedule/inbox.rb +211 -0
- data/lib/tilia/cal_dav/schedule/outbox.rb +143 -0
- data/lib/tilia/cal_dav/schedule/plugin.rb +851 -0
- data/lib/tilia/cal_dav/schedule/scheduling_object.rb +126 -0
- data/lib/tilia/cal_dav/shareable_calendar.rb +54 -0
- data/lib/tilia/cal_dav/shared_calendar.rb +120 -0
- data/lib/tilia/cal_dav/sharing_plugin.rb +359 -0
- data/lib/tilia/cal_dav/subscriptions.rb +9 -0
- data/lib/tilia/cal_dav/subscriptions/i_subscription.rb +37 -0
- data/lib/tilia/cal_dav/subscriptions/plugin.rb +83 -0
- data/lib/tilia/cal_dav/subscriptions/subscription.rb +205 -0
- data/lib/tilia/cal_dav/xml.rb +10 -0
- data/lib/tilia/cal_dav/xml/filter.rb +12 -0
- data/lib/tilia/cal_dav/xml/filter/calendar_data.rb +64 -0
- data/lib/tilia/cal_dav/xml/filter/comp_filter.rb +79 -0
- data/lib/tilia/cal_dav/xml/filter/param_filter.rb +66 -0
- data/lib/tilia/cal_dav/xml/filter/prop_filter.rb +80 -0
- data/lib/tilia/cal_dav/xml/notification.rb +13 -0
- data/lib/tilia/cal_dav/xml/notification/invite.rb +253 -0
- data/lib/tilia/cal_dav/xml/notification/invite_reply.rb +167 -0
- data/lib/tilia/cal_dav/xml/notification/notification_interface.rb +41 -0
- data/lib/tilia/cal_dav/xml/notification/system_status.rb +139 -0
- data/lib/tilia/cal_dav/xml/property.rb +15 -0
- data/lib/tilia/cal_dav/xml/property/allowed_sharing_modes.rb +64 -0
- data/lib/tilia/cal_dav/xml/property/email_address_set.rb +60 -0
- data/lib/tilia/cal_dav/xml/property/invite.rb +207 -0
- data/lib/tilia/cal_dav/xml/property/schedule_calendar_transp.rb +108 -0
- data/lib/tilia/cal_dav/xml/property/supported_calendar_component_set.rb +100 -0
- data/lib/tilia/cal_dav/xml/property/supported_calendar_data.rb +50 -0
- data/lib/tilia/cal_dav/xml/property/supported_collation_set.rb +47 -0
- data/lib/tilia/cal_dav/xml/request.rb +14 -0
- data/lib/tilia/cal_dav/xml/request/calendar_multi_get_report.rb +99 -0
- data/lib/tilia/cal_dav/xml/request/calendar_query_report.rb +112 -0
- data/lib/tilia/cal_dav/xml/request/free_busy_query_report.rb +70 -0
- data/lib/tilia/cal_dav/xml/request/invite_reply.rb +110 -0
- data/lib/tilia/cal_dav/xml/request/mk_calendar.rb +67 -0
- data/lib/tilia/cal_dav/xml/request/share.rb +93 -0
- data/lib/tilia/card_dav.rb +17 -0
- data/lib/tilia/card_dav/address_book.rb +338 -0
- data/lib/tilia/card_dav/address_book_home.rb +192 -0
- data/lib/tilia/card_dav/address_book_root.rb +58 -0
- data/lib/tilia/card_dav/backend.rb +12 -0
- data/lib/tilia/card_dav/backend/abstract_backend.rb +30 -0
- data/lib/tilia/card_dav/backend/backend_interface.rb +175 -0
- data/lib/tilia/card_dav/backend/sequel.rb +476 -0
- data/lib/tilia/card_dav/backend/sync_support.rb +80 -0
- data/lib/tilia/card_dav/card.rb +193 -0
- data/lib/tilia/card_dav/i_address_book.rb +10 -0
- data/lib/tilia/card_dav/i_card.rb +11 -0
- data/lib/tilia/card_dav/i_directory.rb +14 -0
- data/lib/tilia/card_dav/plugin.rb +724 -0
- data/lib/tilia/card_dav/vcf_export_plugin.rb +122 -0
- data/lib/tilia/card_dav/xml.rb +9 -0
- data/lib/tilia/card_dav/xml/filter.rb +11 -0
- data/lib/tilia/card_dav/xml/filter/address_data.rb +50 -0
- data/lib/tilia/card_dav/xml/filter/param_filter.rb +71 -0
- data/lib/tilia/card_dav/xml/filter/prop_filter.rb +77 -0
- data/lib/tilia/card_dav/xml/property.rb +10 -0
- data/lib/tilia/card_dav/xml/property/supported_address_data.rb +67 -0
- data/lib/tilia/card_dav/xml/property/supported_collation_set.rb +38 -0
- data/lib/tilia/card_dav/xml/request.rb +10 -0
- data/lib/tilia/card_dav/xml/request/address_book_multi_get_report.rb +91 -0
- data/lib/tilia/card_dav/xml/request/address_book_query_report.rb +156 -0
- data/lib/tilia/dav.rb +94 -0
- data/lib/tilia/dav/auth.rb +8 -0
- data/lib/tilia/dav/auth/backend.rb +15 -0
- data/lib/tilia/dav/auth/backend/abstract_basic.rb +119 -0
- data/lib/tilia/dav/auth/backend/abstract_digest.rb +132 -0
- data/lib/tilia/dav/auth/backend/apache.rb +85 -0
- data/lib/tilia/dav/auth/backend/backend_interface.rb +61 -0
- data/lib/tilia/dav/auth/backend/basic_call_back.rb +46 -0
- data/lib/tilia/dav/auth/backend/file.rb +61 -0
- data/lib/tilia/dav/auth/backend/sequel.rb +46 -0
- data/lib/tilia/dav/auth/plugin.rb +157 -0
- data/lib/tilia/dav/browser.rb +12 -0
- data/lib/tilia/dav/browser/assets/favicon.ico +0 -0
- data/lib/tilia/dav/browser/assets/openiconic/ICON-LICENSE +21 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.css +510 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.eot +0 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.otf +0 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.svg +543 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.ttf +0 -0
- data/lib/tilia/dav/browser/assets/openiconic/open-iconic.woff +0 -0
- data/lib/tilia/dav/browser/assets/sabredav.css +228 -0
- data/lib/tilia/dav/browser/assets/sabredav.png +0 -0
- data/lib/tilia/dav/browser/guess_content_type.rb +80 -0
- data/lib/tilia/dav/browser/html_output.rb +27 -0
- data/lib/tilia/dav/browser/html_output_helper.rb +86 -0
- data/lib/tilia/dav/browser/map_get_to_prop_find.rb +41 -0
- data/lib/tilia/dav/browser/plugin.rb +693 -0
- data/lib/tilia/dav/browser/prop_find_all.rb +95 -0
- data/lib/tilia/dav/client.rb +341 -0
- data/lib/tilia/dav/collection.rb +79 -0
- data/lib/tilia/dav/core_plugin.rb +824 -0
- data/lib/tilia/dav/exception.rb +59 -0
- data/lib/tilia/dav/exception/bad_request.rb +18 -0
- data/lib/tilia/dav/exception/conflict.rb +18 -0
- data/lib/tilia/dav/exception/conflicting_lock.rb +26 -0
- data/lib/tilia/dav/exception/forbidden.rb +18 -0
- data/lib/tilia/dav/exception/insufficient_storage.rb +18 -0
- data/lib/tilia/dav/exception/invalid_resource_type.rb +23 -0
- data/lib/tilia/dav/exception/invalid_sync_token.rb +26 -0
- data/lib/tilia/dav/exception/length_required.rb +18 -0
- data/lib/tilia/dav/exception/lock_token_matches_request_uri.rb +25 -0
- data/lib/tilia/dav/exception/locked.rb +48 -0
- data/lib/tilia/dav/exception/method_not_allowed.rb +29 -0
- data/lib/tilia/dav/exception/not_authenticated.rb +18 -0
- data/lib/tilia/dav/exception/not_found.rb +18 -0
- data/lib/tilia/dav/exception/not_implemented.rb +18 -0
- data/lib/tilia/dav/exception/payment_required.rb +18 -0
- data/lib/tilia/dav/exception/precondition_failed.rb +47 -0
- data/lib/tilia/dav/exception/report_not_supported.rb +21 -0
- data/lib/tilia/dav/exception/requested_range_not_satisfiable.rb +18 -0
- data/lib/tilia/dav/exception/service_unavailable.rb +18 -0
- data/lib/tilia/dav/exception/too_many_matches.rb +21 -0
- data/lib/tilia/dav/exception/unsupported_media_type.rb +18 -0
- data/lib/tilia/dav/file.rb +58 -0
- data/lib/tilia/dav/fs.rb +9 -0
- data/lib/tilia/dav/fs/directory.rb +119 -0
- data/lib/tilia/dav/fs/file.rb +69 -0
- data/lib/tilia/dav/fs/node.rb +57 -0
- data/lib/tilia/dav/fs_ext.rb +8 -0
- data/lib/tilia/dav/fs_ext/directory.rb +175 -0
- data/lib/tilia/dav/fs_ext/file.rb +118 -0
- data/lib/tilia/dav/i_collection.rb +65 -0
- data/lib/tilia/dav/i_extended_collection.rb +36 -0
- data/lib/tilia/dav/i_file.rb +70 -0
- data/lib/tilia/dav/i_move_target.rb +37 -0
- data/lib/tilia/dav/i_multi_get.rb +29 -0
- data/lib/tilia/dav/i_node.rb +33 -0
- data/lib/tilia/dav/i_properties.rb +39 -0
- data/lib/tilia/dav/i_quota.rb +19 -0
- data/lib/tilia/dav/locks.rb +9 -0
- data/lib/tilia/dav/locks/backend.rb +12 -0
- data/lib/tilia/dav/locks/backend/abstract_backend.rb +16 -0
- data/lib/tilia/dav/locks/backend/backend_interface.rb +41 -0
- data/lib/tilia/dav/locks/backend/file.rb +146 -0
- data/lib/tilia/dav/locks/backend/sequel.rb +154 -0
- data/lib/tilia/dav/locks/lock_info.rb +60 -0
- data/lib/tilia/dav/locks/plugin.rb +467 -0
- data/lib/tilia/dav/mk_col.rb +47 -0
- data/lib/tilia/dav/mount.rb +7 -0
- data/lib/tilia/dav/mount/plugin.rb +62 -0
- data/lib/tilia/dav/node.rb +36 -0
- data/lib/tilia/dav/partial_update.rb +8 -0
- data/lib/tilia/dav/partial_update/i_patch_support.rb +40 -0
- data/lib/tilia/dav/partial_update/plugin.rb +179 -0
- data/lib/tilia/dav/prop_find.rb +262 -0
- data/lib/tilia/dav/prop_patch.rb +278 -0
- data/lib/tilia/dav/property_storage.rb +8 -0
- data/lib/tilia/dav/property_storage/backend.rb +10 -0
- data/lib/tilia/dav/property_storage/backend/backend_interface.rb +69 -0
- data/lib/tilia/dav/property_storage/backend/sequel.rb +192 -0
- data/lib/tilia/dav/property_storage/plugin.rb +131 -0
- data/lib/tilia/dav/server.rb +1388 -0
- data/lib/tilia/dav/server_plugin.rb +81 -0
- data/lib/tilia/dav/simple_collection.rb +71 -0
- data/lib/tilia/dav/simple_file.rb +82 -0
- data/lib/tilia/dav/string_util.rb +68 -0
- data/lib/tilia/dav/sync.rb +8 -0
- data/lib/tilia/dav/sync/i_sync_collection.rb +80 -0
- data/lib/tilia/dav/sync/plugin.rb +225 -0
- data/lib/tilia/dav/temporary_file_filter_plugin.rb +248 -0
- data/lib/tilia/dav/tree.rb +270 -0
- data/lib/tilia/dav/uuid_util.rb +45 -0
- data/lib/tilia/dav/version.rb +9 -0
- data/lib/tilia/dav/xml.rb +11 -0
- data/lib/tilia/dav/xml/element.rb +10 -0
- data/lib/tilia/dav/xml/element/prop.rb +92 -0
- data/lib/tilia/dav/xml/element/response.rb +188 -0
- data/lib/tilia/dav/xml/property.rb +16 -0
- data/lib/tilia/dav/xml/property/complex.rb +76 -0
- data/lib/tilia/dav/xml/property/get_last_modified.rb +79 -0
- data/lib/tilia/dav/xml/property/href.rb +137 -0
- data/lib/tilia/dav/xml/property/lock_discovery.rb +89 -0
- data/lib/tilia/dav/xml/property/resource_type.rb +96 -0
- data/lib/tilia/dav/xml/property/supported_lock.rb +48 -0
- data/lib/tilia/dav/xml/property/supported_method_set.rb +101 -0
- data/lib/tilia/dav/xml/property/supported_report_set.rb +118 -0
- data/lib/tilia/dav/xml/request.rb +13 -0
- data/lib/tilia/dav/xml/request/lock.rb +67 -0
- data/lib/tilia/dav/xml/request/mk_col.rb +69 -0
- data/lib/tilia/dav/xml/request/prop_find.rb +70 -0
- data/lib/tilia/dav/xml/request/prop_patch.rb +101 -0
- data/lib/tilia/dav/xml/request/sync_collection_report.rb +102 -0
- data/lib/tilia/dav/xml/response.rb +9 -0
- data/lib/tilia/dav/xml/response/multi_status.rb +108 -0
- data/lib/tilia/dav/xml/service.rb +42 -0
- data/lib/tilia/dav_acl.rb +16 -0
- data/lib/tilia/dav_acl/abstract_principal_collection.rb +143 -0
- data/lib/tilia/dav_acl/exception.rb +11 -0
- data/lib/tilia/dav_acl/exception/ace_conflict.rb +21 -0
- data/lib/tilia/dav_acl/exception/need_privileges.rb +65 -0
- data/lib/tilia/dav_acl/exception/no_abstract.rb +21 -0
- data/lib/tilia/dav_acl/exception/not_recognized_principal.rb +21 -0
- data/lib/tilia/dav_acl/exception/not_supported_privilege.rb +21 -0
- data/lib/tilia/dav_acl/fs.rb +9 -0
- data/lib/tilia/dav_acl/fs/collection.rb +108 -0
- data/lib/tilia/dav_acl/fs/file.rb +87 -0
- data/lib/tilia/dav_acl/fs/home_collection.rb +148 -0
- data/lib/tilia/dav_acl/i_acl.rb +61 -0
- data/lib/tilia/dav_acl/i_principal.rb +63 -0
- data/lib/tilia/dav_acl/i_principal_collection.rb +52 -0
- data/lib/tilia/dav_acl/plugin.rb +1109 -0
- data/lib/tilia/dav_acl/principal.rb +213 -0
- data/lib/tilia/dav_acl/principal_backend.rb +11 -0
- data/lib/tilia/dav_acl/principal_backend/abstract_backend.rb +42 -0
- data/lib/tilia/dav_acl/principal_backend/backend_interface.rb +127 -0
- data/lib/tilia/dav_acl/principal_backend/create_principal_support.rb +27 -0
- data/lib/tilia/dav_acl/principal_backend/sequel.rb +313 -0
- data/lib/tilia/dav_acl/principal_collection.rb +117 -0
- data/lib/tilia/dav_acl/xml.rb +8 -0
- data/lib/tilia/dav_acl/xml/property.rb +13 -0
- data/lib/tilia/dav_acl/xml/property/acl.rb +222 -0
- data/lib/tilia/dav_acl/xml/property/acl_restrictions.rb +40 -0
- data/lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb +125 -0
- data/lib/tilia/dav_acl/xml/property/principal.rb +149 -0
- data/lib/tilia/dav_acl/xml/property/supported_privilege_set.rb +135 -0
- data/lib/tilia/dav_acl/xml/request.rb +11 -0
- data/lib/tilia/dav_acl/xml/request/expand_property_report.rb +86 -0
- data/lib/tilia/dav_acl/xml/request/principal_property_search_report.rb +111 -0
- data/lib/tilia/dav_acl/xml/request/principal_search_property_set_report.rb +49 -0
- data/test/cal_dav/backend/abstract_sequel_test.rb +817 -0
- data/test/cal_dav/backend/abstract_test.rb +163 -0
- data/test/cal_dav/backend/mock.rb +169 -0
- data/test/cal_dav/backend/mock_scheduling.rb +84 -0
- data/test/cal_dav/backend/mock_sharing.rb +124 -0
- data/test/cal_dav/backend/mock_subscription_support.rb +123 -0
- data/test/cal_dav/backend/sequel_my_sql_test.rb +102 -0
- data/test/cal_dav/backend/sequel_sqlite_test.rb +105 -0
- data/test/cal_dav/calendar_home_notifications_test.rb +41 -0
- data/test/cal_dav/calendar_home_shared_calendars_test.rb +64 -0
- data/test/cal_dav/calendar_home_subscriptions_test.rb +67 -0
- data/test/cal_dav/calendar_home_test.rb +144 -0
- data/test/cal_dav/calendar_object_test.rb +317 -0
- data/test/cal_dav/calendar_query_v_alarm_test.rb +114 -0
- data/test/cal_dav/calendar_query_validator_test.rb +820 -0
- data/test/cal_dav/calendar_test.rb +203 -0
- data/test/cal_dav/expand_events_double_events_test.rb +94 -0
- data/test/cal_dav/expand_events_dtstar_tand_dten_dby_day_test.rb +94 -0
- data/test/cal_dav/expand_events_dtstar_tand_dtend_test.rb +100 -0
- data/test/cal_dav/expand_events_floating_time_test.rb +211 -0
- data/test/cal_dav/free_busy_report_test.rb +156 -0
- data/test/cal_dav/get_events_by_timerange_test.rb +74 -0
- data/test/cal_dav/ics_export_plugin_test.rb +638 -0
- data/test/cal_dav/issue166_test.rb +59 -0
- data/test/cal_dav/issue172_test.rb +139 -0
- data/test/cal_dav/issue203_test.rb +130 -0
- data/test/cal_dav/issue205_test.rb +89 -0
- data/test/cal_dav/issue211_test.rb +84 -0
- data/test/cal_dav/issue220_test.rb +94 -0
- data/test/cal_dav/issue228_test.rb +74 -0
- data/test/cal_dav/j_cal_transform_test.rb +244 -0
- data/test/cal_dav/notifications/collection_test.rb +67 -0
- data/test/cal_dav/notifications/node_test.rb +73 -0
- data/test/cal_dav/notifications/plugin_test.rb +144 -0
- data/test/cal_dav/plugin_test.rb +1049 -0
- data/test/cal_dav/principal/collection_test.rb +19 -0
- data/test/cal_dav/principal/proxy_read_test.rb +67 -0
- data/test/cal_dav/principal/proxy_write_test.rb +29 -0
- data/test/cal_dav/principal/user_test.rb +91 -0
- data/test/cal_dav/schedule/deliver_new_event_test.rb +81 -0
- data/test/cal_dav/schedule/free_busy_request_test.rb +565 -0
- data/test/cal_dav/schedule/i_mip/mock_plugin.rb +40 -0
- data/test/cal_dav/schedule/i_mip_plugin_test.rb +196 -0
- data/test/cal_dav/schedule/inbox_test.rb +150 -0
- data/test/cal_dav/schedule/outbox_post_test.rb +124 -0
- data/test/cal_dav/schedule/outbox_test.rb +76 -0
- data/test/cal_dav/schedule/plugin_basic_test.rb +39 -0
- data/test/cal_dav/schedule/plugin_properties_test.rb +96 -0
- data/test/cal_dav/schedule/plugin_properties_with_shared_calendar_test.rb +69 -0
- data/test/cal_dav/schedule/schedule_deliver_test.rb +605 -0
- data/test/cal_dav/schedule/scheduling_object_test.rb +327 -0
- data/test/cal_dav/shareable_calendar_test.rb +58 -0
- data/test/cal_dav/shared_calendar_test.rb +189 -0
- data/test/cal_dav/sharing_plugin_test.rb +373 -0
- data/test/cal_dav/subscriptions/create_subscription_test.rb +115 -0
- data/test/cal_dav/subscriptions/plugin_test.rb +46 -0
- data/test/cal_dav/subscriptions/subscription_test.rb +119 -0
- data/test/cal_dav/test_util.rb +164 -0
- data/test/cal_dav/validate_i_cal_test.rb +219 -0
- data/test/cal_dav/xml/notification/invite_reply_test.rb +136 -0
- data/test/cal_dav/xml/notification/invite_test.rb +225 -0
- data/test/cal_dav/xml/notification/system_status_test.rb +63 -0
- data/test/cal_dav/xml/property/allowed_sharing_modes_test.rb +34 -0
- data/test/cal_dav/xml/property/email_address_set_test.rb +35 -0
- data/test/cal_dav/xml/property/invite_test.rb +173 -0
- data/test/cal_dav/xml/property/schedule_calendar_transp_test.rb +96 -0
- data/test/cal_dav/xml/property/supported_calendar_component_set_test.rb +76 -0
- data/test/cal_dav/xml/property/supported_calendar_data_test.rb +32 -0
- data/test/cal_dav/xml/property/supported_collation_set_test.rb +33 -0
- data/test/cal_dav/xml/request/calendar_query_report_test.rb +339 -0
- data/test/cal_dav/xml/request/invite_reply_test.rb +68 -0
- data/test/cal_dav/xml/request/share_test.rb +79 -0
- data/test/card_dav/abstract_plugin_test.rb +24 -0
- data/test/card_dav/address_book_home_test.rb +128 -0
- data/test/card_dav/address_book_query_test.rb +303 -0
- data/test/card_dav/address_book_root_test.rb +26 -0
- data/test/card_dav/address_book_test.rb +166 -0
- data/test/card_dav/backend/abstract_sequel_test.rb +302 -0
- data/test/card_dav/backend/mock.rb +122 -0
- data/test/card_dav/backend/sequel_my_sql_test.rb +56 -0
- data/test/card_dav/backend/sequel_sqlite_test.rb +59 -0
- data/test/card_dav/card_test.rb +164 -0
- data/test/card_dav/i_directory_test.rb +22 -0
- data/test/card_dav/multi_get_test.rb +97 -0
- data/test/card_dav/plugin_test.rb +87 -0
- data/test/card_dav/sogo_strip_content_type_test.rb +63 -0
- data/test/card_dav/test_util.rb +51 -0
- data/test/card_dav/validate_filter_test.rb +210 -0
- data/test/card_dav/validate_v_card_test.rb +143 -0
- data/test/card_dav/vcf_export_test.rb +66 -0
- data/test/card_dav/xml/property/supported_address_data_test.rb +34 -0
- data/test/card_dav/xml/property/supported_collation_set_test.rb +34 -0
- data/test/card_dav/xml/request/address_book_query_report_test.rb +276 -0
- data/test/dav/abstract_server.rb +36 -0
- data/test/dav/auth/backend/abstract_basic_test.rb +74 -0
- data/test/dav/auth/backend/abstract_digest_test.rb +114 -0
- data/test/dav/auth/backend/abstract_sequel_test.rb +25 -0
- data/test/dav/auth/backend/apache_test.rb +60 -0
- data/test/dav/auth/backend/basic_call_back_test.rb +33 -0
- data/test/dav/auth/backend/file_test.rb +43 -0
- data/test/dav/auth/backend/mock.rb +73 -0
- data/test/dav/auth/backend/sequel_my_sql_test.rb +32 -0
- data/test/dav/auth/backend/sequel_sqlite_test.rb +21 -0
- data/test/dav/auth/plugin_test.rb +92 -0
- data/test/dav/basic_node_test.rb +143 -0
- data/test/dav/browser/guess_content_type_test.rb +44 -0
- data/test/dav/browser/map_get_to_prop_find_test.rb +37 -0
- data/test/dav/browser/plugin_test.rb +165 -0
- data/test/dav/browser/prop_find_all_test.rb +59 -0
- data/test/dav/client_mock.rb +24 -0
- data/test/dav/client_test.rb +231 -0
- data/test/dav/copy_test.rb +33 -0
- data/test/dav/exception/locked_test.rb +61 -0
- data/test/dav/exception/payment_required_test.rb +14 -0
- data/test/dav/exception/service_unavailable_test.rb +14 -0
- data/test/dav/exception/too_many_matches_test.rb +31 -0
- data/test/dav/exception_test.rb +24 -0
- data/test/dav/fs_ext/file_test.rb +72 -0
- data/test/dav/fs_ext/server_test.rb +251 -0
- data/test/dav/get_if_conditions_test.rb +299 -0
- data/test/dav/http_delete_test.rb +110 -0
- data/test/dav/http_get_test.rb +130 -0
- data/test/dav/http_head_test.rb +80 -0
- data/test/dav/http_move_test.rb +105 -0
- data/test/dav/http_prefer_parsing_test.rb +186 -0
- data/test/dav/http_put_test.rb +271 -0
- data/test/dav/issue33_test.rb +90 -0
- data/test/dav/locks/backend/abstract_test.rb +160 -0
- data/test/dav/locks/backend/file_test.rb +24 -0
- data/test/dav/locks/backend/mock.rb +82 -0
- data/test/dav/locks/backend/sequel_my_sql_test.rb +32 -0
- data/test/dav/locks/backend/sequel_test.rb +19 -0
- data/test/dav/locks/ms_word_test.rb +119 -0
- data/test/dav/locks/plugin2_test.rb +61 -0
- data/test/dav/locks/plugin_test.rb +896 -0
- data/test/dav/mock/collection.rb +113 -0
- data/test/dav/mock/file.rb +100 -0
- data/test/dav/mock/properties_collection.rb +80 -0
- data/test/dav/mock/streaming_file.rb +66 -0
- data/test/dav/mount/plugin_test.rb +48 -0
- data/test/dav/object_tree_test.rb +65 -0
- data/test/dav/partial_update/file_mock.rb +92 -0
- data/test/dav/partial_update/plugin_test.rb +125 -0
- data/test/dav/partial_update/specification_test.rb +77 -0
- data/test/dav/prop_find_test.rb +87 -0
- data/test/dav/prop_patch_test.rb +367 -0
- data/test/dav/property_storage/backend/abstract_sequel_test.rb +147 -0
- data/test/dav/property_storage/backend/mock.rb +96 -0
- data/test/dav/property_storage/backend/sequel_mysql_test.rb +32 -0
- data/test/dav/property_storage/backend/sequel_sqlite_test.rb +31 -0
- data/test/dav/property_storage/plugin_test.rb +90 -0
- data/test/dav/server_copy_move_test.rb +164 -0
- data/test/dav/server_events_test.rb +105 -0
- data/test/dav/server_mkcol_test.rb +337 -0
- data/test/dav/server_mock.rb +10 -0
- data/test/dav/server_plugin_test.rb +85 -0
- data/test/dav/server_precondition_test.rb +253 -0
- data/test/dav/server_props_infinite_depth_test.rb +144 -0
- data/test/dav/server_props_test.rb +182 -0
- data/test/dav/server_range_test.rb +262 -0
- data/test/dav/server_simple_test.rb +388 -0
- data/test/dav/server_update_properties_test.rb +93 -0
- data/test/dav/simple_file_test.rb +17 -0
- data/test/dav/string_util_test.rb +92 -0
- data/test/dav/sync/mock_sync_collection.rb +141 -0
- data/test/dav/sync/plugin_test.rb +491 -0
- data/test/dav/sync_token_property_test.rb +105 -0
- data/test/dav/temporary_file_filter_test.rb +179 -0
- data/test/dav/test_plugin.rb +24 -0
- data/test/dav/tree_test.rb +201 -0
- data/test/dav/uuid_util_test.rb +14 -0
- data/test/dav/xml/element/prop_test.rb +121 -0
- data/test/dav/xml/element/response_test.rb +202 -0
- data/test/dav/xml/property/href_test.rb +112 -0
- data/test/dav/xml/property/last_modified_test.rb +52 -0
- data/test/dav/xml/property/lock_discovery_test.rb +79 -0
- data/test/dav/xml/property/supported_method_set_test.rb +54 -0
- data/test/dav/xml/property/supported_report_set_test.rb +109 -0
- data/test/dav/xml/request/prop_find_test.rb +45 -0
- data/test/dav/xml/request/prop_patch_test.rb +47 -0
- data/test/dav/xml/request/sync_collection_test.rb +89 -0
- data/test/dav/xml/xml_tester.rb +35 -0
- data/test/dav_acl/acl_method_test.rb +299 -0
- data/test/dav_acl/allow_access_test.rb +94 -0
- data/test/dav_acl/block_access_test.rb +161 -0
- data/test/dav_acl/exception/ace_conflict_test.rb +33 -0
- data/test/dav_acl/exception/need_privileges_exception_test.rb +43 -0
- data/test/dav_acl/exception/no_abstract_test.rb +33 -0
- data/test/dav_acl/exception/not_recognized_principal_test.rb +33 -0
- data/test/dav_acl/exception/not_supported_privilege_test.rb +33 -0
- data/test/dav_acl/expand_properties_test.rb +265 -0
- data/test/dav_acl/fs/collection_test.rb +39 -0
- data/test/dav_acl/fs/file_test.rb +47 -0
- data/test/dav_acl/fs/home_collection_test.rb +82 -0
- data/test/dav_acl/mock_acl_node.rb +27 -0
- data/test/dav_acl/mock_principal.rb +27 -0
- data/test/dav_acl/plugin_admin_test.rb +60 -0
- data/test/dav_acl/plugin_properties_test.rb +346 -0
- data/test/dav_acl/plugin_update_properties_test.rb +82 -0
- data/test/dav_acl/principal_backend/abstract_sequel_test.rb +159 -0
- data/test/dav_acl/principal_backend/mock.rb +150 -0
- data/test/dav_acl/principal_backend/sequel_my_sql_test.rb +43 -0
- data/test/dav_acl/principal_backend/sequel_sqlite_test.rb +31 -0
- data/test/dav_acl/principal_collection_test.rb +44 -0
- data/test/dav_acl/principal_property_search_test.rb +354 -0
- data/test/dav_acl/principal_search_property_set_test.rb +125 -0
- data/test/dav_acl/principal_test.rb +181 -0
- data/test/dav_acl/simple_plugin_test.rb +320 -0
- data/test/dav_acl/xml/property/acl_restrictions_test.rb +28 -0
- data/test/dav_acl/xml/property/acl_test.rb +325 -0
- data/test/dav_acl/xml/property/current_user_privilege_set_test.rb +77 -0
- data/test/dav_acl/xml/property/principal_test.rb +158 -0
- data/test/dav_acl/xml/property/supported_privilege_set_test.rb +109 -0
- data/test/dav_server_test.rb +225 -0
- data/test/http/response_mock.rb +16 -0
- data/test/http/sapi_mock.rb +29 -0
- data/test/test_helper.rb +176 -0
- data/tilia-dav.gemspec +28 -0
- metadata +726 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tilia
|
2
|
+
module CalDav
|
3
|
+
module Notifications
|
4
|
+
# This node represents a list of notifications.
|
5
|
+
#
|
6
|
+
# It provides no additional functionality, but you must implement this
|
7
|
+
# interface to allow the Notifications plugin to mark the collection
|
8
|
+
# as a notifications collection.
|
9
|
+
#
|
10
|
+
# This collection should only return Sabre\CalDAV\Notifications\INode nodes as
|
11
|
+
# its children.
|
12
|
+
module ICollection
|
13
|
+
include Dav::ICollection
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Tilia
|
2
|
+
module CalDav
|
3
|
+
module Notifications
|
4
|
+
# This node represents a single notification.
|
5
|
+
#
|
6
|
+
# The signature is mostly identical to that of Sabre\DAV\IFile, but the get method
|
7
|
+
# MUST return an xml document that matches the requirements of the
|
8
|
+
# 'caldav-notifications.txt' spec.
|
9
|
+
#
|
10
|
+
# For a complete example, check out the Notification class, which contains
|
11
|
+
# some helper functions.
|
12
|
+
module INode
|
13
|
+
# This method must return an xml element, using the
|
14
|
+
# Sabre\CalDAV\Notifications\INotificationType classes.
|
15
|
+
#
|
16
|
+
# @return INotificationType
|
17
|
+
def notification_type
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the etag for the notification.
|
21
|
+
#
|
22
|
+
# The etag must be surrounded by litteral double-quotes.
|
23
|
+
#
|
24
|
+
# @return string
|
25
|
+
def etag
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Tilia
|
2
|
+
module CalDav
|
3
|
+
module Notifications
|
4
|
+
# This node represents a single notification.
|
5
|
+
#
|
6
|
+
# The signature is mostly identical to that of Sabre\DAV\IFile, but the get method
|
7
|
+
# MUST return an xml document that matches the requirements of the
|
8
|
+
# 'caldav-notifications.txt' spec.
|
9
|
+
class Node < Dav::File
|
10
|
+
include INode
|
11
|
+
include DavAcl::IAcl
|
12
|
+
|
13
|
+
# @!attribute [r] caldav_backend
|
14
|
+
# @!visibility private
|
15
|
+
# The notification backend
|
16
|
+
#
|
17
|
+
# @var Sabre\CalDAV\Backend\NotificationSupport
|
18
|
+
|
19
|
+
# @!attribute [r] notification
|
20
|
+
# @!visibility private
|
21
|
+
# The actual notification
|
22
|
+
#
|
23
|
+
# @var Sabre\CalDAV\Notifications\INotificationType
|
24
|
+
|
25
|
+
# @!attribute [r] principal_uri
|
26
|
+
# @!visibility private
|
27
|
+
# Owner principal of the notification
|
28
|
+
#
|
29
|
+
# @var string
|
30
|
+
|
31
|
+
# Constructor
|
32
|
+
#
|
33
|
+
# @param CalDAV\Backend\NotificationSupport caldav_backend
|
34
|
+
# @param string principal_uri
|
35
|
+
# @param NotificationInterface notification
|
36
|
+
def initialize(caldav_backend, principal_uri, notification)
|
37
|
+
@caldav_backend = caldav_backend
|
38
|
+
@principal_uri = principal_uri
|
39
|
+
@notification = notification
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the path name for this notification
|
43
|
+
#
|
44
|
+
# @return id
|
45
|
+
def name
|
46
|
+
@notification.id.to_s + '.xml'
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns the etag for the notification.
|
50
|
+
#
|
51
|
+
# The etag must be surrounded by litteral double-quotes.
|
52
|
+
#
|
53
|
+
# @return string
|
54
|
+
def etag
|
55
|
+
@notification.etag
|
56
|
+
end
|
57
|
+
|
58
|
+
# This method must return an xml element, using the
|
59
|
+
# Sabre\CalDAV\Notifications\INotificationType classes.
|
60
|
+
#
|
61
|
+
# @return INotificationType
|
62
|
+
def notification_type
|
63
|
+
@notification
|
64
|
+
end
|
65
|
+
|
66
|
+
# Deletes this notification
|
67
|
+
#
|
68
|
+
# @return void
|
69
|
+
def delete
|
70
|
+
@caldav_backend.delete_notification(owner, @notification)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the owner principal
|
74
|
+
#
|
75
|
+
# This must be a url to a principal, or null if there's no owner
|
76
|
+
#
|
77
|
+
# @return string|null
|
78
|
+
def owner
|
79
|
+
@principal_uri
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns a group principal
|
83
|
+
#
|
84
|
+
# This must be a url to a principal, or null if there's no owner
|
85
|
+
#
|
86
|
+
# @return string|null
|
87
|
+
def group
|
88
|
+
nil
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns a list of ACE's for this node.
|
92
|
+
#
|
93
|
+
# Each ACE has the following properties:
|
94
|
+
# * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
|
95
|
+
# currently the only supported privileges
|
96
|
+
# * 'principal', a url to the principal who owns the node
|
97
|
+
# * 'protected' (optional), indicating that this ACE is not allowed to
|
98
|
+
# be updated.
|
99
|
+
#
|
100
|
+
# @return array
|
101
|
+
def acl
|
102
|
+
[
|
103
|
+
{
|
104
|
+
'principal' => owner,
|
105
|
+
'privilege' => '{DAV:}read',
|
106
|
+
'protected' => true
|
107
|
+
},
|
108
|
+
{
|
109
|
+
'principal' => owner,
|
110
|
+
'privilege' => '{DAV:}write',
|
111
|
+
'protected' => true
|
112
|
+
}
|
113
|
+
]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Updates the ACL
|
117
|
+
#
|
118
|
+
# This method will receive a list of new ACE's as an array argument.
|
119
|
+
#
|
120
|
+
# @param array acl
|
121
|
+
# @return void
|
122
|
+
def acl=(_acl)
|
123
|
+
fail Dav::Exception::NotImplemented, 'Updating ACLs is not implemented here'
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns the list of supported privileges for this node.
|
127
|
+
#
|
128
|
+
# The returned data structure is a list of nested privileges.
|
129
|
+
# See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
|
130
|
+
# standard structure.
|
131
|
+
#
|
132
|
+
# If null is returned from this method, the default privilege set is used,
|
133
|
+
# which is fine for most common usecases.
|
134
|
+
#
|
135
|
+
# @return array|null
|
136
|
+
def supported_privilege_set
|
137
|
+
nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module Tilia
|
2
|
+
module CalDav
|
3
|
+
module Notifications
|
4
|
+
# Notifications plugin
|
5
|
+
#
|
6
|
+
# This plugin implements several features required by the caldav-notification
|
7
|
+
# draft specification.
|
8
|
+
#
|
9
|
+
# Before version 2.1.0 this functionality was part of Sabre\CalDAV\Plugin but
|
10
|
+
# this has since been split up.
|
11
|
+
class Plugin < Dav::ServerPlugin
|
12
|
+
# This is the namespace for the proprietary calendarserver extensions
|
13
|
+
NS_CALENDARSERVER = 'http://calendarserver.org/ns/'
|
14
|
+
|
15
|
+
# @!attribute [r] server
|
16
|
+
# @!visibility private
|
17
|
+
# Reference to the main server object.
|
18
|
+
#
|
19
|
+
# @var Server
|
20
|
+
|
21
|
+
# Returns a plugin name.
|
22
|
+
#
|
23
|
+
# Using this name other plugins will be able to access other plugins
|
24
|
+
# using \Sabre\DAV\Server::getPlugin
|
25
|
+
#
|
26
|
+
# @return string
|
27
|
+
def plugin_name
|
28
|
+
'notifications'
|
29
|
+
end
|
30
|
+
|
31
|
+
# This initializes the plugin.
|
32
|
+
#
|
33
|
+
# This function is called by Sabre\DAV\Server, after
|
34
|
+
# addPlugin is called.
|
35
|
+
#
|
36
|
+
# This method should set up the required event subscriptions.
|
37
|
+
#
|
38
|
+
# @param Server server
|
39
|
+
# @return void
|
40
|
+
def setup(server)
|
41
|
+
@server = server
|
42
|
+
@server.on('method:GET', method(:http_get), 90)
|
43
|
+
@server.on('propFind', method(:prop_find))
|
44
|
+
|
45
|
+
@server.xml.namespace_map[NS_CALENDARSERVER] = 'cs'
|
46
|
+
@server.resource_type_mapping[ICollection] = "{#{NS_CALENDARSERVER}}notification"
|
47
|
+
|
48
|
+
@server.protected_properties += [
|
49
|
+
"{#{NS_CALENDARSERVER}}notification-URL",
|
50
|
+
"{#{NS_CALENDARSERVER}}notificationtype"
|
51
|
+
]
|
52
|
+
end
|
53
|
+
|
54
|
+
# PropFind
|
55
|
+
#
|
56
|
+
# @param PropFind prop_find
|
57
|
+
# @param BaseINode node
|
58
|
+
# @return void
|
59
|
+
def prop_find(prop_find, node)
|
60
|
+
caldav_plugin = @server.plugin('caldav')
|
61
|
+
|
62
|
+
if node.is_a?(DavAcl::IPrincipal)
|
63
|
+
principal_url = node.principal_url
|
64
|
+
|
65
|
+
# notification-URL property
|
66
|
+
prop_find.handle(
|
67
|
+
"{#{NS_CALENDARSERVER}}notification-URL",
|
68
|
+
lambda do
|
69
|
+
notification_path = caldav_plugin.calendar_home_for_principal(principal_url) + '/notifications/'
|
70
|
+
return Dav::Xml::Property::Href.new(notification_path)
|
71
|
+
end
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
if node.is_a?(INode)
|
76
|
+
prop_find.handle(
|
77
|
+
"{#{NS_CALENDARSERVER}}notificationtype",
|
78
|
+
node.method(:notification_type)
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# This event is triggered before the usual GET request handler.
|
84
|
+
#
|
85
|
+
# We use this to intercept GET calls to notification nodes, and return the
|
86
|
+
# proper response.
|
87
|
+
#
|
88
|
+
# @param RequestInterface request
|
89
|
+
# @param ResponseInterface response
|
90
|
+
# @return void
|
91
|
+
def http_get(request, response)
|
92
|
+
path = request.path
|
93
|
+
|
94
|
+
begin
|
95
|
+
node = @server.tree.node_for_path(path)
|
96
|
+
rescue Dav::Exception::NotFound
|
97
|
+
return true
|
98
|
+
end
|
99
|
+
|
100
|
+
return true unless node.is_a?(INode)
|
101
|
+
|
102
|
+
writer = @server.xml.writer
|
103
|
+
writer.context_uri = @server.base_uri
|
104
|
+
writer.open_memory
|
105
|
+
writer.start_document
|
106
|
+
writer.start_element('{http://calendarserver.org/ns/}notification')
|
107
|
+
node.notification_type.xml_serialize_full(writer)
|
108
|
+
writer.end_element
|
109
|
+
|
110
|
+
response.update_header('Content-Type', 'application/xml')
|
111
|
+
response.update_header('ETag', node.etag)
|
112
|
+
response.status = 200
|
113
|
+
response.body = writer.output_memory
|
114
|
+
|
115
|
+
# Return false to break the event chain.
|
116
|
+
false
|
117
|
+
end
|
118
|
+
|
119
|
+
# Returns a bunch of meta-data about the plugin.
|
120
|
+
#
|
121
|
+
# Providing this information is optional, and is mainly displayed by the
|
122
|
+
# Browser plugin.
|
123
|
+
#
|
124
|
+
# The description key in the returned array may contain html and will not
|
125
|
+
# be sanitized.
|
126
|
+
#
|
127
|
+
# @return array
|
128
|
+
def plugin_info
|
129
|
+
{
|
130
|
+
'name' => plugin_name,
|
131
|
+
'description' => 'Adds support for caldav-notifications, which is required to enable caldav-sharing.',
|
132
|
+
'link' => 'http://sabre.io/dav/caldav-sharing/'
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,891 @@
|
|
1
|
+
module Tilia
|
2
|
+
module CalDav
|
3
|
+
# CalDAV plugin
|
4
|
+
#
|
5
|
+
# This plugin provides functionality added by CalDAV (RFC 4791)
|
6
|
+
# It implements new reports, and the MKCALENDAR method.
|
7
|
+
class Plugin < Dav::ServerPlugin
|
8
|
+
# This is the official CalDAV namespace
|
9
|
+
NS_CALDAV = 'urn:ietf:params:xml:ns:caldav'
|
10
|
+
|
11
|
+
# This is the namespace for the proprietary calendarserver extensions
|
12
|
+
NS_CALENDARSERVER = 'http://calendarserver.org/ns/'
|
13
|
+
|
14
|
+
# The hardcoded root for calendar objects. It is unfortunate
|
15
|
+
# that we're stuck with it, but it will have to do for now
|
16
|
+
CALENDAR_ROOT = 'calendars'
|
17
|
+
|
18
|
+
# @!attribute [r] server
|
19
|
+
# @!visibility private
|
20
|
+
# Reference to server object
|
21
|
+
#
|
22
|
+
# @var DAV\Server
|
23
|
+
|
24
|
+
# @!attribute [r] max_resource_size
|
25
|
+
# @!visibility private
|
26
|
+
# The default PDO storage uses a MySQL MEDIUMBLOB for iCalendar data,
|
27
|
+
# which can hold up to 2^24 = 16777216 bytes. This is plenty. We're
|
28
|
+
# capping it to 10M here.
|
29
|
+
|
30
|
+
# Use this method to tell the server this plugin defines additional
|
31
|
+
# HTTP methods.
|
32
|
+
#
|
33
|
+
# This method is passed a uri. It should only return HTTP methods that are
|
34
|
+
# available for the specified uri.
|
35
|
+
#
|
36
|
+
# @param string uri
|
37
|
+
# @return array
|
38
|
+
def http_methods(uri)
|
39
|
+
# The MKCALENDAR is only available on unmapped uri's, whose
|
40
|
+
# parents extend IExtendedCollection
|
41
|
+
(parent, name) = Uri.split(uri)
|
42
|
+
|
43
|
+
node = @server.tree.node_for_path(parent)
|
44
|
+
|
45
|
+
if node.is_a?(Dav::IExtendedCollection)
|
46
|
+
begin
|
47
|
+
node.child(name)
|
48
|
+
rescue Dav::Exception::NotFound
|
49
|
+
return ['MKCALENDAR']
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
[]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the path to a principal's calendar home.
|
57
|
+
#
|
58
|
+
# The return url must not end with a slash.
|
59
|
+
#
|
60
|
+
# @param string principal_url
|
61
|
+
# @return string
|
62
|
+
def calendar_home_for_principal(principal_url)
|
63
|
+
# The default is a bit naive, but it can be overwritten.
|
64
|
+
node_name = Uri.split(principal_url).second
|
65
|
+
|
66
|
+
CALENDAR_ROOT + '/' + node_name
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns a list of features for the DAV: HTTP header.
|
70
|
+
#
|
71
|
+
# @return array
|
72
|
+
def features
|
73
|
+
['calendar-access', 'calendar-proxy']
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns a plugin name.
|
77
|
+
#
|
78
|
+
# Using this name other plugins will be able to access other plugins
|
79
|
+
# using DAV\Server::getPlugin
|
80
|
+
#
|
81
|
+
# @return string
|
82
|
+
def plugin_name
|
83
|
+
'caldav'
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns a list of reports this plugin supports.
|
87
|
+
#
|
88
|
+
# This will be used in the {DAV:}supported-report-set property.
|
89
|
+
# Note that you still need to subscribe to the 'report' event to actually
|
90
|
+
# implement them
|
91
|
+
#
|
92
|
+
# @param string uri
|
93
|
+
# @return array
|
94
|
+
def supported_report_set(uri)
|
95
|
+
node = @server.tree.node_for_path(uri)
|
96
|
+
|
97
|
+
reports = []
|
98
|
+
if node.is_a?(ICalendarObjectContainer) || node.is_a?(ICalendarObject)
|
99
|
+
reports << "{#{NS_CALDAV}}calendar-multiget"
|
100
|
+
reports << "{#{NS_CALDAV}}calendar-query"
|
101
|
+
end
|
102
|
+
|
103
|
+
reports << "{#{NS_CALDAV}}free-busy-query" if node.is_a?(ICalendar)
|
104
|
+
|
105
|
+
# iCal has a bug where it assumes that sync support is enabled, only
|
106
|
+
# if we say we support it on the calendar-home, even though this is
|
107
|
+
# not actually the case.
|
108
|
+
if node.is_a?(CalendarHome) && @server.plugin('sync')
|
109
|
+
reports << '{DAV:}sync-collection'
|
110
|
+
end
|
111
|
+
|
112
|
+
reports
|
113
|
+
end
|
114
|
+
|
115
|
+
# Initializes the plugin
|
116
|
+
#
|
117
|
+
# @param DAV\Server server
|
118
|
+
# @return void
|
119
|
+
def setup(server)
|
120
|
+
@server = server
|
121
|
+
|
122
|
+
@server.on('method:MKCALENDAR', method(:http_mk_calendar))
|
123
|
+
@server.on('report', method(:report))
|
124
|
+
@server.on('propFind', method(:prop_find))
|
125
|
+
@server.on('onHTMLActionsPanel', method(:html_actions_panel))
|
126
|
+
@server.on('beforeCreateFile', method(:before_create_file))
|
127
|
+
@server.on('beforeWriteContent', method(:before_write_content))
|
128
|
+
@server.on('afterMethod:GET', method(:http_after_get))
|
129
|
+
|
130
|
+
@server.xml.namespace_map[NS_CALDAV] = 'cal'
|
131
|
+
@server.xml.namespace_map[NS_CALENDARSERVER] = 'cs'
|
132
|
+
|
133
|
+
@server.xml.element_map["{#{NS_CALDAV}}supported-calendar-component-set"] = Xml::Property::SupportedCalendarComponentSet
|
134
|
+
@server.xml.element_map["{#{NS_CALDAV}}calendar-query"] = Xml::Request::CalendarQueryReport
|
135
|
+
@server.xml.element_map["{#{NS_CALDAV}}calendar-multiget"] = Xml::Request::CalendarMultiGetReport
|
136
|
+
@server.xml.element_map["{#{NS_CALDAV}}free-busy-query"] = Xml::Request::FreeBusyQueryReport
|
137
|
+
@server.xml.element_map["{#{NS_CALDAV}}mkcalendar"] = Xml::Request::MkCalendar
|
138
|
+
@server.xml.element_map["{#{NS_CALDAV}}schedule-calendar-transp"] = Xml::Property::ScheduleCalendarTransp
|
139
|
+
@server.xml.element_map["{#{NS_CALDAV}}supported-calendar-component-set"] = Xml::Property::SupportedCalendarComponentSet
|
140
|
+
|
141
|
+
@server.resource_type_mapping[ICalendar] = '{urn:ietf:params:xml:ns:caldav}calendar'
|
142
|
+
|
143
|
+
@server.resource_type_mapping[Principal::IProxyRead] = '{http://calendarserver.org/ns/}calendar-proxy-read'
|
144
|
+
@server.resource_type_mapping[Principal::IProxyWrite] = '{http://calendarserver.org/ns/}calendar-proxy-write'
|
145
|
+
|
146
|
+
@server.protected_properties += [
|
147
|
+
"{#{NS_CALDAV}}supported-calendar-component-set",
|
148
|
+
"{#{NS_CALDAV}}supported-calendar-data",
|
149
|
+
"{#{NS_CALDAV}}max-resource-size",
|
150
|
+
"{#{NS_CALDAV}}min-date-time",
|
151
|
+
"{#{NS_CALDAV}}max-date-time",
|
152
|
+
"{#{NS_CALDAV}}max-instances",
|
153
|
+
"{#{NS_CALDAV}}max-attendees-per-instance",
|
154
|
+
"{#{NS_CALDAV}}calendar-home-set",
|
155
|
+
"{#{NS_CALDAV}}supported-collation-set",
|
156
|
+
"{#{NS_CALDAV}}calendar-data",
|
157
|
+
|
158
|
+
# CalendarServer extensions
|
159
|
+
"{#{NS_CALENDARSERVER}}getctag",
|
160
|
+
"{#{NS_CALENDARSERVER}}calendar-proxy-read-for",
|
161
|
+
"{#{NS_CALENDARSERVER}}calendar-proxy-write-for"
|
162
|
+
]
|
163
|
+
|
164
|
+
acl_plugin = @server.plugin('acl')
|
165
|
+
if acl_plugin
|
166
|
+
acl_plugin.principal_search_property_set["{#{NS_CALDAV}}calendar-user-address-set"] = 'Calendar address'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# This functions handles REPORT requests specific to CalDAV
|
171
|
+
#
|
172
|
+
# @param string report_name
|
173
|
+
# @param mixed report
|
174
|
+
# @param mixed _path
|
175
|
+
# @return bool
|
176
|
+
def report(report_name, report, _path)
|
177
|
+
case report_name
|
178
|
+
when "{#{NS_CALDAV}}calendar-multiget"
|
179
|
+
@server.transaction_type = 'report-calendar-multiget'
|
180
|
+
calendar_multi_get_report(report)
|
181
|
+
return false
|
182
|
+
when "{#{NS_CALDAV}}calendar-query"
|
183
|
+
@server.transaction_type = 'report-calendar-query'
|
184
|
+
calendar_query_report(report)
|
185
|
+
return false
|
186
|
+
when "{#{NS_CALDAV}}free-busy-query"
|
187
|
+
@server.transaction_type = 'report-free-busy-query'
|
188
|
+
free_busy_query_report(report)
|
189
|
+
return false
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# This function handles the MKCALENDAR HTTP method, which creates
|
194
|
+
# a new calendar.
|
195
|
+
#
|
196
|
+
# @param RequestInterface request
|
197
|
+
# @param ResponseInterface response
|
198
|
+
# @return bool
|
199
|
+
def http_mk_calendar(request, _response)
|
200
|
+
body = request.body_as_string
|
201
|
+
path = request.path
|
202
|
+
|
203
|
+
properties = {}
|
204
|
+
|
205
|
+
unless body.blank?
|
206
|
+
begin
|
207
|
+
mkcalendar = @server.xml.expect(
|
208
|
+
'{urn:ietf:params:xml:ns:caldav}mkcalendar',
|
209
|
+
body
|
210
|
+
)
|
211
|
+
rescue Tilia::Xml::ParseException => e
|
212
|
+
raise Dav::Exception::BadRequest, e.message
|
213
|
+
end
|
214
|
+
|
215
|
+
properties = mkcalendar.properties
|
216
|
+
end
|
217
|
+
|
218
|
+
# iCal abuses MKCALENDAR since iCal 10.9.2 to create server-stored
|
219
|
+
# subscriptions. Before that it used MKCOL which was the correct way
|
220
|
+
# to do this.
|
221
|
+
#
|
222
|
+
# If the body had a {DAV:}resourcetype, it means we stumbled upon this
|
223
|
+
# request, and we simply use it instead of the pre-defined list.
|
224
|
+
if properties.key?('{DAV:}resourcetype')
|
225
|
+
resource_type = properties['{DAV:}resourcetype'].value
|
226
|
+
else
|
227
|
+
resource_type = ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar']
|
228
|
+
end
|
229
|
+
|
230
|
+
@server.create_collection(path, Dav::MkCol.new(resource_type, properties))
|
231
|
+
|
232
|
+
@server.http_response.status = 201
|
233
|
+
@server.http_response.update_header('Content-Length', 0)
|
234
|
+
|
235
|
+
# This breaks the method chain.
|
236
|
+
false
|
237
|
+
end
|
238
|
+
|
239
|
+
# PropFind
|
240
|
+
#
|
241
|
+
# This method handler is invoked before any after properties for a
|
242
|
+
# resource are fetched. This allows us to add in any CalDAV specific
|
243
|
+
# properties.
|
244
|
+
#
|
245
|
+
# @param DAV\PropFind prop_find
|
246
|
+
# @param DAV\INode node
|
247
|
+
# @return void
|
248
|
+
def prop_find(prop_find, node)
|
249
|
+
ns = "{#{NS_CALDAV}}"
|
250
|
+
|
251
|
+
if node.is_a?(ICalendarObjectContainer)
|
252
|
+
prop_find.handle(ns + 'max-resource-size', @max_resource_size)
|
253
|
+
prop_find.handle(
|
254
|
+
ns + 'supported-calendar-data',
|
255
|
+
-> { Xml::Property::SupportedCalendarData.new }
|
256
|
+
)
|
257
|
+
prop_find.handle(
|
258
|
+
ns + 'supported-collation-set',
|
259
|
+
-> { Xml::Property::SupportedCollationSet.new }
|
260
|
+
)
|
261
|
+
end
|
262
|
+
|
263
|
+
if node.is_a?(DavAcl::IPrincipal)
|
264
|
+
principal_url = node.principal_url
|
265
|
+
|
266
|
+
prop_find.handle(
|
267
|
+
"{#{NS_CALDAV}}calendar-home-set",
|
268
|
+
lambda do
|
269
|
+
calendar_home_path = calendar_home_for_principal(principal_url) + '/'
|
270
|
+
return Dav::Xml::Property::Href.new(calendar_home_path)
|
271
|
+
end
|
272
|
+
)
|
273
|
+
|
274
|
+
# The calendar-user-address-set property is basically mapped to
|
275
|
+
# the {DAV:}alternate-URI-set property.
|
276
|
+
prop_find.handle(
|
277
|
+
"{#{NS_CALDAV}}calendar-user-address-set",
|
278
|
+
lambda do
|
279
|
+
addresses = node.alternate_uri_set
|
280
|
+
addresses << @server.base_uri + node.principal_url + '/'
|
281
|
+
return Dav::Xml::Property::Href.new(addresses, false)
|
282
|
+
end
|
283
|
+
)
|
284
|
+
# For some reason somebody thought it was a good idea to add
|
285
|
+
# another one of these properties. We're supporting it too.
|
286
|
+
prop_find.handle(
|
287
|
+
"{#{NS_CALENDARSERVER}}email-address-set",
|
288
|
+
lambda do
|
289
|
+
addresses = node.alternate_uri_set
|
290
|
+
emails = []
|
291
|
+
addresses.each do |address|
|
292
|
+
emails << address[7..-1] if address[0, 7] == 'mailto:'
|
293
|
+
end
|
294
|
+
|
295
|
+
return Xml::Property::EmailAddressSet.new(emails)
|
296
|
+
end
|
297
|
+
)
|
298
|
+
|
299
|
+
# These two properties are shortcuts for ical to easily find
|
300
|
+
# other principals this principal has access to.
|
301
|
+
prop_read = "{#{NS_CALENDARSERVER}}calendar-proxy-read-for"
|
302
|
+
prop_write = "{#{NS_CALENDARSERVER}}calendar-proxy-write-for"
|
303
|
+
|
304
|
+
if prop_find.status(prop_read) == 404 || prop_find.status(prop_write) == 404
|
305
|
+
acl_plugin = @server.plugin('acl')
|
306
|
+
membership = acl_plugin.principal_membership(prop_find.path)
|
307
|
+
|
308
|
+
read_list = []
|
309
|
+
write_list = []
|
310
|
+
membership.each do |group|
|
311
|
+
group_node = @server.tree.node_for_path(group)
|
312
|
+
|
313
|
+
list_item = Uri.split(group)[0] + '/'
|
314
|
+
|
315
|
+
# If the node is either ap proxy-read or proxy-write
|
316
|
+
# group, we grab the parent principal and add it to the
|
317
|
+
# list.
|
318
|
+
read_list << list_item if group_node.is_a?(Principal::IProxyRead)
|
319
|
+
if group_node.is_a?(Principal::IProxyWrite)
|
320
|
+
write_list << list_item
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
prop_find.set(prop_read, Dav::Xml::Property::Href.new(read_list))
|
325
|
+
prop_find.set(prop_write, Dav::Xml::Property::Href.new(write_list))
|
326
|
+
end
|
327
|
+
end # instanceof IPrincipal
|
328
|
+
|
329
|
+
if node.is_a?(ICalendarObject)
|
330
|
+
# The calendar-data property is not supposed to be a 'real'
|
331
|
+
# property, but in large chunks of the spec it does act as such.
|
332
|
+
# Therefore we simply expose it as a property.
|
333
|
+
prop_find.handle(
|
334
|
+
"{#{NS_CALDAV}}calendar-data",
|
335
|
+
lambda do
|
336
|
+
val = node.get
|
337
|
+
val = val.read unless val.is_a?(String)
|
338
|
+
|
339
|
+
# Taking out \r to not screw up the xml output
|
340
|
+
return val.delete("\r")
|
341
|
+
end
|
342
|
+
)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
# This function handles the calendar-multiget REPORT.
|
347
|
+
#
|
348
|
+
# This report is used by the client to fetch the content of a series
|
349
|
+
# of urls. Effectively avoiding a lot of redundant requests.
|
350
|
+
#
|
351
|
+
# @param CalendarMultiGetReport report
|
352
|
+
# @return void
|
353
|
+
def calendar_multi_get_report(report)
|
354
|
+
needs_json = report.content_type == 'application/calendar+json'
|
355
|
+
|
356
|
+
time_zones = {}
|
357
|
+
property_list = []
|
358
|
+
|
359
|
+
paths = report.hrefs.map { |h| @server.calculate_uri(h) }
|
360
|
+
|
361
|
+
@server.properties_for_multiple_paths(paths, report.properties).each do |uri, obj_props|
|
362
|
+
if (needs_json || report.expand) && obj_props[200].key?("{#{NS_CALDAV}}calendar-data")
|
363
|
+
v_object = VObject::Reader.read(obj_props[200]["{#{NS_CALDAV}}calendar-data"])
|
364
|
+
|
365
|
+
if report.expand
|
366
|
+
# We're expanding, and for that we need to figure out the
|
367
|
+
# calendar's timezone.
|
368
|
+
calendar_path = Uri.split(uri).first
|
369
|
+
|
370
|
+
unless time_zones.key?(calendar_path)
|
371
|
+
# Checking the calendar-timezone property.
|
372
|
+
tz_prop = "{#{NS_CALDAV}}calendar-timezone"
|
373
|
+
tz_result = @server.properties(calendar_path, [tz_prop])
|
374
|
+
|
375
|
+
if tz_result.key?(tz_prop)
|
376
|
+
# This property contains a VCALENDAR with a single
|
377
|
+
# VTIMEZONE.
|
378
|
+
vtimezone_obj = VObject::Reader.read(tz_result[tz_prop])
|
379
|
+
time_zone = vtimezone_obj['VTIMEZONE'].time_zone
|
380
|
+
else
|
381
|
+
# Defaulting to UTC.
|
382
|
+
time_zone = ActiveSupport::TimeZone.new('UTC')
|
383
|
+
end
|
384
|
+
|
385
|
+
time_zones[calendar_path] = time_zone
|
386
|
+
end
|
387
|
+
|
388
|
+
v_object.expand(report.expand['start'], report.expand['end'], time_zones[calendar_path])
|
389
|
+
end
|
390
|
+
|
391
|
+
if needs_json
|
392
|
+
obj_props[200]["{#{NS_CALDAV}}calendar-data"] = v_object.json_serialize.to_json
|
393
|
+
else
|
394
|
+
obj_props[200]["{#{NS_CALDAV}}calendar-data"] = v_object.serialize
|
395
|
+
end
|
396
|
+
|
397
|
+
# Destroy circular references so PHP will garbage collect the
|
398
|
+
# object.
|
399
|
+
v_object.destroy
|
400
|
+
end
|
401
|
+
|
402
|
+
property_list << obj_props
|
403
|
+
end
|
404
|
+
|
405
|
+
prefer = @server.http_prefer
|
406
|
+
|
407
|
+
@server.http_response.status = 207
|
408
|
+
@server.http_response.update_header('Content-Type', 'application/xml; charset=utf-8')
|
409
|
+
@server.http_response.update_header('Vary', 'Brief,Prefer')
|
410
|
+
@server.http_response.body = @server.generate_multi_status(property_list, prefer['return'] == 'minimal')
|
411
|
+
end
|
412
|
+
|
413
|
+
# This function handles the calendar-query REPORT
|
414
|
+
#
|
415
|
+
# This report is used by clients to request calendar objects based on
|
416
|
+
# complex conditions.
|
417
|
+
#
|
418
|
+
# @param Xml\Request\CalendarQueryReport report
|
419
|
+
# @return void
|
420
|
+
def calendar_query_report(report)
|
421
|
+
path = @server.request_uri
|
422
|
+
|
423
|
+
needs_json = report.content_type == 'application/calendar+json'
|
424
|
+
|
425
|
+
node = @server.tree.node_for_path(@server.request_uri)
|
426
|
+
depth = @server.http_depth(0)
|
427
|
+
|
428
|
+
# The default result is an empty array
|
429
|
+
result = []
|
430
|
+
|
431
|
+
calendar_time_zone = nil
|
432
|
+
if report.expand
|
433
|
+
# We're expanding, and for that we need to figure out the
|
434
|
+
# calendar's timezone.
|
435
|
+
tz_prop = "{#{NS_CALDAV}}calendar-timezone"
|
436
|
+
tz_result = @server.properties(path, [tz_prop])
|
437
|
+
|
438
|
+
if tz_result.key?(tz_prop)
|
439
|
+
# This property contains a VCALENDAR with a single
|
440
|
+
# VTIMEZONE.
|
441
|
+
vtimezone_obj = VObject::Reader.read(tz_result[tz_prop])
|
442
|
+
calendar_time_zone = vtimezone_obj['VTIMEZONE'].time_zone
|
443
|
+
|
444
|
+
# Destroy circular references so PHP will garbage collect the
|
445
|
+
# object.
|
446
|
+
vtimezone_obj.destroy
|
447
|
+
else
|
448
|
+
# Defaulting to UTC.
|
449
|
+
calendar_time_zone = ActiveSupport::TimeZone.new('UTC')
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
# The calendarobject was requested directly. In this case we handle
|
454
|
+
# this locally.
|
455
|
+
if depth == 0 && node.is_a?(ICalendarObject)
|
456
|
+
requested_calendar_data = true
|
457
|
+
requested_properties = report.properties
|
458
|
+
|
459
|
+
unless requested_properties.include?('{urn:ietf:params:xml:ns:caldav}calendar-data')
|
460
|
+
# We always retrieve calendar-data, as we need it for filtering.
|
461
|
+
requested_properties << '{urn:ietf:params:xml:ns:caldav}calendar-data'
|
462
|
+
|
463
|
+
# If calendar-data wasn't explicitly requested, we need to remove
|
464
|
+
# it after processing.
|
465
|
+
requested_calendar_data = false
|
466
|
+
end
|
467
|
+
|
468
|
+
properties = @server.properties_for_path(
|
469
|
+
path,
|
470
|
+
requested_properties,
|
471
|
+
0
|
472
|
+
)
|
473
|
+
|
474
|
+
# This array should have only 1 element, the first calendar
|
475
|
+
# object.
|
476
|
+
properties = properties.first
|
477
|
+
|
478
|
+
# If there wasn't any calendar-data returned somehow, we ignore
|
479
|
+
# this.
|
480
|
+
if properties[200].key?('{urn:ietf:params:xml:ns:caldav}calendar-data')
|
481
|
+
validator = CalendarQueryValidator.new
|
482
|
+
|
483
|
+
v_object = VObject::Reader.read(properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])
|
484
|
+
if validator.validate(v_object, report.filters)
|
485
|
+
# If the client didn't require the calendar-data property,
|
486
|
+
# we won't give it back.
|
487
|
+
if !requested_calendar_data
|
488
|
+
properties[200].delete('{urn:ietf:params:xml:ns:caldav}calendar-data')
|
489
|
+
else
|
490
|
+
v_object.expand(report.expand['start'], report.expand['end'], calendar_time_zone) if report.expand
|
491
|
+
|
492
|
+
if needs_json
|
493
|
+
properties[200]["{#{NS_CALDAV}}calendar-data"] = v_object.json_serialize.to_json
|
494
|
+
elsif report.expand
|
495
|
+
properties[200]["{#{NS_CALDAV}}calendar-data"] = v_object.serialize
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
result = [properties]
|
500
|
+
end
|
501
|
+
|
502
|
+
# Destroy circular references so PHP will garbage collect the
|
503
|
+
# object.
|
504
|
+
v_object.destroy
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
if node.is_a?(ICalendarObjectContainer) && depth == 0
|
509
|
+
if @server.http_request.header('User-Agent').to_s.index('MSFT-WP/') == 0
|
510
|
+
# Windows phone incorrectly supplied depth as 0, when it actually
|
511
|
+
# should have set depth to 1. We're implementing a workaround here
|
512
|
+
# to deal with this.
|
513
|
+
depth = 1
|
514
|
+
else
|
515
|
+
fail Dav::Exception::BadRequest, 'A calendar-query REPORT on a calendar with a Depth: 0 is undefined. Set Depth to 1'
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
# If we're dealing with a calendar, the calendar itself is responsible
|
520
|
+
# for the calendar-query.
|
521
|
+
if node.is_a?(ICalendarObjectContainer) && depth == 1
|
522
|
+
node_paths = node.calendar_query(report.filters)
|
523
|
+
|
524
|
+
node_paths.each do |path|
|
525
|
+
properties = @server.properties_for_path(@server.request_uri + '/' + path, report.properties).first
|
526
|
+
|
527
|
+
if needs_json || report.expand
|
528
|
+
v_object = VObject::Reader.read(properties[200]["{#{NS_CALDAV}}calendar-data"])
|
529
|
+
|
530
|
+
v_object.expand(report.expand['start'], report.expand['end'], calendar_time_zone) if report.expand
|
531
|
+
|
532
|
+
if needs_json
|
533
|
+
properties[200]["{#{NS_CALDAV}}calendar-data"] = v_object.json_serialize.to_json
|
534
|
+
else
|
535
|
+
properties[200]["{#{NS_CALDAV}}calendar-data"] = v_object.serialize
|
536
|
+
end
|
537
|
+
|
538
|
+
# Destroy circular references so PHP will garbage collect the
|
539
|
+
# object.
|
540
|
+
v_object.destroy
|
541
|
+
end
|
542
|
+
|
543
|
+
result << properties
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
prefer = @server.http_prefer
|
548
|
+
|
549
|
+
@server.http_response.status = 207
|
550
|
+
@server.http_response.update_header('Content-Type', 'application/xml; charset=utf-8')
|
551
|
+
@server.http_response.update_header('Vary', 'Brief,Prefer')
|
552
|
+
@server.http_response.body = @server.generate_multi_status(result, prefer['return'] == 'minimal')
|
553
|
+
end
|
554
|
+
|
555
|
+
protected
|
556
|
+
|
557
|
+
# This method is responsible for parsing the request and generating the
|
558
|
+
# response for the CALDAV:free-busy-query REPORT.
|
559
|
+
#
|
560
|
+
# @param Xml\Request\FreeBusyQueryReport report
|
561
|
+
# @return void
|
562
|
+
def free_busy_query_report(report)
|
563
|
+
uri = @server.request_uri
|
564
|
+
|
565
|
+
acl = @server.plugin('acl')
|
566
|
+
acl.check_privileges(uri, "{#{NS_CALDAV}}read-free-busy") if acl
|
567
|
+
|
568
|
+
calendar = @server.tree.node_for_path(uri)
|
569
|
+
fail Dav::Exception::NotImplemented, 'The free-busy-query REPORT is only implemented on calendars' unless calendar.is_a?(ICalendar)
|
570
|
+
|
571
|
+
tz_prop = "{#{NS_CALDAV}}calendar-timezone"
|
572
|
+
|
573
|
+
# Figuring out the default timezone for the calendar, for floating
|
574
|
+
# times.
|
575
|
+
calendar_props = @server.properties(uri, [tz_prop])
|
576
|
+
|
577
|
+
if calendar_props.key?(tz_prop)
|
578
|
+
vtimezone_obj = VObject::Reader.read(calendar_props[tz_prop])
|
579
|
+
calendar_time_zone = vtimezone_obj['VTIMEZONE'].time_zone
|
580
|
+
# Destroy circular references so PHP will garbage collect the object.
|
581
|
+
vtimezone_obj.destroy
|
582
|
+
else
|
583
|
+
calendar_time_zone = ActiveSupport::TimeZone.new('UTC')
|
584
|
+
end
|
585
|
+
|
586
|
+
# Doing a calendar-query first, to make sure we get the most
|
587
|
+
# performance.
|
588
|
+
urls = calendar.calendar_query(
|
589
|
+
'name' => 'VCALENDAR',
|
590
|
+
'comp-filters' => [
|
591
|
+
{
|
592
|
+
'name' => 'VEVENT',
|
593
|
+
'comp-filters' => [],
|
594
|
+
'prop-filters' => [],
|
595
|
+
'is-not-defined' => false,
|
596
|
+
'time-range' => {
|
597
|
+
'start' => report.start,
|
598
|
+
'end' => report.end
|
599
|
+
}
|
600
|
+
}
|
601
|
+
],
|
602
|
+
'prop-filters' => [],
|
603
|
+
'is-not-defined' => false,
|
604
|
+
'time-range' => nil
|
605
|
+
)
|
606
|
+
|
607
|
+
objects = urls.map { |url| calendar.child(url).get }
|
608
|
+
|
609
|
+
generator = VObject::FreeBusyGenerator.new
|
610
|
+
generator.objects = objects
|
611
|
+
generator.time_range = report.start..report.end
|
612
|
+
generator.time_zone = calendar_time_zone
|
613
|
+
|
614
|
+
result = generator.result
|
615
|
+
result = result.serialize
|
616
|
+
|
617
|
+
@server.http_response.status = 200
|
618
|
+
@server.http_response.update_header('Content-Type', 'text/calendar')
|
619
|
+
@server.http_response.update_header('Content-Length', result.bytesize)
|
620
|
+
@server.http_response.body = result
|
621
|
+
end
|
622
|
+
|
623
|
+
public
|
624
|
+
|
625
|
+
# This method is triggered before a file gets updated with new content.
|
626
|
+
#
|
627
|
+
# This plugin uses this method to ensure that CalDAV objects receive
|
628
|
+
# valid calendar data.
|
629
|
+
#
|
630
|
+
# @param string path
|
631
|
+
# @param DAV\IFile node
|
632
|
+
# @param [Box] data
|
633
|
+
# @param [Box<bool>] modified Should be set to true, if this event handler
|
634
|
+
# changed &data.
|
635
|
+
# @return void
|
636
|
+
def before_write_content(path, node, data, modified)
|
637
|
+
return true unless node.is_a?(ICalendarObject)
|
638
|
+
|
639
|
+
# We're onyl interested in ICalendarObject nodes that are inside of a
|
640
|
+
# real calendar. This is to avoid triggering validation and scheduling
|
641
|
+
# for non-calendars (such as an inbox).
|
642
|
+
parent = Uri.split(path).first
|
643
|
+
parent_node = @server.tree.node_for_path(parent)
|
644
|
+
|
645
|
+
return true unless parent_node.is_a?(ICalendar)
|
646
|
+
|
647
|
+
validate_i_calendar(
|
648
|
+
data,
|
649
|
+
path,
|
650
|
+
modified,
|
651
|
+
@server.http_request,
|
652
|
+
@server.http_response,
|
653
|
+
false
|
654
|
+
)
|
655
|
+
true
|
656
|
+
end
|
657
|
+
|
658
|
+
# This method is triggered before a new file is created.
|
659
|
+
#
|
660
|
+
# This plugin uses this method to ensure that newly created calendar
|
661
|
+
# objects contain valid calendar data.
|
662
|
+
#
|
663
|
+
# @param string path
|
664
|
+
# @param [Box] data
|
665
|
+
# @param DAV\ICollection parent_node
|
666
|
+
# @param [Box<bool>] modified Should be set to true, if this event handler
|
667
|
+
# changed &data.
|
668
|
+
# @return void
|
669
|
+
def before_create_file(path, data, parent_node, modified)
|
670
|
+
return true unless parent_node.is_a?(ICalendar)
|
671
|
+
|
672
|
+
validate_i_calendar(
|
673
|
+
data,
|
674
|
+
path,
|
675
|
+
modified,
|
676
|
+
@server.http_request,
|
677
|
+
@server.http_response,
|
678
|
+
true
|
679
|
+
)
|
680
|
+
true
|
681
|
+
end
|
682
|
+
|
683
|
+
protected
|
684
|
+
|
685
|
+
# Checks if the submitted iCalendar data is in fact, valid.
|
686
|
+
#
|
687
|
+
# An exception is thrown if it's not.
|
688
|
+
#
|
689
|
+
# @param [Box] data
|
690
|
+
# @param string path
|
691
|
+
# @param [Box<bool>] modified Should be set to true, if this event handler
|
692
|
+
# changed &data.
|
693
|
+
# @param RequestInterface request The http request.
|
694
|
+
# @param ResponseInterface response The http response.
|
695
|
+
# @param bool is_new Is the item a new one, or an update.
|
696
|
+
# @return void
|
697
|
+
def validate_i_calendar(data_box, path, modified_box, request, response, is_new)
|
698
|
+
data = data_box.value
|
699
|
+
modified = modified_box.value
|
700
|
+
|
701
|
+
# If it's a stream, we convert it to a string first.
|
702
|
+
data = data.read unless data.is_a?(String)
|
703
|
+
|
704
|
+
before = Digest::MD5.hexdigest(data)
|
705
|
+
|
706
|
+
# Converting the data to unicode, if needed.
|
707
|
+
data = Dav::StringUtil.ensure_utf8(data)
|
708
|
+
|
709
|
+
modified = true unless before == Digest::MD5.hexdigest(data)
|
710
|
+
|
711
|
+
begin
|
712
|
+
# If the data starts with a [, we can reasonably assume we're dealing
|
713
|
+
# with a jCal object.
|
714
|
+
if data[0] == '['
|
715
|
+
vobj = VObject::Reader.read_json(data)
|
716
|
+
|
717
|
+
# Converting data back to iCalendar, as that's what we
|
718
|
+
# technically support everywhere.
|
719
|
+
data = vobj.serialize
|
720
|
+
modified = true
|
721
|
+
else
|
722
|
+
vobj = VObject::Reader.read(data)
|
723
|
+
end
|
724
|
+
rescue VObject::ParseException => e
|
725
|
+
raise Dav::Exception::UnsupportedMediaType, "This resource only supports valid iCalendar 2.0 data. Parse error: #{e.message}"
|
726
|
+
end
|
727
|
+
|
728
|
+
fail Dav::Exception::UnsupportedMediaType, 'This collection can only support iCalendar objects.' if vobj.name != 'VCALENDAR'
|
729
|
+
|
730
|
+
s_ccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'
|
731
|
+
|
732
|
+
# Get the Supported Components for the target calendar
|
733
|
+
parent_path = Uri.split(path).first
|
734
|
+
calendar_properties = @server.properties(parent_path, [s_ccs])
|
735
|
+
|
736
|
+
if calendar_properties.key?(s_ccs)
|
737
|
+
supported_components = calendar_properties[s_ccs].value
|
738
|
+
else
|
739
|
+
supported_components = ['VJOURNAL', 'VTODO', 'VEVENT']
|
740
|
+
end
|
741
|
+
|
742
|
+
found_type = nil
|
743
|
+
found_uid = nil
|
744
|
+
vobj.components.each do |component|
|
745
|
+
case component.name
|
746
|
+
when 'VTIMEZONE'
|
747
|
+
next
|
748
|
+
when 'VEVENT', 'VTODO', 'VJOURNAL'
|
749
|
+
if found_type.nil?
|
750
|
+
found_type = component.name
|
751
|
+
unless supported_components.include?(found_type)
|
752
|
+
fail Exception::InvalidComponentType, "This calendar only supports #{supported_components.join(', ')}. We found a #{found_type}"
|
753
|
+
end
|
754
|
+
unless component.key?('UID')
|
755
|
+
fail Dav::Exception::BadRequest, "Every #{component.name} component must have an UID"
|
756
|
+
end
|
757
|
+
|
758
|
+
found_uid = component['UID'].to_s
|
759
|
+
else
|
760
|
+
unless found_type == component.name
|
761
|
+
fail Dav::Exception::BadRequest, "A calendar object must only contain 1 component. We found a #{component.name} as well as a #{found_type}"
|
762
|
+
end
|
763
|
+
unless found_uid == component['UID'].to_s
|
764
|
+
fail Dav::Exception::BadRequest, "Every #{component.name} in this object must have identical UIDs"
|
765
|
+
end
|
766
|
+
end
|
767
|
+
else
|
768
|
+
fail Dav::Exception::BadRequest, "You are not allowed to create components of type: #{component.name} here"
|
769
|
+
end
|
770
|
+
end
|
771
|
+
|
772
|
+
fail Dav::Exception::BadRequest, 'iCalendar object must contain at least 1 of VEVENT, VTODO or VJOURNAL' unless found_type
|
773
|
+
|
774
|
+
# We use an extra variable to allow event handles to tell us wether
|
775
|
+
# the object was modified or not.
|
776
|
+
#
|
777
|
+
# This helps us determine if we need to re-serialize the object.
|
778
|
+
sub_modified = Box.new(false)
|
779
|
+
|
780
|
+
@server.emit(
|
781
|
+
'calendarObjectChange',
|
782
|
+
[
|
783
|
+
request,
|
784
|
+
response,
|
785
|
+
vobj,
|
786
|
+
parent_path,
|
787
|
+
sub_modified,
|
788
|
+
is_new
|
789
|
+
]
|
790
|
+
)
|
791
|
+
|
792
|
+
if sub_modified.value
|
793
|
+
# An event handler told us that it modified the object.
|
794
|
+
data = vobj.serialize
|
795
|
+
|
796
|
+
# Using md5 to figure out if there was an *actual* change.
|
797
|
+
modified = true if !modified && before != Digest::MD5.hexdigest(data)
|
798
|
+
end
|
799
|
+
|
800
|
+
# Destroy circular references so PHP will garbage collect the object.
|
801
|
+
vobj.destroy
|
802
|
+
|
803
|
+
# Update boxes
|
804
|
+
modified_box.value = modified
|
805
|
+
data_box.value = data
|
806
|
+
end
|
807
|
+
|
808
|
+
public
|
809
|
+
|
810
|
+
# This method is used to generate HTML output for the
|
811
|
+
# DAV\Browser\Plugin. This allows us to generate an interface users
|
812
|
+
# can use to create new calendars.
|
813
|
+
#
|
814
|
+
# @param DAV\INode node
|
815
|
+
# @param string output
|
816
|
+
# @return bool
|
817
|
+
def html_actions_panel(node, output)
|
818
|
+
return true unless node.is_a?(CalendarHome)
|
819
|
+
|
820
|
+
output.value = <<HTML
|
821
|
+
<tr><td colspan="2"><form method="post" action="">
|
822
|
+
<h3>Create new calendar</h3>
|
823
|
+
<input type="hidden" name="sabreAction" value="mkcol" />
|
824
|
+
<input type="hidden" name="resourceType" value="{DAV:}collection,{#{NS_CALDAV}}calendar" />
|
825
|
+
<label>Name (uri):</label> <input type="text" name="name" /><br />
|
826
|
+
<label>Display name:</label> <input type="text" name="{DAV:}displayname" /><br />
|
827
|
+
<input type="submit" value="create" />
|
828
|
+
</form>
|
829
|
+
</td></tr>
|
830
|
+
HTML
|
831
|
+
|
832
|
+
false
|
833
|
+
end
|
834
|
+
|
835
|
+
# This event is triggered after GET requests.
|
836
|
+
#
|
837
|
+
# This is used to transform data into jCal, if this was requested.
|
838
|
+
#
|
839
|
+
# @param RequestInterface request
|
840
|
+
# @param ResponseInterface response
|
841
|
+
# @return void
|
842
|
+
def http_after_get(request, response)
|
843
|
+
return unless response.header('Content-Type').index('text/calendar')
|
844
|
+
|
845
|
+
result = Http::Util.negotiate(
|
846
|
+
request.header('Accept'),
|
847
|
+
['text/calendar', 'application/calendar+json']
|
848
|
+
)
|
849
|
+
|
850
|
+
unless result == 'application/calendar+json'
|
851
|
+
# Do nothing
|
852
|
+
return
|
853
|
+
end
|
854
|
+
|
855
|
+
# Transforming.
|
856
|
+
vobj = VObject::Reader.read(response.body)
|
857
|
+
|
858
|
+
json_body = vobj.json_serialize.to_json
|
859
|
+
response.body = json_body
|
860
|
+
|
861
|
+
# Destroy circular references so PHP will garbage collect the object.
|
862
|
+
vobj.destroy
|
863
|
+
|
864
|
+
response.update_header('Content-Type', 'application/calendar+json')
|
865
|
+
response.update_header('Content-Length', json_body.bytesize)
|
866
|
+
end
|
867
|
+
|
868
|
+
# Returns a bunch of meta-data about the plugin.
|
869
|
+
#
|
870
|
+
# Providing this information is optional, and is mainly displayed by the
|
871
|
+
# Browser plugin.
|
872
|
+
#
|
873
|
+
# The description key in the returned array may contain html and will not
|
874
|
+
# be sanitized.
|
875
|
+
#
|
876
|
+
# @return array
|
877
|
+
def plugin_info
|
878
|
+
{
|
879
|
+
'name' => plugin_name,
|
880
|
+
'description' => 'Adds support for CalDAV (rfc4791)',
|
881
|
+
'link' => 'http://sabre.io/dav/caldav/'
|
882
|
+
}
|
883
|
+
end
|
884
|
+
|
885
|
+
# Sets the instance variables
|
886
|
+
def initialize
|
887
|
+
@max_resource_size = 10_000_000
|
888
|
+
end
|
889
|
+
end
|
890
|
+
end
|
891
|
+
end
|