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