Skip to content

Commit

Permalink
caldav: some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart-k committed Jan 4, 2025
1 parent 745013b commit 9a5314c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 41 deletions.
56 changes: 15 additions & 41 deletions crates/caldav/src/calendar/methods/mkcalendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,34 @@ use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
use tracing::instrument;
use tracing_actix_web::RootSpan;

#[derive(XmlDeserialize, Clone, Debug)]
pub struct Resourcetype {
calendar: Option<()>,
collection: Option<()>,
}

#[derive(XmlDeserialize, Clone, Debug)]
pub struct CalendarComponentElement {
#[xml(ty = "attr")]
name: String,
}

#[derive(XmlDeserialize, Clone, Debug)]
pub struct SupportedCalendarComponentSetElement {
#[xml(flatten)]
comp: Vec<CalendarComponentElement>,
}

#[derive(XmlDeserialize, Clone, Debug)]
pub struct MkcolCalendarProp {
// TODO: Add namespaces
resourcetype: Option<Resourcetype>,
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
displayname: Option<String>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
calendar_description: Option<String>,
#[xml(ns = "rustical_dav::namespace::NS_ICAL")]
calendar_color: Option<String>,
order: Option<i64>,
#[xml(ns = "rustical_dav::namespace::NS_ICAL")]
calendar_order: Option<i64>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
calendar_timezone: Option<String>,
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
calendar_timezone_id: Option<String>,
supported_calendar_component_set: Option<SupportedCalendarComponentSetElement>,
}

#[derive(XmlDeserialize, Clone, Debug)]
pub struct PropElement<T: XmlDeserialize> {
prop: T,
pub struct PropElement {
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
prop: MkcolCalendarProp,
}

#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
#[xml(root = b"mkcalendar")]
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
struct MkcalendarRequest {
set: PropElement<MkcolCalendarProp>,
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
set: PropElement,
}

#[instrument(parent = root_span.id(), skip(store, root_span))]
Expand All @@ -68,7 +56,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
let calendar = Calendar {
id: cal_id.to_owned(),
principal: principal.to_owned(),
order: request.order.unwrap_or(0),
order: request.calendar_order.unwrap_or(0),
displayname: request.displayname,
timezone: request.calendar_timezone,
timezone_id: request.calendar_timezone_id,
Expand All @@ -79,20 +67,6 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
subscription_url: None,
};

match store.get_calendar(&principal, &cal_id).await {
Err(rustical_store::Error::NotFound) => {
// No conflict, no worries
}
Ok(_) => {
// oh no, there's a conflict
return Ok(HttpResponse::Conflict().body("A calendar already exists at this URI"));
}
Err(err) => {
// some other error
return Err(err.into());
}
}

match store.insert_calendar(calendar).await {
// The spec says we should return a mkcalendar-response but I don't know what goes into it.
// However, it works without one but breaks on iPadOS when using an empty one :)
Expand All @@ -112,7 +86,7 @@ mod tests {

#[test]
fn test_xml_mkcalendar() {
let mkcalendar_request = MkcalendarRequest::parse_str(r#"
MkcalendarRequest::parse_str(r#"
<?xml version='1.0' encoding='UTF-8' ?>
<CAL:mkcalendar xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
<set>
Expand Down
1 change: 1 addition & 0 deletions crates/caldav/src/calendar/methods/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ mod tests {
}
}),
timezone: None,
timezone_id: None,
})
)
}
Expand Down

0 comments on commit 9a5314c

Please sign in to comment.