Got rid of this ServicePrefix thing

This commit is contained in:
Lennart
2024-10-04 18:15:35 +02:00
parent a2e3cd527e
commit 2aa0e173c8
4 changed files with 8 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
use crate::{ use crate::{
calendar_object::resource::{CalendarObjectProp, CalendarObjectResource}, calendar_object::resource::{CalendarObjectProp, CalendarObjectResource},
principal::PrincipalResource,
Error, Error,
}; };
use actix_web::{ use actix_web::{
@@ -27,14 +28,13 @@ pub struct CalendarMultigetRequest {
pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>( pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>(
cal_query: &CalendarMultigetRequest, cal_query: &CalendarMultigetRequest,
prefix: &str, principal_url: &str,
principal: &str, principal: &str,
cid: &str, cid: &str,
store: &RwLock<C>, store: &RwLock<C>,
) -> Result<Vec<CalendarObject>, Error> { ) -> Result<Vec<CalendarObject>, Error> {
// TODO: add proper error results for single events // TODO: add proper error results for single events
let resource_def = let resource_def = ResourceDef::prefix(principal_url).join(&ResourceDef::new("/{cid}/{uid}"));
ResourceDef::prefix(prefix).join(&ResourceDef::new("/user/{principal}/{cid}/{uid}"));
let mut result = vec![]; let mut result = vec![];
@@ -45,10 +45,6 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>(
// TODO: Handle error // TODO: Handle error
continue; continue;
}; };
if path.get("principal").unwrap() != principal {
// TODO: Handle error
continue;
}
if path.get("cid").unwrap() != cid { if path.get("cid").unwrap() != cid {
// TODO: Handle error // TODO: Handle error
continue; continue;
@@ -63,13 +59,14 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore + ?Sized>(
pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>( pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
cal_multiget: CalendarMultigetRequest, cal_multiget: CalendarMultigetRequest,
req: HttpRequest, req: HttpRequest,
prefix: &str,
principal: &str, principal: &str,
cid: &str, cid: &str,
cal_store: &RwLock<C>, cal_store: &RwLock<C>,
) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> { ) -> Result<MultistatusElement<PropstatWrapper<CalendarObjectProp>, String>, Error> {
let principal_url = PrincipalResource::get_url(req.resource_map(), vec![principal]).unwrap();
let objects = let objects =
get_objects_calendar_multiget(&cal_multiget, prefix, principal, cid, cal_store).await?; get_objects_calendar_multiget(&cal_multiget, &principal_url, principal, cid, cal_store)
.await?;
let props = match cal_multiget.prop { let props = match cal_multiget.prop {
PropfindType::Allprop => { PropfindType::Allprop => {

View File

@@ -5,7 +5,6 @@ use actix_web::{
}; };
use calendar_multiget::{handle_calendar_multiget, CalendarMultigetRequest}; use calendar_multiget::{handle_calendar_multiget, CalendarMultigetRequest};
use calendar_query::{handle_calendar_query, CalendarQueryRequest}; use calendar_query::{handle_calendar_query, CalendarQueryRequest};
use rustical_dav::methods::propfind::ServicePrefix;
use rustical_store::{auth::User, CalendarStore}; use rustical_store::{auth::User, CalendarStore};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sync_collection::{handle_sync_collection, SyncCollectionRequest}; use sync_collection::{handle_sync_collection, SyncCollectionRequest};
@@ -37,9 +36,7 @@ pub async fn route_report_calendar<C: CalendarStore + ?Sized>(
user: User, user: User,
req: HttpRequest, req: HttpRequest,
cal_store: Data<RwLock<C>>, cal_store: Data<RwLock<C>>,
prefix: Data<ServicePrefix>,
) -> Result<impl Responder, Error> { ) -> Result<impl Responder, Error> {
let prefix = prefix.into_inner();
let (principal, cid) = path.into_inner(); let (principal, cid) = path.into_inner();
if principal != user.id { if principal != user.id {
return Err(Error::Unauthorized); return Err(Error::Unauthorized);
@@ -54,8 +51,7 @@ pub async fn route_report_calendar<C: CalendarStore + ?Sized>(
handle_calendar_query(cal_query, req, &principal, &cid, &cal_store).await? handle_calendar_query(cal_query, req, &principal, &cid, &cal_store).await?
} }
ReportRequest::CalendarMultiget(cal_multiget) => { ReportRequest::CalendarMultiget(cal_multiget) => {
handle_calendar_multiget(cal_multiget, req, &prefix, &principal, &cid, &cal_store) handle_calendar_multiget(cal_multiget, req, &principal, &cid, &cal_store).await?
.await?
} }
ReportRequest::SyncCollection(sync_collection) => { ReportRequest::SyncCollection(sync_collection) => {
handle_sync_collection(sync_collection, req, &principal, &cid, &cal_store).await? handle_sync_collection(sync_collection, req, &principal, &cid, &cal_store).await?

View File

@@ -5,7 +5,7 @@ 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::{propfind::ServicePrefix, route_delete}; 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;
@@ -44,7 +44,6 @@ pub fn configure_dav<AP: AuthenticationProvider, C: CalendarStore + ?Sized>(
.app_data(Data::new(CalDavContext { .app_data(Data::new(CalDavContext {
store: store.clone(), store: store.clone(),
})) }))
.app_data(Data::new(ServicePrefix(prefix)))
.app_data(Data::from(store.clone())) .app_data(Data::from(store.clone()))
.service( .service(
web::resource("{path:.*}") web::resource("{path:.*}")

View File

@@ -7,16 +7,11 @@ use crate::xml::TagList;
use crate::Error; use crate::Error;
use actix_web::web::Path; use actix_web::web::Path;
use actix_web::HttpRequest; use actix_web::HttpRequest;
use derive_more::derive::Deref;
use rustical_store::auth::User; use rustical_store::auth::User;
use serde::Deserialize; use serde::Deserialize;
use tracing::instrument; use tracing::instrument;
use tracing_actix_web::RootSpan; use tracing_actix_web::RootSpan;
// This is not the final place for this struct
#[derive(Deref)]
pub struct ServicePrefix(pub String);
#[derive(Deserialize, Clone, Debug)] #[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct PropElement { pub struct PropElement {