Skip to content

Commit

Permalink
Remove all that extension business and replace with internal properties
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart-k committed Nov 5, 2024
1 parent 4da0ca3 commit d5ef666
Show file tree
Hide file tree
Showing 21 changed files with 176 additions and 264 deletions.
10 changes: 8 additions & 2 deletions crates/caldav/src/calendar/methods/report/calendar_multiget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use actix_web::{
};
use rustical_dav::{
methods::propfind::{PropElement, PropfindType},
resource::Resource,
resource::{CommonPropertiesProp, EitherProp, Resource},
xml::{
multistatus::{PropstatWrapper, ResponseElement},
MultistatusElement,
Expand Down Expand Up @@ -69,7 +69,13 @@ pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
) -> Result<
MultistatusElement<
PropstatWrapper<EitherProp<CalendarObjectProp, CommonPropertiesProp>>,
String,
>,
Error,
> {
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
let (objects, not_found) =
get_objects_calendar_multiget(&cal_multiget, &principal_url, principal, cal_id, cal_store)
Expand Down
10 changes: 8 additions & 2 deletions crates/caldav/src/calendar/methods/report/calendar_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use actix_web::HttpRequest;
use chrono::{DateTime, Utc};
use rustical_dav::{
methods::propfind::{PropElement, PropfindType},
resource::Resource,
resource::{CommonPropertiesProp, EitherProp, Resource},
xml::{multistatus::PropstatWrapper, MultistatusElement},
};
use rustical_store::{auth::User, CalendarObject, CalendarStore};
Expand Down Expand Up @@ -210,7 +210,13 @@ pub async fn handle_calendar_query<C: CalendarStore + ?Sized>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
) -> Result<
MultistatusElement<
PropstatWrapper<EitherProp<CalendarObjectProp, CommonPropertiesProp>>,
String,
>,
Error,
> {
let objects = get_objects_calendar_query(&cal_query, principal, cal_id, cal_store).await?;

let props = match cal_query.prop {
Expand Down
10 changes: 8 additions & 2 deletions crates/caldav/src/calendar/methods/report/sync_collection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::{http::StatusCode, HttpRequest};
use rustical_dav::{
methods::propfind::{PropElement, PropfindType},
resource::Resource,
resource::{CommonPropertiesProp, EitherProp, Resource},
xml::{
multistatus::{PropstatWrapper, ResponseElement},
MultistatusElement,
Expand Down Expand Up @@ -49,7 +49,13 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
) -> Result<
MultistatusElement<
PropstatWrapper<EitherProp<CalendarObjectProp, CommonPropertiesProp>>,
String,
>,
Error,
> {
let props = match sync_collection.prop {
PropfindType::Allprop => {
vec!["allprop".to_owned()]
Expand Down
8 changes: 1 addition & 7 deletions crates/caldav/src/calendar/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use actix_web::web;
use actix_web::{web::Data, HttpRequest};
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::extensions::CommonPropertiesProp;
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{Resource, ResourceService};
use rustical_store::auth::User;
Expand Down Expand Up @@ -46,7 +45,7 @@ pub enum CalendarPropName {
Getctag,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum CalendarProp {
// WebDAV (RFC 2518)
Expand Down Expand Up @@ -83,10 +82,6 @@ pub enum CalendarProp {
// Didn't find the spec
Getctag(String),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down Expand Up @@ -183,7 +178,6 @@ impl Resource for CalendarResource {
CalendarProp::SyncToken(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::Invalid => Err(rustical_dav::Error::PropReadOnly),
_ => panic!("we shouldn't end up here"),
}
}

Expand Down
7 changes: 1 addition & 6 deletions crates/caldav/src/calendar_object/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use actix_web::{dev::ResourceMap, web::Data, HttpRequest};
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::{
extensions::CommonPropertiesProp,
privileges::UserPrivilegeSet,
resource::{Resource, ResourceService},
};
Expand All @@ -28,7 +27,7 @@ pub enum CalendarObjectPropName {
Getcontenttype,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum CalendarObjectProp {
// WebDAV (RFC 2518)
Expand All @@ -39,10 +38,6 @@ pub enum CalendarObjectProp {
#[serde(rename = "C:calendar-data")]
CalendarData(String),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down
2 changes: 2 additions & 0 deletions crates/caldav/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use actix_web::{http::StatusCode, HttpResponse};
use tracing::error;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down Expand Up @@ -41,6 +42,7 @@ impl actix_web::ResponseError for Error {
}
}
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
error!("Error: {self}");
match self {
Error::DavError(err) => err.error_response(),
_ => HttpResponse::build(self.status_code()).body(self.to_string()),
Expand Down
8 changes: 1 addition & 7 deletions crates/caldav/src/principal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use actix_web::dev::ResourceMap;
use actix_web::web::Data;
use actix_web::HttpRequest;
use async_trait::async_trait;
use derive_more::derive::From;
use rustical_dav::extensions::CommonPropertiesProp;
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{Resource, ResourceService};
use rustical_dav::xml::HrefElement;
Expand All @@ -25,7 +23,7 @@ pub struct PrincipalResource {
principal: String,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum PrincipalProp {
// WebDAV Access Control (RFC 3744)
Expand All @@ -38,10 +36,6 @@ pub enum PrincipalProp {
#[serde(rename = "C:calendar-user-address-set")]
CalendarUserAddressSet(HrefElement),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down
7 changes: 1 addition & 6 deletions crates/carddav/src/address_object/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use actix_web::{dev::ResourceMap, web::Data, HttpRequest};
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::{
extensions::CommonPropertiesProp,
privileges::UserPrivilegeSet,
resource::{Resource, ResourceService},
};
Expand All @@ -29,7 +28,7 @@ pub enum AddressObjectPropName {
Getcontenttype,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum AddressObjectProp {
// WebDAV (RFC 2518)
Expand All @@ -40,10 +39,6 @@ pub enum AddressObjectProp {
#[serde(rename = "CARD:address-data")]
AddressData(String),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use actix_web::{
};
use rustical_dav::{
methods::propfind::{PropElement, PropfindType},
resource::Resource,
resource::{CommonPropertiesProp, EitherProp, Resource},
xml::{
multistatus::{PropstatWrapper, ResponseElement},
MultistatusElement,
Expand Down Expand Up @@ -68,7 +68,13 @@ pub async fn handle_addressbook_multiget<AS: AddressbookStore + ?Sized>(
principal: &str,
cal_id: &str,
addr_store: &AS,
) -> Result<MultistatusElement<PropstatWrapper<AddressObjectProp>, String>, Error> {
) -> Result<
MultistatusElement<
PropstatWrapper<EitherProp<AddressObjectProp, CommonPropertiesProp>>,
String,
>,
Error,
> {
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
let (objects, not_found) = get_objects_addressbook_multiget(
&addr_multiget,
Expand Down
10 changes: 8 additions & 2 deletions crates/carddav/src/addressbook/methods/report/sync_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use actix_web::{http::StatusCode, HttpRequest};
use rustical_dav::{
methods::propfind::{PropElement, PropfindType},
resource::Resource,
resource::{CommonPropertiesProp, EitherProp, Resource},
xml::{
multistatus::{PropstatWrapper, ResponseElement},
MultistatusElement,
Expand Down Expand Up @@ -47,7 +47,13 @@ pub async fn handle_sync_collection<AS: AddressbookStore + ?Sized>(
principal: &str,
addressbook_id: &str,
addr_store: &AS,
) -> Result<MultistatusElement<PropstatWrapper<AddressObjectProp>, String>, Error> {
) -> Result<
MultistatusElement<
PropstatWrapper<EitherProp<AddressObjectProp, CommonPropertiesProp>>,
String,
>,
Error,
> {
let props = match sync_collection.prop {
PropfindType::Allprop => {
vec!["allprop".to_owned()]
Expand Down
8 changes: 1 addition & 7 deletions crates/carddav/src/addressbook/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use actix_web::web;
use actix_web::{web::Data, HttpRequest};
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::extensions::CommonPropertiesProp;
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{Resource, ResourceService};
use rustical_store::auth::User;
Expand Down Expand Up @@ -39,7 +38,7 @@ pub enum AddressbookPropName {
Getctag,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum AddressbookProp {
// WebDAV (RFC 2518)
Expand Down Expand Up @@ -68,10 +67,6 @@ pub enum AddressbookProp {
// Didn't find the spec
Getctag(String),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down Expand Up @@ -135,7 +130,6 @@ impl Resource for AddressbookResource {
AddressbookProp::SyncToken(_) => Err(rustical_dav::Error::PropReadOnly),
AddressbookProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly),
AddressbookProp::Invalid => Err(rustical_dav::Error::PropReadOnly),
_ => panic!("we shouldn't end up here"),
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/carddav/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use actix_web::{http::StatusCode, HttpResponse};
use tracing::error;

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down Expand Up @@ -41,6 +42,7 @@ impl actix_web::ResponseError for Error {
}
}
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
error!("Error: {self}");
match self {
Error::DavError(err) => err.error_response(),
_ => HttpResponse::build(self.status_code()).body(self.to_string()),
Expand Down
8 changes: 1 addition & 7 deletions crates/carddav/src/principal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use actix_web::dev::ResourceMap;
use actix_web::web::Data;
use actix_web::HttpRequest;
use async_trait::async_trait;
use derive_more::derive::From;
use rustical_dav::extensions::CommonPropertiesProp;
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{Resource, ResourceService};
use rustical_dav::xml::HrefElement;
Expand All @@ -25,7 +23,7 @@ pub struct PrincipalResource {
principal: String,
}

#[derive(Default, Deserialize, Serialize, From, PartialEq)]
#[derive(Default, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "kebab-case")]
pub enum PrincipalProp {
// WebDAV Access Control (RFC 3744)
Expand All @@ -38,10 +36,6 @@ pub enum PrincipalProp {
#[serde(rename = "CARD:principal-address")]
PrincipalAddress(Option<HrefElement>),

#[serde(skip_deserializing, rename = "$value")]
#[from]
ExtCommonProperties(CommonPropertiesProp),

#[serde(other)]
#[default]
Invalid,
Expand Down
4 changes: 2 additions & 2 deletions crates/dav/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use actix_web::{http::StatusCode, HttpResponse};
use thiserror::Error;

// use crate::routes::propfind;
use tracing::error;

#[derive(Debug, Error)]
pub enum Error {
Expand Down Expand Up @@ -41,6 +40,7 @@ impl actix_web::error::ResponseError for Error {
}

fn error_response(&self) -> HttpResponse {
error!("Error: {self}");
match self {
Error::Unauthorized => HttpResponse::build(self.status_code())
.append_header(("WWW-Authenticate", "Basic"))
Expand Down
Loading

0 comments on commit d5ef666

Please sign in to comment.