mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 18:58:18 +00:00
PUT calendar_object: Allow omission of timezones as in RFC7809
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::calendar::methods::report::route_report_calendar;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use crate::calendar_object::CalendarObjectResourceService;
|
||||
use crate::calendar_object::resource::CalendarObjectResource;
|
||||
use crate::{CalDavPrincipalUri, Error};
|
||||
use crate::{CalDavConfig, CalDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use axum::extract::Request;
|
||||
@@ -23,6 +23,7 @@ use tower::Service;
|
||||
pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> {
|
||||
pub(crate) cal_store: Arc<C>,
|
||||
pub(crate) sub_store: Arc<S>,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C, S> {
|
||||
@@ -30,15 +31,17 @@ impl<C: CalendarStore, S: SubscriptionStore> Clone for CalendarResourceService<C
|
||||
Self {
|
||||
cal_store: self.cal_store.clone(),
|
||||
sub_store: self.sub_store.clone(),
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
||||
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>) -> Self {
|
||||
pub const fn new(cal_store: Arc<C>, sub_store: Arc<S>, config: Arc<CalDavConfig>) -> Self {
|
||||
Self {
|
||||
cal_store,
|
||||
sub_store,
|
||||
config,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +115,8 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
||||
Router::new()
|
||||
.nest(
|
||||
"/{object_id}",
|
||||
CalendarObjectResourceService::new(self.cal_store.clone()).axum_router(),
|
||||
CalendarObjectResourceService::new(self.cal_store.clone(), self.config.clone())
|
||||
.axum_router(),
|
||||
)
|
||||
.route_service("/", self.axum_service())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use axum::body::Body;
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum_extra::TypedHeader;
|
||||
use caldata::parser::ParserOptions;
|
||||
use headers::{ContentType, ETag, HeaderMapExt, IfNoneMatch};
|
||||
use http::{HeaderMap, HeaderValue, Method, StatusCode};
|
||||
use rustical_ical::CalendarObject;
|
||||
@@ -20,7 +21,10 @@ pub async fn get_event<C: CalendarStore>(
|
||||
calendar_id,
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
State(CalendarObjectResourceService {
|
||||
cal_store,
|
||||
config: _,
|
||||
}): State<CalendarObjectResourceService<C>>,
|
||||
user: Principal,
|
||||
method: Method,
|
||||
) -> Result<Response, Error> {
|
||||
@@ -57,7 +61,9 @@ pub async fn put_event<C: CalendarStore>(
|
||||
calendar_id,
|
||||
object_id,
|
||||
}): Path<CalendarObjectPathComponents>,
|
||||
State(CalendarObjectResourceService { cal_store }): State<CalendarObjectResourceService<C>>,
|
||||
State(CalendarObjectResourceService { cal_store, config }): State<
|
||||
CalendarObjectResourceService<C>,
|
||||
>,
|
||||
user: Principal,
|
||||
mut if_none_match: Option<TypedHeader<IfNoneMatch>>,
|
||||
header_map: HeaderMap,
|
||||
@@ -94,7 +100,12 @@ pub async fn put_event<C: CalendarStore>(
|
||||
true
|
||||
};
|
||||
|
||||
let object = match CalendarObject::from_ics(body.clone()) {
|
||||
let object = match CalendarObject::import(
|
||||
&body,
|
||||
Some(ParserOptions {
|
||||
rfc7809: config.rfc7809,
|
||||
}),
|
||||
) {
|
||||
Ok(object) => object,
|
||||
Err(err) => {
|
||||
warn!("invalid calendar data:\n{body}");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
CalDavPrincipalUri, Error,
|
||||
CalDavConfig, CalDavPrincipalUri, Error,
|
||||
calendar_object::{
|
||||
methods::{get_event, put_event},
|
||||
resource::CalendarObjectResource,
|
||||
@@ -24,19 +24,21 @@ pub struct CalendarObjectPathComponents {
|
||||
|
||||
pub struct CalendarObjectResourceService<C: CalendarStore> {
|
||||
pub(crate) cal_store: Arc<C>,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<C: CalendarStore> Clone for CalendarObjectResourceService<C> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
cal_store: self.cal_store.clone(),
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: CalendarStore> CalendarObjectResourceService<C> {
|
||||
pub const fn new(cal_store: Arc<C>) -> Self {
|
||||
Self { cal_store }
|
||||
pub const fn new(cal_store: Arc<C>, config: Arc<CalDavConfig>) -> Self {
|
||||
Self { cal_store, config }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use rustical_dav::resources::RootResourceService;
|
||||
use rustical_store::auth::middleware::AuthenticationLayer;
|
||||
use rustical_store::auth::{AuthenticationProvider, Principal};
|
||||
use rustical_store::{CalendarStore, SubscriptionStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod calendar;
|
||||
@@ -34,6 +35,7 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
||||
store: Arc<C>,
|
||||
subscription_store: Arc<S>,
|
||||
simplified_home_set: bool,
|
||||
config: Arc<CalDavConfig>,
|
||||
) -> Router {
|
||||
Router::new().nest(
|
||||
prefix,
|
||||
@@ -42,9 +44,27 @@ pub fn caldav_router<AP: AuthenticationProvider, C: CalendarStore, S: Subscripti
|
||||
sub_store: subscription_store,
|
||||
cal_store: store,
|
||||
simplified_home_set,
|
||||
config,
|
||||
})
|
||||
.axum_router()
|
||||
.layer(AuthenticationLayer::new(auth_provider))
|
||||
.layer(Extension(CalDavPrincipalUri(prefix))),
|
||||
)
|
||||
}
|
||||
|
||||
const fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
pub struct CalDavConfig {
|
||||
#[serde(default = "default_true")]
|
||||
rfc7809: bool,
|
||||
}
|
||||
|
||||
impl Default for CalDavConfig {
|
||||
fn default() -> Self {
|
||||
Self { rfc7809: true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::calendar::CalendarResourceService;
|
||||
use crate::calendar::resource::CalendarResource;
|
||||
use crate::principal::PrincipalResource;
|
||||
use crate::{CalDavPrincipalUri, Error};
|
||||
use crate::{CalDavConfig, CalDavPrincipalUri, Error};
|
||||
use async_trait::async_trait;
|
||||
use axum::Router;
|
||||
use rustical_dav::resource::{AxumMethods, ResourceService};
|
||||
@@ -20,6 +20,7 @@ pub struct PrincipalResourceService<
|
||||
pub(crate) cal_store: Arc<CS>,
|
||||
// If true only return the principal as the calendar home set, otherwise also groups
|
||||
pub(crate) simplified_home_set: bool,
|
||||
pub(crate) config: Arc<CalDavConfig>,
|
||||
}
|
||||
|
||||
impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
|
||||
@@ -31,6 +32,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Clone
|
||||
sub_store: self.sub_store.clone(),
|
||||
cal_store: self.cal_store.clone(),
|
||||
simplified_home_set: self.simplified_home_set,
|
||||
config: self.config.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,8 +86,12 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
||||
Router::new()
|
||||
.nest(
|
||||
"/{calendar_id}",
|
||||
CalendarResourceService::new(self.cal_store.clone(), self.sub_store.clone())
|
||||
.axum_router(),
|
||||
CalendarResourceService::new(
|
||||
self.cal_store.clone(),
|
||||
self.sub_store.clone(),
|
||||
self.config.clone(),
|
||||
)
|
||||
.axum_router(),
|
||||
)
|
||||
.route_service("/", self.axum_service())
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ async fn test_principal_resource(
|
||||
sub_store: Arc::new(sub_store),
|
||||
auth_provider: Arc::new(auth_provider),
|
||||
simplified_home_set: false,
|
||||
config: Default::default(),
|
||||
};
|
||||
|
||||
// We don't have any calendars here
|
||||
|
||||
Reference in New Issue
Block a user