mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
caldav: some cleaning up
This commit is contained in:
@@ -7,46 +7,34 @@ use rustical_xml::{XmlDeserialize, XmlDocument, XmlRootTag};
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use tracing_actix_web::RootSpan;
|
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)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
pub struct MkcolCalendarProp {
|
pub struct MkcolCalendarProp {
|
||||||
// TODO: Add namespaces
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
resourcetype: Option<Resourcetype>,
|
|
||||||
displayname: Option<String>,
|
displayname: Option<String>,
|
||||||
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
calendar_description: Option<String>,
|
calendar_description: Option<String>,
|
||||||
|
#[xml(ns = "rustical_dav::namespace::NS_ICAL")]
|
||||||
calendar_color: Option<String>,
|
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>,
|
calendar_timezone: Option<String>,
|
||||||
|
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
|
||||||
calendar_timezone_id: Option<String>,
|
calendar_timezone_id: Option<String>,
|
||||||
supported_calendar_component_set: Option<SupportedCalendarComponentSetElement>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug)]
|
#[derive(XmlDeserialize, Clone, Debug)]
|
||||||
pub struct PropElement<T: XmlDeserialize> {
|
pub struct PropElement {
|
||||||
prop: T,
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
|
prop: MkcolCalendarProp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||||
#[xml(root = b"mkcalendar")]
|
#[xml(root = b"mkcalendar")]
|
||||||
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
struct MkcalendarRequest {
|
struct MkcalendarRequest {
|
||||||
set: PropElement<MkcolCalendarProp>,
|
#[xml(ns = "rustical_dav::namespace::NS_DAV")]
|
||||||
|
set: PropElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(parent = root_span.id(), skip(store, root_span))]
|
#[instrument(parent = root_span.id(), skip(store, root_span))]
|
||||||
@@ -68,7 +56,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
|
|||||||
let calendar = Calendar {
|
let calendar = Calendar {
|
||||||
id: cal_id.to_owned(),
|
id: cal_id.to_owned(),
|
||||||
principal: principal.to_owned(),
|
principal: principal.to_owned(),
|
||||||
order: request.order.unwrap_or(0),
|
order: request.calendar_order.unwrap_or(0),
|
||||||
displayname: request.displayname,
|
displayname: request.displayname,
|
||||||
timezone: request.calendar_timezone,
|
timezone: request.calendar_timezone,
|
||||||
timezone_id: request.calendar_timezone_id,
|
timezone_id: request.calendar_timezone_id,
|
||||||
@@ -79,20 +67,6 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
|
|||||||
subscription_url: None,
|
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 {
|
match store.insert_calendar(calendar).await {
|
||||||
// The spec says we should return a mkcalendar-response but I don't know what goes into it.
|
// 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 :)
|
// However, it works without one but breaks on iPadOS when using an empty one :)
|
||||||
@@ -112,7 +86,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_xml_mkcalendar() {
|
fn test_xml_mkcalendar() {
|
||||||
let mkcalendar_request = MkcalendarRequest::parse_str(r#"
|
MkcalendarRequest::parse_str(r#"
|
||||||
<?xml version='1.0' encoding='UTF-8' ?>
|
<?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">
|
<CAL:mkcalendar xmlns="DAV:" xmlns:CAL="urn:ietf:params:xml:ns:caldav" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
|
||||||
<set>
|
<set>
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
timezone: None,
|
timezone: None,
|
||||||
|
timezone_id: None,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user