lift restriction on object_id and UID having to match

addresses #135
This commit is contained in:
Lennart
2025-11-01 21:48:37 +01:00
parent db144ebcae
commit 76b4194b94
21 changed files with 234 additions and 103 deletions

View File

@@ -82,7 +82,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
let objects = expanded_cals
.into_iter()
.map(|cal| cal.generate())
.map(CalendarObject::from_ics)
.map(|ics| CalendarObject::from_ics(ics, None))
.collect::<Result<Vec<_>, _>>()?;
let new_cal = Calendar {
principal,

View File

@@ -61,7 +61,7 @@ fn objects_response(
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
let mut responses = Vec::new();
for object in objects {
let path = format!("{}/{}.ics", path, object.get_uid());
let path = format!("{}/{}.ics", path, object.get_id());
responses.push(
CalendarObjectResource {
object,

View File

@@ -33,7 +33,7 @@ pub async fn handle_sync_collection<C: CalendarStore>(
let mut responses = Vec::new();
for object in new_objects {
let path = format!("{}/{}.ics", path, object.get_uid());
let path = format!("{}/{}.ics", path, object.get_id());
responses.push(
CalendarObjectResource {
object,

View File

@@ -11,7 +11,7 @@ use rustical_ical::CalendarObject;
use rustical_store::CalendarStore;
use rustical_store::auth::Principal;
use std::str::FromStr;
use tracing::{debug, error, instrument};
use tracing::{debug, instrument};
#[instrument(skip(cal_store))]
pub async fn get_event<C: CalendarStore>(
@@ -78,18 +78,10 @@ pub async fn put_event<C: CalendarStore>(
true
};
let Ok(object) = CalendarObject::from_ics(body.clone()) else {
let Ok(object) = CalendarObject::from_ics(body.clone(), Some(object_id)) else {
debug!("invalid calendar data:\n{body}");
return Err(Error::PreconditionFailed(Precondition::ValidCalendarData));
};
if object.get_uid() != object_id {
error!(
"Calendar object UID and file name not matching: UID={}, filename={}",
object.get_uid(),
object_id
);
return Err(Error::PreconditionFailed(Precondition::MatchingUid));
}
cal_store
.put_object(principal, calendar_id, object, overwrite)
.await?;

View File

@@ -21,7 +21,7 @@ pub struct CalendarObjectResource {
impl ResourceName for CalendarObjectResource {
fn get_name(&self) -> String {
format!("{}.ics", self.object.get_uid())
format!("{}.ics", self.object.get_id())
}
}

View File

@@ -12,8 +12,6 @@ pub enum Precondition {
#[error("valid-calendar-data")]
#[xml(ns = "rustical_dav::namespace::NS_CALDAV")]
ValidCalendarData,
#[error("matching-uid")]
MatchingUid,
}
impl IntoResponse for Precondition {