mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Reorganise resource methods
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
use super::methods::mkcalendar::route_mkcalendar;
|
||||||
|
use super::methods::report::route_report_calendar;
|
||||||
use super::prop::{
|
use super::prop::{
|
||||||
Resourcetype, SupportedCalendarComponent, SupportedCalendarComponentSet, SupportedCalendarData,
|
Resourcetype, SupportedCalendarComponent, SupportedCalendarComponentSet, SupportedCalendarData,
|
||||||
SupportedReportSet, UserPrivilegeSet,
|
SupportedReportSet, UserPrivilegeSet,
|
||||||
@@ -6,6 +8,8 @@ use crate::calendar_object::resource::CalendarObjectResource;
|
|||||||
use crate::principal::PrincipalResource;
|
use crate::principal::PrincipalResource;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use actix_web::dev::ResourceMap;
|
use actix_web::dev::ResourceMap;
|
||||||
|
use actix_web::http::Method;
|
||||||
|
use actix_web::web;
|
||||||
use actix_web::{web::Data, HttpRequest};
|
use actix_web::{web::Data, HttpRequest};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
@@ -14,6 +18,7 @@ use rustical_dav::xml::HrefElement;
|
|||||||
use rustical_store::model::Calendar;
|
use rustical_store::model::Calendar;
|
||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@@ -316,4 +321,13 @@ impl<C: CalendarStore + ?Sized> ResourceService for CalendarResourceService<C> {
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn actix_additional_routes(res: actix_web::Resource) -> actix_web::Resource {
|
||||||
|
let report_method = || web::method(Method::from_str("REPORT").unwrap());
|
||||||
|
let mkcalendar_method = || web::method(Method::from_str("MKCALENDAR").unwrap());
|
||||||
|
|
||||||
|
res.route(report_method().to(route_report_calendar::<C>))
|
||||||
|
.route(mkcalendar_method().to(route_mkcalendar::<C>))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,15 @@ use actix_web::HttpResponse;
|
|||||||
use rustical_store::auth::User;
|
use rustical_store::auth::User;
|
||||||
use rustical_store::model::CalendarObject;
|
use rustical_store::model::CalendarObject;
|
||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
|
use tracing::instrument;
|
||||||
|
use tracing_actix_web::RootSpan;
|
||||||
|
|
||||||
|
#[instrument(parent = root_span.id(), skip(context, path, root_span))]
|
||||||
pub async fn get_event<C: CalendarStore + ?Sized>(
|
pub async fn get_event<C: CalendarStore + ?Sized>(
|
||||||
context: Data<CalDavContext<C>>,
|
context: Data<CalDavContext<C>>,
|
||||||
path: Path<(String, String, String)>,
|
path: Path<(String, String, String)>,
|
||||||
user: User,
|
user: User,
|
||||||
|
root_span: RootSpan,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let (principal, cid, mut uid) = path.into_inner();
|
let (principal, cid, mut uid) = path.into_inner();
|
||||||
|
|
||||||
@@ -46,12 +50,14 @@ pub async fn get_event<C: CalendarStore + ?Sized>(
|
|||||||
.body(event.get_ics().to_owned()))
|
.body(event.get_ics().to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(parent = root_span.id(), skip(context, path, req, root_span))]
|
||||||
pub async fn put_event<C: CalendarStore + ?Sized>(
|
pub async fn put_event<C: CalendarStore + ?Sized>(
|
||||||
context: Data<CalDavContext<C>>,
|
context: Data<CalDavContext<C>>,
|
||||||
path: Path<(String, String, String)>,
|
path: Path<(String, String, String)>,
|
||||||
body: String,
|
body: String,
|
||||||
user: User,
|
user: User,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
|
root_span: RootSpan,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
let (principal, cid, mut uid) = path.into_inner();
|
let (principal, cid, mut uid) = path.into_inner();
|
||||||
if user.id != principal {
|
if user.id != principal {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ use std::sync::Arc;
|
|||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
|
use super::methods::{get_event, put_event};
|
||||||
|
|
||||||
pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
||||||
pub cal_store: Arc<RwLock<C>>,
|
pub cal_store: Arc<RwLock<C>>,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
@@ -130,4 +132,9 @@ impl<C: CalendarStore + ?Sized> ResourceService for CalendarObjectResourceServic
|
|||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn actix_additional_routes(res: actix_web::Resource) -> actix_web::Resource {
|
||||||
|
res.get(get_event::<C>).put(put_event::<C>)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ use calendar::resource::CalendarResourceService;
|
|||||||
use calendar_object::resource::CalendarObjectResourceService;
|
use calendar_object::resource::CalendarObjectResourceService;
|
||||||
use principal::PrincipalResourceService;
|
use principal::PrincipalResourceService;
|
||||||
use root::RootResourceService;
|
use root::RootResourceService;
|
||||||
use rustical_dav::methods::route_delete;
|
|
||||||
use rustical_dav::resource::ResourceService;
|
use rustical_dav::resource::ResourceService;
|
||||||
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider};
|
use rustical_store::auth::{AuthenticationMiddleware, AuthenticationProvider};
|
||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
use std::str::FromStr;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
@@ -34,9 +32,6 @@ pub fn configure_dav<AP: AuthenticationProvider, C: CalendarStore + ?Sized>(
|
|||||||
auth_provider: Arc<AP>,
|
auth_provider: Arc<AP>,
|
||||||
store: Arc<RwLock<C>>,
|
store: Arc<RwLock<C>>,
|
||||||
) {
|
) {
|
||||||
let report_method = || web::method(Method::from_str("REPORT").unwrap());
|
|
||||||
let mkcalendar_method = || web::method(Method::from_str("MKCALENDAR").unwrap());
|
|
||||||
|
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("")
|
web::scope("")
|
||||||
.wrap(AuthenticationMiddleware::new(auth_provider))
|
.wrap(AuthenticationMiddleware::new(auth_provider))
|
||||||
@@ -57,33 +52,10 @@ pub fn configure_dav<AP: AuthenticationProvider, C: CalendarStore + ?Sized>(
|
|||||||
.service(PrincipalResourceService::<C>::actix_resource())
|
.service(PrincipalResourceService::<C>::actix_resource())
|
||||||
.service(
|
.service(
|
||||||
web::scope("/{calendar}")
|
web::scope("/{calendar}")
|
||||||
.service(
|
.service(CalendarResourceService::<C>::actix_resource())
|
||||||
CalendarResourceService::<C>::actix_resource()
|
|
||||||
.route(report_method().to(
|
|
||||||
calendar::methods::report::route_report_calendar::<C>,
|
|
||||||
))
|
|
||||||
.route(
|
|
||||||
web::method(Method::DELETE)
|
|
||||||
.to(route_delete::<CalendarResourceService<C>>),
|
|
||||||
)
|
|
||||||
.route(mkcalendar_method().to(
|
|
||||||
calendar::methods::mkcalendar::route_mkcalendar::<C>,
|
|
||||||
)),
|
|
||||||
)
|
|
||||||
.service(
|
.service(
|
||||||
web::scope("/{object}").service(
|
web::scope("/{object}").service(
|
||||||
CalendarObjectResourceService::<C>::actix_resource()
|
CalendarObjectResourceService::<C>::actix_resource(),
|
||||||
.route(web::method(Method::DELETE).to(route_delete::<
|
|
||||||
CalendarObjectResourceService<C>,
|
|
||||||
>))
|
|
||||||
.route(
|
|
||||||
web::method(Method::GET)
|
|
||||||
.to(calendar_object::methods::get_event::<C>),
|
|
||||||
)
|
|
||||||
.route(
|
|
||||||
web::method(Method::PUT)
|
|
||||||
.to(calendar_object::methods::put_event::<C>),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::methods::{route_propfind, route_proppatch};
|
use crate::methods::{route_delete, route_propfind, route_proppatch};
|
||||||
use crate::xml::multistatus::{PropTagWrapper, PropstatElement, PropstatWrapper};
|
use crate::xml::multistatus::{PropTagWrapper, PropstatElement, PropstatWrapper};
|
||||||
use crate::xml::{multistatus::ResponseElement, TagList};
|
use crate::xml::{multistatus::ResponseElement, TagList};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
@@ -164,17 +164,27 @@ pub trait ResourceService: Sized + 'static {
|
|||||||
Err(crate::Error::Unauthorized.into())
|
Err(crate::Error::Unauthorized.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn resource_name() -> &'static str {
|
fn resource_name() -> &'static str {
|
||||||
Self::Resource::resource_name()
|
Self::Resource::resource_name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn actix_resource() -> actix_web::Resource {
|
fn actix_resource() -> actix_web::Resource {
|
||||||
let propfind_method = || web::method(Method::from_str("PROPFIND").unwrap());
|
let propfind_method = || web::method(Method::from_str("PROPFIND").unwrap());
|
||||||
let proppatch_method = || web::method(Method::from_str("PROPPATCH").unwrap());
|
let proppatch_method = || web::method(Method::from_str("PROPPATCH").unwrap());
|
||||||
|
|
||||||
web::resource("")
|
Self::actix_additional_routes(
|
||||||
.name(Self::resource_name())
|
web::resource("")
|
||||||
.route(propfind_method().to(route_propfind::<Self>))
|
.name(Self::resource_name())
|
||||||
.route(proppatch_method().to(route_proppatch::<Self>))
|
.route(propfind_method().to(route_propfind::<Self>))
|
||||||
|
.route(proppatch_method().to(route_proppatch::<Self>))
|
||||||
|
.delete(route_delete::<Self>),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn actix_additional_routes(res: actix_web::Resource) -> actix_web::Resource {
|
||||||
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user