From 0415664ff30e4f4681bd7ba1eafc3b9be695a05a Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sun, 15 Jun 2025 16:31:07 +0200 Subject: [PATCH] calendar_store: Fix deleted objects being returned --- ...496a884c59adb8b64b569d36f4ce10f88f47.json} | 4 +- ...de8b7ce3575d92fddbc6e9582d141bc9e49d.json} | 6 +- Cargo.lock | 68 +++++++++++++++++++ .../methods/report/calendar_multiget.rs | 2 +- crates/caldav/src/calendar_object/methods.rs | 2 +- crates/caldav/src/calendar_object/service.rs | 2 +- crates/store/src/calendar_store.rs | 1 + crates/store/src/combined_calendar_store.rs | 5 +- crates/store/src/contact_birthday_store.rs | 3 +- crates/store_sqlite/src/addressbook_store.rs | 2 +- crates/store_sqlite/src/calendar_store.rs | 11 +-- 11 files changed, 90 insertions(+), 16 deletions(-) rename .sqlx/{query-395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e.json => query-246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47.json} (74%) rename .sqlx/{query-d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b.json => query-543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d.json} (71%) diff --git a/.sqlx/query-395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e.json b/.sqlx/query-246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47.json similarity index 74% rename from .sqlx/query-395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e.json rename to .sqlx/query-246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47.json index 77e3d81..d04dbbf 100644 --- a/.sqlx/query-395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e.json +++ b/.sqlx/query-246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) or ?)", + "query": "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)", "describe": { "columns": [ { @@ -22,5 +22,5 @@ false ] }, - "hash": "395e40a7b3333b79bc2ad50a123d99f74bc2712a16257ee2119dd211fdb61f7e" + "hash": "246ec675667992c1297c29348d46496a884c59adb8b64b569d36f4ce10f88f47" } diff --git a/.sqlx/query-d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b.json b/.sqlx/query-543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d.json similarity index 71% rename from .sqlx/query-d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b.json rename to .sqlx/query-543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d.json index a7fbccd..91945b2 100644 --- a/.sqlx/query-d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b.json +++ b/.sqlx/query-543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d.json @@ -1,6 +1,6 @@ { "db_name": "SQLite", - "query": "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?)", + "query": "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)", "describe": { "columns": [ { @@ -15,12 +15,12 @@ } ], "parameters": { - "Right": 3 + "Right": 4 }, "nullable": [ false, false ] }, - "hash": "d2f7423e2e8f97607f6664200990dcadb927445880ec6edffba3b5aedf4e199b" + "hash": "543838c030550cb09d1af08adfeade8b7ce3575d92fddbc6e9582d141bc9e49d" } diff --git a/Cargo.lock b/Cargo.lock index f0cef53..0bbbb2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,7 +768,11 @@ dependencies = [ "base64 0.21.7", "byteorder", "hex", + "hkdf", + "lazy_static", "once_cell", + "openssl", + "sha2", "thiserror 1.0.69", ] @@ -916,6 +920,21 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1834,6 +1853,54 @@ dependencies = [ "url", ] +[[package]] +name = "openssl" +version = "0.10.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-src" +version = "300.5.0+3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ce546f549326b0e6052b649198487d91320875da901e7bd11a06d1ee3f9c2f" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" +dependencies = [ + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + [[package]] name = "opentelemetry" version = "0.30.0" @@ -2815,6 +2882,7 @@ dependencies = [ "http", "itertools 0.14.0", "log", + "openssl", "p256", "quick-xml", "rand 0.9.1", diff --git a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs index 4ee7237..e8b2d43 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs @@ -29,7 +29,7 @@ pub async fn get_objects_calendar_multiget( if let Some(filename) = href.strip_prefix(path) { let filename = filename.trim_start_matches("/"); if let Some(object_id) = filename.strip_suffix(".ics") { - match store.get_object(principal, cal_id, object_id).await { + match store.get_object(principal, cal_id, object_id, false).await { Ok(object) => result.push(object), Err(rustical_store::Error::NotFound) => not_found.push(href.to_owned()), Err(err) => return Err(err.into()), diff --git a/crates/caldav/src/calendar_object/methods.rs b/crates/caldav/src/calendar_object/methods.rs index 8ec8f79..74366f3 100644 --- a/crates/caldav/src/calendar_object/methods.rs +++ b/crates/caldav/src/calendar_object/methods.rs @@ -33,7 +33,7 @@ pub async fn get_event( } let event = cal_store - .get_object(&principal, &calendar_id, &object_id) + .get_object(&principal, &calendar_id, &object_id, false) .await?; let mut resp = Response::builder().status(StatusCode::OK); diff --git a/crates/caldav/src/calendar_object/service.rs b/crates/caldav/src/calendar_object/service.rs index bd8106b..d9efed4 100644 --- a/crates/caldav/src/calendar_object/service.rs +++ b/crates/caldav/src/calendar_object/service.rs @@ -61,7 +61,7 @@ impl ResourceService for CalendarObjectResourceService { ) -> Result { let object = self .cal_store - .get_object(principal, calendar_id, object_id) + .get_object(principal, calendar_id, object_id, false) .await?; Ok(CalendarObjectResource { object, diff --git a/crates/store/src/calendar_store.rs b/crates/store/src/calendar_store.rs index 4bcfe08..20e4c21 100644 --- a/crates/store/src/calendar_store.rs +++ b/crates/store/src/calendar_store.rs @@ -58,6 +58,7 @@ pub trait CalendarStore: Send + Sync + 'static { principal: &str, cal_id: &str, object_id: &str, + show_deleted: bool, ) -> Result; async fn put_object( &self, diff --git a/crates/store/src/combined_calendar_store.rs b/crates/store/src/combined_calendar_store.rs index d125b37..e476fa7 100644 --- a/crates/store/src/combined_calendar_store.rs +++ b/crates/store/src/combined_calendar_store.rs @@ -96,14 +96,15 @@ impl CalendarStore for CombinedCalendarSto principal: &str, cal_id: &str, object_id: &str, + show_deleted: bool, ) -> Result { if cal_id.starts_with(BIRTHDAYS_PREFIX) { self.birthday_store - .get_object(principal, cal_id, object_id) + .get_object(principal, cal_id, object_id, show_deleted) .await } else { self.cal_store - .get_object(principal, cal_id, object_id) + .get_object(principal, cal_id, object_id, show_deleted) .await } } diff --git a/crates/store/src/contact_birthday_store.rs b/crates/store/src/contact_birthday_store.rs index 3e187bc..450d8e5 100644 --- a/crates/store/src/contact_birthday_store.rs +++ b/crates/store/src/contact_birthday_store.rs @@ -126,13 +126,14 @@ impl CalendarStore for ContactBirthdayStore { principal: &str, cal_id: &str, object_id: &str, + show_deleted: bool, ) -> Result { let cal_id = cal_id .strip_prefix(BIRTHDAYS_PREFIX) .ok_or(Error::NotFound)?; let (addressobject_id, date_type) = object_id.rsplit_once("-").ok_or(Error::NotFound)?; self.0 - .get_object(principal, cal_id, addressobject_id, false) + .get_object(principal, cal_id, addressobject_id, show_deleted) .await? .get_significant_dates()? .remove(date_type) diff --git a/crates/store_sqlite/src/addressbook_store.rs b/crates/store_sqlite/src/addressbook_store.rs index c2f334b..1566be9 100644 --- a/crates/store_sqlite/src/addressbook_store.rs +++ b/crates/store_sqlite/src/addressbook_store.rs @@ -250,7 +250,7 @@ impl SqliteAddressbookStore { ) -> Result { Ok(sqlx::query_as!( AddressObjectRow, - "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) or ?)", + "SELECT id, vcf FROM addressobjects WHERE (principal, addressbook_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)", principal, addressbook_id, object_id, diff --git a/crates/store_sqlite/src/calendar_store.rs b/crates/store_sqlite/src/calendar_store.rs index 8cd81e8..4de7353 100644 --- a/crates/store_sqlite/src/calendar_store.rs +++ b/crates/store_sqlite/src/calendar_store.rs @@ -296,13 +296,15 @@ impl SqliteCalendarStore { principal: &str, cal_id: &str, object_id: &str, + show_deleted: bool, ) -> Result { sqlx::query_as!( CalendarObjectRow, - "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?)", + "SELECT id, ics FROM calendarobjects WHERE (principal, cal_id, id) = (?, ?, ?) AND ((deleted_at IS NULL) OR ?)", principal, cal_id, - object_id + object_id, + show_deleted ) .fetch_one(executor) .await @@ -454,7 +456,7 @@ impl SqliteCalendarStore { .unwrap_or(0); for Row { object_id, .. } in changes { - match Self::_get_object(&mut *conn, principal, cal_id, &object_id).await { + match Self::_get_object(&mut *conn, principal, cal_id, &object_id, false).await { Ok(object) => objects.push(object), Err(rustical_store::Error::NotFound) => deleted_objects.push(object_id), Err(err) => return Err(err), @@ -557,8 +559,9 @@ impl CalendarStore for SqliteCalendarStore { principal: &str, cal_id: &str, object_id: &str, + show_deleted: bool, ) -> Result { - Self::_get_object(&self.db, principal, cal_id, object_id).await + Self::_get_object(&self.db, principal, cal_id, object_id, show_deleted).await } #[instrument]