outsource root resource to dav crate

This commit is contained in:
Lennart
2024-11-04 17:42:55 +01:00
parent 4fd32b3f33
commit 0fed7b05fa
8 changed files with 108 additions and 234 deletions

View File

@@ -10,9 +10,9 @@ use address_object::resource::AddressObjectResourceService;
use addressbook::resource::AddressbookResourceService;
pub use error::Error;
use futures_util::FutureExt;
use principal::PrincipalResourceService;
use root::RootResourceService;
use principal::{PrincipalResource, PrincipalResourceService};
use rustical_dav::resource::ResourceService;
use rustical_dav::resources::RootResourceService;
use rustical_store::{
auth::{AuthenticationMiddleware, AuthenticationProvider},
AddressbookStore,
@@ -23,7 +23,6 @@ pub mod address_object;
pub mod addressbook;
pub mod error;
pub mod principal;
pub mod root;
pub fn configure_well_known(cfg: &mut web::ServiceConfig, carddav_root: String) {
cfg.service(web::redirect("/carddav", carddav_root).permanent());
@@ -60,7 +59,7 @@ pub fn configure_dav<AP: AuthenticationProvider, A: AddressbookStore + ?Sized>(
})
})
.app_data(Data::from(store.clone()))
.service(RootResourceService::actix_resource())
.service(RootResourceService::<PrincipalResource>::actix_resource())
.service(
web::scope("/user").service(
web::scope("/{principal}")

View File

@@ -1,103 +0,0 @@
use crate::principal::PrincipalResource;
use crate::Error;
use actix_web::dev::ResourceMap;
use actix_web::HttpRequest;
use async_trait::async_trait;
use derive_more::{From, TryInto};
use rustical_dav::extension::BoxedExtension;
use rustical_dav::extensions::{
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
};
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
use rustical_store::auth::User;
use serde::{Deserialize, Serialize};
use strum::{EnumString, VariantNames};
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
#[strum(serialize_all = "kebab-case")]
pub enum RootPropName {
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
}
#[derive(Deserialize, Serialize, Default, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Resourcetype {
collection: (),
}
#[derive(Deserialize, Serialize, From, TryInto)]
#[serde(rename_all = "kebab-case")]
pub enum RootProp {
#[serde(skip_deserializing, untagged)]
#[from]
#[try_into]
ExtCommonProperties(CommonPropertiesProp<RootResource>),
#[serde(untagged)]
Invalid,
}
impl InvalidProperty for RootProp {
fn invalid_property(&self) -> bool {
matches!(self, Self::Invalid)
}
}
#[derive(Clone)]
pub struct RootResource;
impl Resource for RootResource {
type PropName = RootPropName;
type Prop = RootProp;
type Error = Error;
type ResourceType = Resourcetype;
fn list_extensions() -> Vec<BoxedExtension<Self>> {
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
PrincipalResource,
>::default())]
}
fn get_prop(
&self,
_rmap: &ResourceMap,
_user: &User,
_prop: &Self::PropName,
) -> Result<Self::Prop, Self::Error> {
panic!("we shouldn't end up here")
}
#[inline]
fn resource_name() -> &'static str {
"carddav_root"
}
fn get_user_privileges(&self, _user: &User) -> Result<UserPrivilegeSet, Self::Error> {
Ok(UserPrivilegeSet::all())
}
}
pub struct RootResourceService;
#[async_trait(?Send)]
impl ResourceService for RootResourceService {
type PathComponents = ();
type MemberType = PrincipalResource;
type Resource = RootResource;
type Error = Error;
async fn new(
_req: &HttpRequest,
_path_components: Self::PathComponents,
) -> Result<Self, Self::Error> {
Ok(Self)
}
async fn get_resource(&self) -> Result<Self::Resource, Self::Error> {
Ok(RootResource)
}
}