diff --git a/crates/dav/src/lib.rs b/crates/dav/src/lib.rs index b0d8e53..c957d70 100644 --- a/crates/dav/src/lib.rs +++ b/crates/dav/src/lib.rs @@ -41,7 +41,6 @@ pub fn configure_dav( } }); - // cfg.app_data(store) cfg.app_data(Data::new(Context { prefix, store })) .service( web::resource("{path:.*}") @@ -51,7 +50,7 @@ pub fn configure_dav( ) .service( web::resource("") - .route(web::method(propfind_method()).to(root::route_propfind_root)) + .route(web::method(propfind_method()).to(root::route_propfind_root::)) .wrap(auth.clone()), ) .service( diff --git a/crates/dav/src/routes/calendar.rs b/crates/dav/src/routes/calendar.rs index d201b52..65261d0 100644 --- a/crates/dav/src/routes/calendar.rs +++ b/crates/dav/src/routes/calendar.rs @@ -94,6 +94,7 @@ pub fn generate_propfind_calendar_response( props: Vec<&str>, principal: &str, path: &str, + prefix: &str, calendar: &Calendar, ) -> Result { let mut props = props; @@ -126,8 +127,7 @@ pub fn generate_propfind_calendar_response( writer .create_element("href") .write_text_content(BytesText::new(&format!( - // TODO: Replace hard-coded string - "/dav/{principal}/", + "{prefix}/{principal}/", )))?; Ok(()) })?; @@ -189,6 +189,7 @@ pub async fn route_propfind_calendar( props.clone(), auth.user_id(), request.path(), + &context.prefix, &calendar, ) .map_err(|_e| Error::InternalError)?; diff --git a/crates/dav/src/routes/principal.rs b/crates/dav/src/routes/principal.rs index 86f8330..feaa7dd 100644 --- a/crates/dav/src/routes/principal.rs +++ b/crates/dav/src/routes/principal.rs @@ -26,6 +26,7 @@ pub async fn generate_propfind_principal_response( props: Vec<&str>, principal: &str, path: &str, + prefix: &str, ) -> Result { let mut props = props; if props.contains(&"allprops") { @@ -55,8 +56,9 @@ pub async fn generate_propfind_principal_response( writer.create_element(prop).write_inner_content(|writer| { writer .create_element("href") - // TODO: Replace hard-coded string - .write_text_content(BytesText::new(&format!("/dav/{principal}/",)))?; + .write_text_content(BytesText::new(&format!( + "{prefix}/{principal}/", + )))?; Ok(()) })?; } @@ -67,8 +69,7 @@ pub async fn generate_propfind_principal_response( writer .create_element("href") .write_text_content(BytesText::new(&format!( - // TODO: Replace hard-coded string - "/dav/{principal}/" + "{prefix}/{principal}/" )))?; Ok(()) })?; @@ -111,6 +112,7 @@ pub async fn route_propfind_principal( props.clone(), auth.user_id(), &format!("{}/{}", request.path(), cal.id), + &context.prefix, &cal, ) .map_err(|_e| Error::InternalError)?, @@ -119,9 +121,14 @@ pub async fn route_propfind_principal( } responses.push( - generate_propfind_principal_response(props.clone(), auth.user_id(), request.path()) - .await - .map_err(|_e| Error::InternalError)?, + generate_propfind_principal_response( + props.clone(), + auth.user_id(), + request.path(), + &context.prefix, + ) + .await + .map_err(|_e| Error::InternalError)?, ); let output = generate_multistatus(vec![Namespace::Dav, Namespace::CalDAV], |writer| { diff --git a/crates/dav/src/routes/root.rs b/crates/dav/src/routes/root.rs index 4d285cd..cfccc20 100644 --- a/crates/dav/src/routes/root.rs +++ b/crates/dav/src/routes/root.rs @@ -1,5 +1,6 @@ use actix_web::{ http::{header::ContentType, StatusCode}, + web::Data, HttpRequest, HttpResponse, }; use actix_web_httpauth::extractors::basic::BasicAuth; @@ -7,6 +8,7 @@ use quick_xml::{ events::{BytesText, Event}, Writer, }; +use rustical_store::calendar::CalendarStore; use crate::{ namespace::Namespace, @@ -14,7 +16,7 @@ use crate::{ generate_multistatus, parse_propfind, write_invalid_props_response, write_propstat_response, write_resourcetype, }, - Error, + Context, Error, }; // Executes the PROPFIND request and returns a XML string to be written into a object. @@ -22,6 +24,7 @@ pub async fn generate_propfind_root_response( props: Vec<&str>, principal: &str, path: &str, + prefix: &str, ) -> Result { let mut props = props; if props.contains(&"allprops") { @@ -45,7 +48,7 @@ pub async fn generate_propfind_root_response( .create_element("href") .write_text_content(BytesText::new( // TODO: Replace hard-coded string - &format!("/dav/{principal}",), + &format!("{prefix}/{principal}"), ))?; Ok(()) })?; @@ -61,17 +64,22 @@ pub async fn generate_propfind_root_response( Ok(std::str::from_utf8(&output_buffer)?.to_string()) } -pub async fn route_propfind_root( +pub async fn route_propfind_root( body: String, request: HttpRequest, auth: BasicAuth, + context: Data>, ) -> Result { let props = parse_propfind(&body).map_err(|_e| Error::BadRequest)?; - let responses_string = - generate_propfind_root_response(props.clone(), auth.user_id(), request.path()) - .await - .map_err(|_e| Error::InternalError)?; + let responses_string = generate_propfind_root_response( + props.clone(), + auth.user_id(), + request.path(), + &context.prefix, + ) + .await + .map_err(|_e| Error::InternalError)?; let output = generate_multistatus(vec![Namespace::Dav, Namespace::CalDAV], |writer| { writer.write_event(Event::Text(BytesText::from_escaped(responses_string)))?;