Fix data model to fix event collisions with multiple principals

This commit is contained in:
Lennart
2024-06-21 21:16:31 +02:00
parent aed6bcff63
commit 06d1095c66
11 changed files with 245 additions and 100 deletions

View File

@@ -29,7 +29,7 @@ pub async fn route_delete_calendar<A: CheckAuthentication, C: CalendarStore + ?S
.store
.write()
.await
.delete_calendar(&cid, !no_trash)
.delete_calendar(&principal, &cid, !no_trash)
.await?;
Ok(HttpResponse::Ok().body(""))

View File

@@ -69,16 +69,22 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
let calendar = Calendar {
id: cid.to_owned(),
owner: principal,
principal: principal.to_owned(),
order: request.order.unwrap_or(0),
name: request.displayname,
displayname: request.displayname,
timezone: request.calendar_timezone,
color: request.calendar_color,
description: request.calendar_description,
deleted_at: None,
};
match context.store.read().await.get_calendar(&cid).await {
match context
.store
.read()
.await
.get_calendar(&principal, &cid)
.await
{
Err(rustical_store::Error::NotFound) => {
// No conflict, no worries
}
@@ -92,13 +98,7 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
}
}
match context
.store
.write()
.await
.insert_calendar(cid, calendar)
.await
{
match context.store.write().await.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 :)
Ok(()) => Ok(HttpResponse::Created()

View File

@@ -120,20 +120,22 @@ pub enum ReportRequest {
async fn get_events_calendar_query<C: CalendarStore + ?Sized>(
_cal_query: CalendarQueryRequest,
principal: &str,
cid: &str,
store: &RwLock<C>,
) -> Result<Vec<Event>, Error> {
// TODO: Implement filtering
Ok(store.read().await.get_events(cid).await?)
Ok(store.read().await.get_events(principal, cid).await?)
}
async fn get_events_calendar_multiget<C: CalendarStore + ?Sized>(
_cal_query: CalendarMultigetRequest,
principal: &str,
cid: &str,
store: &RwLock<C>,
) -> Result<Vec<Event>, Error> {
// TODO: proper implementation
Ok(store.read().await.get_events(cid).await?)
Ok(store.read().await.get_events(principal, cid).await?)
}
pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
@@ -152,10 +154,10 @@ pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?S
let request: ReportRequest = quick_xml::de::from_str(&body)?;
let events = match request.clone() {
ReportRequest::CalendarQuery(cal_query) => {
get_events_calendar_query(cal_query, &cid, &cal_store).await?
get_events_calendar_query(cal_query, &principal, &cid, &cal_store).await?
}
ReportRequest::CalendarMultiget(cal_multiget) => {
get_events_calendar_multiget(cal_multiget, &cid, &cal_store).await?
get_events_calendar_multiget(cal_multiget, &principal, &cid, &cal_store).await?
}
};