mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
caldav, carddav: Generate Propname enums with strum
This commit is contained in:
@@ -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<C: CalendarStore + ?Sized> {
|
||||
cal_store: Arc<C>,
|
||||
@@ -33,27 +31,12 @@ pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<C: CalendarStore + ?Sized> {
|
||||
cal_store: Arc<C>,
|
||||
@@ -19,15 +19,12 @@ pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<C: CalendarStore + ?Sized> {
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AS: AddressbookStore + ?Sized> {
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AS: AddressbookStore + ?Sized> {
|
||||
addr_store: Arc<AS>,
|
||||
@@ -25,21 +25,13 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
|
||||
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<String>),
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<A: AddressbookStore + ?Sized> {
|
||||
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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<PR: Resource> Resource for RootResource<PR> {
|
||||
_user: &User,
|
||||
_prop: &Self::PropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
panic!("we shouldn't end up here")
|
||||
unreachable!("we shouldn't end up here")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user