caldav: Refactoring to for consistent terminology between resources and resource services

This commit is contained in:
Lennart
2024-09-29 14:00:06 +02:00
parent 7f164da438
commit 2a347f0616
8 changed files with 58 additions and 48 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
event::resource::{EventFile, EventProp},
event::resource::{EventProp, EventResource},
Error,
};
use actix_web::{
@@ -87,7 +87,7 @@ pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
for event in events {
let path = format!("{}/{}", req.path(), event.get_uid());
responses.push(
EventFile::from(event)
EventResource::from(event)
.propfind(prefix, path, props.clone())
.await?,
);

View File

@@ -9,7 +9,7 @@ use serde::Deserialize;
use tokio::sync::RwLock;
use crate::{
event::resource::{EventFile, EventProp},
event::resource::{EventProp, EventResource},
Error,
};
@@ -126,7 +126,7 @@ pub async fn handle_calendar_query<C: CalendarStore + ?Sized>(
for event in events {
let path = format!("{}/{}", req.path(), event.get_uid());
responses.push(
EventFile::from(event)
EventResource::from(event)
.propfind(prefix, path, props.clone())
.await?,
);

View File

@@ -15,7 +15,7 @@ use serde::Deserialize;
use tokio::sync::RwLock;
use crate::{
event::resource::{EventFile, EventProp},
event::resource::{EventProp, EventResource},
Error,
};
@@ -73,7 +73,7 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
for event in new_events {
let path = format!("{}/{}", req.path(), event.get_uid());
responses.push(
EventFile::from(event)
EventResource::from(event)
.propfind(prefix, path, props.clone())
.await?,
);

View File

@@ -1,4 +1,4 @@
use crate::event::resource::EventFile;
use crate::event::resource::EventResource;
use crate::Error;
use actix_web::{web::Data, HttpRequest};
use anyhow::anyhow;
@@ -19,7 +19,7 @@ use super::prop::{
SupportedReportSet, UserPrivilegeSet,
};
pub struct CalendarResource<C: CalendarStore + ?Sized> {
pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
pub cal_store: Arc<RwLock<C>>,
pub path: String,
pub principal: String,
@@ -89,9 +89,9 @@ impl InvalidProperty for CalendarProp {
}
#[derive(Clone, Debug, From, Into)]
pub struct CalendarFile(Calendar);
pub struct CalendarResource(Calendar);
impl Resource for CalendarFile {
impl Resource for CalendarResource {
type PropName = CalendarPropName;
type Prop = CalendarProp;
type Error = Error;
@@ -226,10 +226,10 @@ impl Resource for CalendarFile {
}
#[async_trait(?Send)]
impl<C: CalendarStore + ?Sized> ResourceService for CalendarResource<C> {
type MemberType = EventFile;
impl<C: CalendarStore + ?Sized> ResourceService for CalendarResourceService<C> {
type MemberType = EventResource;
type PathComponents = (String, String); // principal, calendar_id
type File = CalendarFile;
type File = CalendarResource;
type Error = Error;
async fn get_file(&self) -> Result<Self::File, Error> {

View File

@@ -11,7 +11,7 @@ use std::sync::Arc;
use strum::{EnumString, VariantNames};
use tokio::sync::RwLock;
pub struct EventResource<C: CalendarStore + ?Sized> {
pub struct EventResourceService<C: CalendarStore + ?Sized> {
pub cal_store: Arc<RwLock<C>>,
pub path: String,
pub principal: String,
@@ -45,9 +45,9 @@ impl InvalidProperty for EventProp {
}
#[derive(Clone, From, Into)]
pub struct EventFile(Event);
pub struct EventResource(Event);
impl Resource for EventFile {
impl Resource for EventResource {
type PropName = EventPropName;
type Prop = EventProp;
type Error = Error;
@@ -64,10 +64,10 @@ impl Resource for EventFile {
}
#[async_trait(?Send)]
impl<C: CalendarStore + ?Sized> ResourceService for EventResource<C> {
impl<C: CalendarStore + ?Sized> ResourceService for EventResourceService<C> {
type PathComponents = (String, String, String); // principal, calendar, event
type File = EventFile;
type MemberType = EventFile;
type File = EventResource;
type MemberType = EventResource;
type Error = Error;
async fn new(

View File

@@ -1,10 +1,10 @@
use actix_web::http::Method;
use actix_web::web::{self, Data};
use actix_web::{guard, HttpResponse, Responder};
use calendar::resource::CalendarResource;
use event::resource::EventResource;
use principal::PrincipalResource;
use root::RootResource;
use calendar::resource::CalendarResourceService;
use event::resource::EventResourceService;
use principal::PrincipalResourceService;
use root::RootResourceService;
use rustical_auth::CheckAuthentication;
use rustical_dav::methods::{
propfind::ServicePrefix, route_delete, route_propfind, route_proppatch,
@@ -55,16 +55,21 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
)
.service(
web::resource("")
.route(propfind_method().to(route_propfind::<A, RootResource>))
.route(proppatch_method().to(route_proppatch::<A, RootResource>)),
.route(propfind_method().to(route_propfind::<A, RootResourceService>))
.route(proppatch_method().to(route_proppatch::<A, RootResourceService>)),
)
.service(
web::scope("/user").service(
web::scope("/{principal}")
.service(
web::resource("")
.route(propfind_method().to(route_propfind::<A, PrincipalResource<C>>))
.route(proppatch_method().to(route_proppatch::<A, PrincipalResource<C>>)),
.route(
propfind_method().to(route_propfind::<A, PrincipalResourceService<C>>),
)
.route(
proppatch_method()
.to(route_proppatch::<A, PrincipalResourceService<C>>),
),
)
.service(
web::scope("/{calendar}")
@@ -76,15 +81,16 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
),
)
.route(
propfind_method().to(route_propfind::<A, CalendarResource<C>>),
propfind_method()
.to(route_propfind::<A, CalendarResourceService<C>>),
)
.route(
proppatch_method()
.to(route_proppatch::<A, CalendarResource<C>>),
.to(route_proppatch::<A, CalendarResourceService<C>>),
)
.route(
web::method(Method::DELETE)
.to(route_delete::<A, CalendarResource<C>>),
.to(route_delete::<A, CalendarResourceService<C>>),
)
.route(
mkcalendar_method().to(
@@ -94,13 +100,17 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
)
.service(
web::resource("/{event}")
.route(propfind_method().to(route_propfind::<A, EventResource<C>>))
.route(
proppatch_method().to(route_proppatch::<A, EventResource<C>>),
propfind_method()
.to(route_propfind::<A, EventResourceService<C>>),
)
.route(
proppatch_method()
.to(route_proppatch::<A, EventResourceService<C>>),
)
.route(
web::method(Method::DELETE)
.to(route_delete::<A, EventResource<C>>),
.to(route_delete::<A, EventResourceService<C>>),
)
.route(
web::method(Method::GET).to(event::methods::get_event::<A, C>),

View File

@@ -11,16 +11,16 @@ use std::sync::Arc;
use strum::{EnumString, VariantNames};
use tokio::sync::RwLock;
use crate::calendar::resource::CalendarFile;
use crate::calendar::resource::CalendarResource;
pub struct PrincipalResource<C: CalendarStore + ?Sized> {
pub struct PrincipalResourceService<C: CalendarStore + ?Sized> {
principal: String,
path: String,
cal_store: Arc<RwLock<C>>,
}
#[derive(Clone)]
pub struct PrincipalFile {
pub struct PrincipalResource {
principal: String,
}
@@ -63,7 +63,7 @@ pub enum PrincipalPropName {
CalendarUserAddressSet,
}
impl Resource for PrincipalFile {
impl Resource for PrincipalResource {
type PropName = PrincipalPropName;
type Prop = PrincipalProp;
type Error = Error;
@@ -85,10 +85,10 @@ impl Resource for PrincipalFile {
}
#[async_trait(?Send)]
impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResourceService<C> {
type PathComponents = (String,);
type MemberType = CalendarFile;
type File = PrincipalFile;
type MemberType = CalendarResource;
type File = PrincipalResource;
type Error = Error;
async fn new(
@@ -113,7 +113,7 @@ impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
}
async fn get_file(&self) -> Result<Self::File, Self::Error> {
Ok(PrincipalFile {
Ok(PrincipalResource {
principal: self.principal.to_owned(),
})
}

View File

@@ -7,7 +7,7 @@ use rustical_dav::xml::HrefElement;
use serde::{Deserialize, Serialize};
use strum::{EnumString, VariantNames};
pub struct RootResource {
pub struct RootResourceService {
principal: String,
}
@@ -41,11 +41,11 @@ impl InvalidProperty for RootProp {
}
#[derive(Clone)]
pub struct RootFile {
pub struct RootResource {
pub principal: String,
}
impl Resource for RootFile {
impl Resource for RootResource {
type PropName = RootPropName;
type Prop = RootProp;
type Error = Error;
@@ -61,10 +61,10 @@ impl Resource for RootFile {
}
#[async_trait(?Send)]
impl ResourceService for RootResource {
impl ResourceService for RootResourceService {
type PathComponents = ();
type MemberType = RootFile;
type File = RootFile;
type MemberType = RootResource;
type File = RootResource;
type Error = Error;
async fn new(
@@ -78,7 +78,7 @@ impl ResourceService for RootResource {
}
async fn get_file(&self) -> Result<Self::File, Self::Error> {
Ok(RootFile {
Ok(RootResource {
principal: self.principal.to_owned(),
})
}