A few fixes to MKCALENDAR

This commit is contained in:
Lennart
2024-06-01 19:49:33 +02:00
parent 5afbb85cb7
commit 468d74875b

View File

@@ -25,14 +25,14 @@ pub struct CalendarComponentElement {
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct SupportedCalendarComponentSetElement { pub struct SupportedCalendarComponentSetElement {
#[serde(flatten)] #[serde(rename = "$value")]
comp: Vec<CalendarComponentElement>, comp: Vec<CalendarComponentElement>,
} }
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct MkcolCalendarProp { pub struct MkcolCalendarProp {
resourcetype: Resourcetype, resourcetype: Option<Resourcetype>,
displayname: Option<String>, displayname: Option<String>,
calendar_description: Option<String>, calendar_description: Option<String>,
calendar_color: Option<String>, calendar_color: Option<String>,
@@ -52,11 +52,6 @@ struct MkcalendarRequest {
set: PropElement<MkcolCalendarProp>, set: PropElement<MkcolCalendarProp>,
} }
// TODO: Not sure yet what to send back :)
#[derive(Serialize, Clone, Debug)]
#[serde(rename = "mkcalendar-response")]
struct MkcalendarResponse;
pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>( pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
path: Path<(String, String)>, path: Path<(String, String)>,
body: String, body: String,
@@ -80,6 +75,20 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
description: request.calendar_description, description: request.calendar_description,
}; };
match context.store.read().await.get_calendar(&cid).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 context match context
.store .store
.write() .write()
@@ -87,10 +96,14 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
.insert_calendar(cid, calendar) .insert_calendar(cid, calendar)
.await .await
{ {
Ok(()) => { // The spec says we should return a mkcalendar-response but I don't know what goes into it.
let response = quick_xml::se::to_string(&MkcalendarResponse).unwrap(); // However, it works without one but breaks on iPadOS when using an empty one :)
Ok(HttpResponse::Created().body(response)) Ok(()) => Ok(HttpResponse::Created()
.insert_header(("Cache-Control", "no-cache"))
.body("")),
Err(err) => {
dbg!(err.to_string());
Err(err.into())
} }
Err(_err) => Ok(HttpResponse::InternalServerError().body("")),
} }
} }