diff --git a/crates/caldav/src/calendar/resource.rs b/crates/caldav/src/calendar/resource.rs index 9197010..1435a1c 100644 --- a/crates/caldav/src/calendar/resource.rs +++ b/crates/caldav/src/calendar/resource.rs @@ -13,8 +13,6 @@ use actix_web::http::Method; use actix_web::web; use actix_web::{web::Data, HttpRequest}; use async_trait::async_trait; -use base64::prelude::{BASE64_STANDARD, BASE64_URL_SAFE}; -use base64::Engine; use derive_more::derive::{From, Into}; use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::resource::{Resource, ResourceService}; @@ -25,7 +23,7 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::str::FromStr; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; pub struct CalendarResourceService { cal_store: Arc, @@ -33,27 +31,12 @@ pub struct CalendarResourceService { calendar_id: String, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum CalendarPropName { - Displayname, - Getcontenttype, - Transports, - Topic, - CalendarColor, - CalendarDescription, - CalendarTimezone, - CalendarOrder, - SupportedCalendarComponentSet, - SupportedCalendarData, - MaxResourceSize, - SupportedReportSet, - SyncToken, - Getctag, - Source, -} - -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] +#[strum_discriminants( + name(CalendarPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] #[serde(rename_all = "kebab-case")] pub enum CalendarProp { // WebDAV (RFC 2518) @@ -178,6 +161,9 @@ impl Resource for CalendarResource { CalendarPropName::Source => { CalendarProp::Source(self.0.subscription_url.to_owned().map(HrefElement::from)) } + CalendarPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } @@ -255,6 +241,7 @@ impl Resource for CalendarResource { CalendarPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), // Converting a calendar subscription calendar into a normal one would be weird CalendarPropName::Source => Err(rustical_dav::Error::PropReadOnly), + CalendarPropName::Invalid => Err(rustical_dav::Error::PropReadOnly), } } diff --git a/crates/caldav/src/calendar_object/resource.rs b/crates/caldav/src/calendar_object/resource.rs index 0d499b4..99d33a4 100644 --- a/crates/caldav/src/calendar_object/resource.rs +++ b/crates/caldav/src/calendar_object/resource.rs @@ -10,7 +10,7 @@ use rustical_dav::{ use rustical_store::{auth::User, CalendarObject, CalendarStore}; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; pub struct CalendarObjectResourceService { cal_store: Arc, @@ -19,15 +19,12 @@ pub struct CalendarObjectResourceService { object_id: String, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum CalendarObjectPropName { - Getetag, - CalendarData, - Getcontenttype, -} - -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] +#[strum_discriminants( + name(CalendarObjectPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] #[serde(rename_all = "kebab-case")] pub enum CalendarObjectProp { // WebDAV (RFC 2518) @@ -73,6 +70,9 @@ impl Resource for CalendarObjectResource { CalendarObjectPropName::Getcontenttype => { CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) } + CalendarObjectPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } diff --git a/crates/caldav/src/principal/mod.rs b/crates/caldav/src/principal/mod.rs index 1926a24..fb21ead 100644 --- a/crates/caldav/src/principal/mod.rs +++ b/crates/caldav/src/principal/mod.rs @@ -11,7 +11,7 @@ use rustical_store::auth::User; use rustical_store::CalendarStore; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; pub struct PrincipalResourceService { principal: String, @@ -23,11 +23,17 @@ pub struct PrincipalResource { principal: String, } -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] +#[strum_discriminants( + name(PrincipalPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] #[serde(rename_all = "kebab-case")] pub enum PrincipalProp { // WebDAV Access Control (RFC 3744) #[serde(rename = "principal-URL")] + #[strum_discriminants(strum(serialize = "principal-URL"))] PrincipalUrl(HrefElement), // CalDAV (RFC 4791) @@ -41,15 +47,6 @@ pub enum PrincipalProp { Invalid, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum PrincipalPropName { - #[strum(serialize = "principal-URL")] - PrincipalUrl, - CalendarHomeSet, - CalendarUserAddressSet, -} - impl PrincipalResource { pub fn get_principal_url(rmap: &ResourceMap, principal: &str) -> String { Self::get_url(rmap, vec![principal]).unwrap() @@ -80,6 +77,9 @@ impl Resource for PrincipalResource { PrincipalPropName::CalendarUserAddressSet => { PrincipalProp::CalendarUserAddressSet(principal_href) } + PrincipalPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } diff --git a/crates/carddav/src/address_object/resource.rs b/crates/carddav/src/address_object/resource.rs index 7db5250..05454db 100644 --- a/crates/carddav/src/address_object/resource.rs +++ b/crates/carddav/src/address_object/resource.rs @@ -9,7 +9,7 @@ use rustical_dav::{ use rustical_store::{auth::User, AddressObject, AddressbookStore}; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; use super::methods::{get_object, put_object}; @@ -20,15 +20,12 @@ pub struct AddressObjectResourceService { object_id: String, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum AddressObjectPropName { - Getetag, - AddressData, - Getcontenttype, -} - -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] +#[strum_discriminants( + name(AddressObjectPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] #[serde(rename_all = "kebab-case")] pub enum AddressObjectProp { // WebDAV (RFC 2518) @@ -74,6 +71,9 @@ impl Resource for AddressObjectResource { AddressObjectPropName::Getcontenttype => { AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned()) } + AddressObjectPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } diff --git a/crates/carddav/src/addressbook/resource.rs b/crates/carddav/src/addressbook/resource.rs index 6b40a32..e4943e3 100644 --- a/crates/carddav/src/addressbook/resource.rs +++ b/crates/carddav/src/addressbook/resource.rs @@ -17,7 +17,7 @@ use rustical_store::{Addressbook, AddressbookStore}; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; pub struct AddressbookResourceService { addr_store: Arc, @@ -25,21 +25,13 @@ pub struct AddressbookResourceService { addressbook_id: String, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum AddressbookPropName { - Displayname, - Getcontenttype, - AddressbookDescription, - SupportedAddressData, - SupportedReportSet, - MaxResourceSize, - SyncToken, - Getctag, -} - -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] #[serde(rename_all = "kebab-case")] +#[strum_discriminants( + name(AddressbookPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] pub enum AddressbookProp { // WebDAV (RFC 2518) Displayname(Option), @@ -110,6 +102,9 @@ impl Resource for AddressbookResource { } AddressbookPropName::SyncToken => AddressbookProp::SyncToken(self.0.format_synctoken()), AddressbookPropName::Getctag => AddressbookProp::Getctag(self.0.format_synctoken()), + AddressbookPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } @@ -149,6 +144,7 @@ impl Resource for AddressbookResource { AddressbookPropName::SupportedAddressData => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), + AddressbookPropName::Invalid => Err(rustical_dav::Error::PropReadOnly), } } diff --git a/crates/carddav/src/principal/mod.rs b/crates/carddav/src/principal/mod.rs index 8489b96..0592de1 100644 --- a/crates/carddav/src/principal/mod.rs +++ b/crates/carddav/src/principal/mod.rs @@ -11,7 +11,7 @@ use rustical_store::auth::User; use rustical_store::AddressbookStore; use serde::{Deserialize, Serialize}; use std::sync::Arc; -use strum::{EnumString, VariantNames}; +use strum::{EnumDiscriminants, EnumString, VariantNames}; pub struct PrincipalResourceService { principal: String, @@ -23,11 +23,17 @@ pub struct PrincipalResource { principal: String, } -#[derive(Default, Deserialize, Serialize, PartialEq)] +#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)] +#[strum_discriminants( + name(PrincipalPropName), + derive(EnumString, VariantNames), + strum(serialize_all = "kebab-case") +)] #[serde(rename_all = "kebab-case")] pub enum PrincipalProp { // WebDAV Access Control (RFC 3744) #[serde(rename = "principal-URL")] + #[strum_discriminants(strum(serialize = "principal-URL"))] PrincipalUrl(HrefElement), // CardDAV (RFC 6352) @@ -41,15 +47,6 @@ pub enum PrincipalProp { Invalid, } -#[derive(EnumString, VariantNames, Clone)] -#[strum(serialize_all = "kebab-case")] -pub enum PrincipalPropName { - #[strum(serialize = "principal-URL")] - PrincipalUrl, - AddressbookHomeSet, - PrincipalAddress, -} - impl PrincipalResource { pub fn get_principal_url(rmap: &ResourceMap, principal: &str) -> String { Self::get_url(rmap, vec![principal]).unwrap() @@ -80,6 +77,9 @@ impl Resource for PrincipalResource { PrincipalProp::AddressbookHomeSet(principal_href) } PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None), + PrincipalPropName::Invalid => { + return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into()) + } }) } diff --git a/crates/dav/src/resources/root.rs b/crates/dav/src/resources/root.rs index 2881f36..9bcaf61 100644 --- a/crates/dav/src/resources/root.rs +++ b/crates/dav/src/resources/root.rs @@ -45,7 +45,7 @@ impl Resource for RootResource { _user: &User, _prop: &Self::PropName, ) -> Result { - panic!("we shouldn't end up here") + unreachable!("we shouldn't end up here") } #[inline]