Some preparation to parse CalDAV REPORT requests with calendar-data

This commit is contained in:
Lennart
2025-04-27 15:09:28 +02:00
parent 19708b7951
commit 3b58d73b58
6 changed files with 128 additions and 44 deletions

View File

@@ -1,12 +1,12 @@
use crate::Error;
use actix_web::{
web::{Data, Path},
HttpRequest, Responder,
web::{Data, Path},
};
use calendar_multiget::{handle_calendar_multiget, CalendarMultigetRequest};
use calendar_query::{handle_calendar_query, CalendarQueryRequest};
use rustical_dav::xml::sync_collection::SyncCollectionRequest;
use rustical_store::{auth::User, CalendarStore};
use calendar_multiget::{CalendarMultigetRequest, handle_calendar_multiget};
use calendar_query::{CalendarQueryRequest, handle_calendar_query};
use rustical_dav::xml::{Propname, sync_collection::SyncCollectionRequest};
use rustical_store::{CalendarStore, auth::User};
use rustical_xml::{XmlDeserialize, XmlDocument};
use sync_collection::handle_sync_collection;
use tracing::instrument;
@@ -15,6 +15,34 @@ mod calendar_multiget;
mod calendar_query;
mod sync_collection;
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
pub(crate) struct ExpandElement {
#[xml(ty = "attr")]
start: String,
#[xml(ty = "attr")]
end: String,
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
pub struct CalendarData {
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
comp: Option<()>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
expand: Option<ExpandElement>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
limit_recurrence_set: Option<()>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
limit_freebusy_set: Option<()>,
}
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
pub enum ReportPropName {
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
CalendarData(CalendarData),
#[xml(other)]
Propname(Propname),
}
#[derive(XmlDeserialize, XmlDocument, Clone, Debug, PartialEq)]
pub(crate) enum ReportRequest {
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
@@ -22,7 +50,7 @@ pub(crate) enum ReportRequest {
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
CalendarQuery(CalendarQueryRequest),
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
SyncCollection(SyncCollectionRequest),
SyncCollection(SyncCollectionRequest<ReportPropName>),
}
#[instrument(skip(req, cal_store))]
@@ -79,12 +107,42 @@ pub async fn route_report_calendar<C: CalendarStore>(
#[cfg(test)]
mod tests {
use super::*;
use calendar_query::{CompFilterElement, FilterElement, TimeRangeElement};
use rustical_dav::xml::{PropElement, PropfindType, Propname};
use rustical_store::calendar::UtcDateTime;
use rustical_xml::ValueDeserialize;
use super::*;
#[test]
fn test_xml_calendar_data() {
let report_request = ReportRequest::parse_str(r#"
<?xml version="1.0" encoding="UTF-8"?>
<calendar-multiget xmlns="urn:ietf:params:xml:ns:caldav" xmlns:D="DAV:">
<D:prop>
<D:getetag/>
<D:displayname/>
<calendar-data>
<expand start="20250426T220000Z" end="20250503T220000Z"/>
</calendar-data>
</D:prop>
<D:href>/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b</D:href>
</calendar-multiget>
"#).unwrap();
assert_eq!(
report_request,
ReportRequest::CalendarMultiget(CalendarMultigetRequest {
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
ReportPropName::Propname(Propname("getetag".to_owned())),
ReportPropName::Propname(Propname("displayname".to_owned())),
ReportPropName::CalendarData(CalendarData { comp: None, expand: Some(ExpandElement { start: "20250426T220000Z".to_owned(), end: "20250503T220000Z".to_owned() }), limit_recurrence_set: None, limit_freebusy_set: None })
])),
href: vec![
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
]
})
)
}
#[test]
fn test_xml_calendar_query() {
@@ -108,7 +166,9 @@ mod tests {
assert_eq!(
report_request,
ReportRequest::CalendarQuery(CalendarQueryRequest {
prop: PropfindType::Prop(PropElement(vec![Propname("getetag".to_owned())])),
prop: PropfindType::Prop(PropElement(vec![ReportPropName::Propname(Propname(
"getetag".to_owned()
))])),
filter: Some(FilterElement {
comp_filter: CompFilterElement {
is_not_defined: None,
@@ -155,8 +215,8 @@ mod tests {
report_request,
ReportRequest::CalendarMultiget(CalendarMultigetRequest {
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
Propname("getetag".to_owned()),
Propname("displayname".to_owned())
ReportPropName::Propname(Propname("getetag".to_owned())),
ReportPropName::Propname(Propname("displayname".to_owned()))
])),
href: vec![
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()