mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Remove hard-coded /dav paths
This commit is contained in:
@@ -41,7 +41,6 @@ pub fn configure_dav<C: CalendarStore>(
|
||||
}
|
||||
});
|
||||
|
||||
// cfg.app_data(store)
|
||||
cfg.app_data(Data::new(Context { prefix, store }))
|
||||
.service(
|
||||
web::resource("{path:.*}")
|
||||
@@ -51,7 +50,7 @@ pub fn configure_dav<C: CalendarStore>(
|
||||
)
|
||||
.service(
|
||||
web::resource("")
|
||||
.route(web::method(propfind_method()).to(root::route_propfind_root))
|
||||
.route(web::method(propfind_method()).to(root::route_propfind_root::<C>))
|
||||
.wrap(auth.clone()),
|
||||
)
|
||||
.service(
|
||||
|
||||
@@ -94,6 +94,7 @@ pub fn generate_propfind_calendar_response(
|
||||
props: Vec<&str>,
|
||||
principal: &str,
|
||||
path: &str,
|
||||
prefix: &str,
|
||||
calendar: &Calendar,
|
||||
) -> Result<String> {
|
||||
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<C: CalendarStore>(
|
||||
props.clone(),
|
||||
auth.user_id(),
|
||||
request.path(),
|
||||
&context.prefix,
|
||||
&calendar,
|
||||
)
|
||||
.map_err(|_e| Error::InternalError)?;
|
||||
|
||||
@@ -26,6 +26,7 @@ pub async fn generate_propfind_principal_response(
|
||||
props: Vec<&str>,
|
||||
principal: &str,
|
||||
path: &str,
|
||||
prefix: &str,
|
||||
) -> Result<String, quick_xml::Error> {
|
||||
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<C: CalendarStore>(
|
||||
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<C: CalendarStore>(
|
||||
}
|
||||
|
||||
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| {
|
||||
|
||||
@@ -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 <mulstistatus> object.
|
||||
@@ -22,6 +24,7 @@ pub async fn generate_propfind_root_response(
|
||||
props: Vec<&str>,
|
||||
principal: &str,
|
||||
path: &str,
|
||||
prefix: &str,
|
||||
) -> Result<String, quick_xml::Error> {
|
||||
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<C: CalendarStore>(
|
||||
body: String,
|
||||
request: HttpRequest,
|
||||
auth: BasicAuth,
|
||||
context: Data<Context<C>>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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)))?;
|
||||
|
||||
Reference in New Issue
Block a user