mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
slight report refactoring
This commit is contained in:
@@ -1,18 +1,9 @@
|
|||||||
use super::ReportPropName;
|
use super::ReportPropName;
|
||||||
use crate::{
|
use crate::Error;
|
||||||
Error,
|
use actix_web::dev::{Path, ResourceDef};
|
||||||
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
|
use rustical_dav::xml::PropfindType;
|
||||||
};
|
|
||||||
use actix_web::{
|
|
||||||
dev::{Path, ResourceDef},
|
|
||||||
http::StatusCode,
|
|
||||||
};
|
|
||||||
use rustical_dav::{
|
|
||||||
resource::{PrincipalUri, Resource},
|
|
||||||
xml::{MultistatusElement, PropfindType, multistatus::ResponseElement},
|
|
||||||
};
|
|
||||||
use rustical_ical::CalendarObject;
|
use rustical_ical::CalendarObject;
|
||||||
use rustical_store::{CalendarStore, auth::User};
|
use rustical_store::CalendarStore;
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
@@ -54,44 +45,3 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
|
|||||||
|
|
||||||
Ok((result, not_found))
|
Ok((result, not_found))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_calendar_multiget<C: CalendarStore>(
|
|
||||||
cal_multiget: &CalendarMultigetRequest,
|
|
||||||
props: &[&str],
|
|
||||||
path: &str,
|
|
||||||
puri: &impl PrincipalUri,
|
|
||||||
user: &User,
|
|
||||||
principal: &str,
|
|
||||||
cal_id: &str,
|
|
||||||
cal_store: &C,
|
|
||||||
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
|
||||||
let (objects, not_found) =
|
|
||||||
get_objects_calendar_multiget(cal_multiget, path, principal, cal_id, cal_store).await?;
|
|
||||||
|
|
||||||
let mut responses = Vec::new();
|
|
||||||
for object in objects {
|
|
||||||
let path = format!("{}/{}.ics", path, object.get_id());
|
|
||||||
responses.push(
|
|
||||||
CalendarObjectResource {
|
|
||||||
object,
|
|
||||||
principal: principal.to_owned(),
|
|
||||||
}
|
|
||||||
.propfind(&path, props, puri, user)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let not_found_responses = not_found
|
|
||||||
.into_iter()
|
|
||||||
.map(|path| ResponseElement {
|
|
||||||
href: path,
|
|
||||||
status: Some(StatusCode::NOT_FOUND),
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(MultistatusElement {
|
|
||||||
responses,
|
|
||||||
member_responses: not_found_responses,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
use rustical_dav::{
|
use super::ReportPropName;
|
||||||
resource::{PrincipalUri, Resource},
|
use crate::Error;
|
||||||
xml::{MultistatusElement, PropfindType},
|
use rustical_dav::xml::PropfindType;
|
||||||
};
|
|
||||||
use rustical_ical::{CalendarObject, UtcDateTime};
|
use rustical_ical::{CalendarObject, UtcDateTime};
|
||||||
use rustical_store::{CalendarStore, auth::User, calendar_store::CalendarQuery};
|
use rustical_store::{CalendarStore, calendar_store::CalendarQuery};
|
||||||
use rustical_xml::XmlDeserialize;
|
use rustical_xml::XmlDeserialize;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
Error,
|
|
||||||
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::ReportPropName;
|
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) struct TimeRangeElement {
|
pub(crate) struct TimeRangeElement {
|
||||||
@@ -212,33 +204,3 @@ pub async fn get_objects_calendar_query<C: CalendarStore>(
|
|||||||
}
|
}
|
||||||
Ok(objects)
|
Ok(objects)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_calendar_query<C: CalendarStore>(
|
|
||||||
cal_query: &CalendarQueryRequest,
|
|
||||||
props: &[&str],
|
|
||||||
path: &str,
|
|
||||||
puri: &impl PrincipalUri,
|
|
||||||
user: &User,
|
|
||||||
principal: &str,
|
|
||||||
cal_id: &str,
|
|
||||||
cal_store: &C,
|
|
||||||
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
|
||||||
let objects = get_objects_calendar_query(cal_query, principal, cal_id, cal_store).await?;
|
|
||||||
|
|
||||||
let mut responses = Vec::new();
|
|
||||||
for object in objects {
|
|
||||||
let path = format!("{}/{}.ics", path, object.get_id());
|
|
||||||
responses.push(
|
|
||||||
CalendarObjectResource {
|
|
||||||
object,
|
|
||||||
principal: principal.to_owned(),
|
|
||||||
}
|
|
||||||
.propfind(&path, props, puri, user)?,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(MultistatusElement {
|
|
||||||
responses,
|
|
||||||
..Default::default()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
use crate::{CalDavPrincipalUri, Error};
|
use crate::{
|
||||||
|
CalDavPrincipalUri, Error,
|
||||||
|
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
|
||||||
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
HttpRequest, Responder,
|
HttpRequest, Responder,
|
||||||
|
http::StatusCode,
|
||||||
web::{Data, Path},
|
web::{Data, Path},
|
||||||
};
|
};
|
||||||
use calendar_multiget::{CalendarMultigetRequest, handle_calendar_multiget};
|
use calendar_multiget::{CalendarMultigetRequest, get_objects_calendar_multiget};
|
||||||
use calendar_query::{CalendarQueryRequest, handle_calendar_query};
|
use calendar_query::{CalendarQueryRequest, get_objects_calendar_query};
|
||||||
use rustical_dav::xml::{
|
use rustical_dav::{
|
||||||
PropElement, PropfindType, Propname, sync_collection::SyncCollectionRequest,
|
resource::{PrincipalUri, Resource},
|
||||||
|
xml::{
|
||||||
|
MultistatusElement, PropElement, PropfindType, Propname, multistatus::ResponseElement,
|
||||||
|
sync_collection::SyncCollectionRequest,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
use rustical_ical::{CalendarObject, UtcDateTime};
|
||||||
use rustical_store::{CalendarStore, auth::User};
|
use rustical_store::{CalendarStore, auth::User};
|
||||||
use rustical_xml::{XmlDeserialize, XmlDocument};
|
use rustical_xml::{XmlDeserialize, XmlDocument};
|
||||||
use sync_collection::handle_sync_collection;
|
use sync_collection::handle_sync_collection;
|
||||||
@@ -20,9 +29,9 @@ mod sync_collection;
|
|||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
pub(crate) struct ExpandElement {
|
pub(crate) struct ExpandElement {
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
start: String,
|
start: UtcDateTime,
|
||||||
#[xml(ty = "attr")]
|
#[xml(ty = "attr")]
|
||||||
end: String,
|
end: UtcDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
#[derive(XmlDeserialize, Clone, Debug, PartialEq)]
|
||||||
@@ -81,6 +90,43 @@ impl ReportRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn objects_response(
|
||||||
|
objects: Vec<CalendarObject>,
|
||||||
|
not_found: Vec<String>,
|
||||||
|
path: &str,
|
||||||
|
principal: &str,
|
||||||
|
puri: &impl PrincipalUri,
|
||||||
|
user: &User,
|
||||||
|
props: &[&str],
|
||||||
|
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
|
||||||
|
let mut responses = Vec::new();
|
||||||
|
for object in objects {
|
||||||
|
let path = format!("{}/{}.ics", path, object.get_id());
|
||||||
|
responses.push(
|
||||||
|
CalendarObjectResource {
|
||||||
|
object,
|
||||||
|
principal: principal.to_owned(),
|
||||||
|
}
|
||||||
|
.propfind(&path, props, puri, user)?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let not_found_responses = not_found
|
||||||
|
.into_iter()
|
||||||
|
.map(|path| ResponseElement {
|
||||||
|
href: path,
|
||||||
|
status: Some(StatusCode::NOT_FOUND),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Ok(MultistatusElement {
|
||||||
|
responses,
|
||||||
|
member_responses: not_found_responses,
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument(skip(req, cal_store))]
|
#[instrument(skip(req, cal_store))]
|
||||||
pub async fn route_report_calendar<C: CalendarStore>(
|
pub async fn route_report_calendar<C: CalendarStore>(
|
||||||
path: Path<(String, String)>,
|
path: Path<(String, String)>,
|
||||||
@@ -100,30 +146,37 @@ pub async fn route_report_calendar<C: CalendarStore>(
|
|||||||
|
|
||||||
Ok(match &request {
|
Ok(match &request {
|
||||||
ReportRequest::CalendarQuery(cal_query) => {
|
ReportRequest::CalendarQuery(cal_query) => {
|
||||||
handle_calendar_query(
|
let objects =
|
||||||
cal_query,
|
get_objects_calendar_query(cal_query, &principal, &cal_id, cal_store.as_ref())
|
||||||
&props,
|
.await?;
|
||||||
|
objects_response(
|
||||||
|
objects,
|
||||||
|
vec![],
|
||||||
req.path(),
|
req.path(),
|
||||||
|
&principal,
|
||||||
puri.as_ref(),
|
puri.as_ref(),
|
||||||
&user,
|
&user,
|
||||||
&principal,
|
&props,
|
||||||
&cal_id,
|
)?
|
||||||
cal_store.as_ref(),
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
}
|
}
|
||||||
ReportRequest::CalendarMultiget(cal_multiget) => {
|
ReportRequest::CalendarMultiget(cal_multiget) => {
|
||||||
handle_calendar_multiget(
|
let (objects, not_found) = get_objects_calendar_multiget(
|
||||||
cal_multiget,
|
cal_multiget,
|
||||||
&props,
|
|
||||||
req.path(),
|
req.path(),
|
||||||
puri.as_ref(),
|
|
||||||
&user,
|
|
||||||
&principal,
|
&principal,
|
||||||
&cal_id,
|
&cal_id,
|
||||||
cal_store.as_ref(),
|
cal_store.as_ref(),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
|
objects_response(
|
||||||
|
objects,
|
||||||
|
not_found,
|
||||||
|
req.path(),
|
||||||
|
&principal,
|
||||||
|
puri.as_ref(),
|
||||||
|
&user,
|
||||||
|
&props,
|
||||||
|
)?
|
||||||
}
|
}
|
||||||
ReportRequest::SyncCollection(sync_collection) => {
|
ReportRequest::SyncCollection(sync_collection) => {
|
||||||
handle_sync_collection(
|
handle_sync_collection(
|
||||||
@@ -171,7 +224,10 @@ mod tests {
|
|||||||
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
|
prop: rustical_dav::xml::PropfindType::Prop(PropElement(vec![
|
||||||
ReportPropName::Propname(Propname{name: "getetag".to_owned(), ns: Some("DAV:".into())}),
|
ReportPropName::Propname(Propname{name: "getetag".to_owned(), ns: Some("DAV:".into())}),
|
||||||
ReportPropName::Propname(Propname{name: "displayname".to_owned(), ns: Some("DAV:".into())}),
|
ReportPropName::Propname(Propname{name: "displayname".to_owned(), ns: Some("DAV:".into())}),
|
||||||
ReportPropName::CalendarData(CalendarData { comp: None, expand: Some(ExpandElement { start: "20250426T220000Z".to_owned(), end: "20250503T220000Z".to_owned() }), limit_recurrence_set: None, limit_freebusy_set: None })
|
ReportPropName::CalendarData(CalendarData { comp: None, expand: Some(ExpandElement {
|
||||||
|
start: <UtcDateTime as ValueDeserialize>::deserialize("20250426T220000Z").unwrap(),
|
||||||
|
end: <UtcDateTime as ValueDeserialize>::deserialize("20250503T220000Z").unwrap(),
|
||||||
|
}), limit_recurrence_set: None, limit_freebusy_set: None })
|
||||||
])),
|
])),
|
||||||
href: vec![
|
href: vec![
|
||||||
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
"/caldav/user/user/6f787542-5256-401a-8db97003260da/ae7a998fdfd1d84a20391168962c62b".to_owned()
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ pub enum CalDateTimeError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deref, PartialEq)]
|
#[derive(Debug, Clone, Deref, PartialEq)]
|
||||||
pub struct UtcDateTime(DateTime<Utc>);
|
pub struct UtcDateTime(pub DateTime<Utc>);
|
||||||
|
|
||||||
impl ValueDeserialize for UtcDateTime {
|
impl ValueDeserialize for UtcDateTime {
|
||||||
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
fn deserialize(val: &str) -> Result<Self, rustical_xml::XmlError> {
|
||||||
|
|||||||
Reference in New Issue
Block a user