principal: Add auth checking and fix member path

This commit is contained in:
Lennart
2024-05-27 15:38:00 +02:00
parent 27d8967413
commit fe5f3207ae

View File

@@ -97,8 +97,11 @@ impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
async fn new( async fn new(
req: HttpRequest, req: HttpRequest,
auth_info: AuthInfo, auth_info: AuthInfo,
_path_components: Self::PathComponents, (principal,): Self::PathComponents,
) -> Result<Self, rustical_dav::error::Error> { ) -> Result<Self, rustical_dav::error::Error> {
if auth_info.user_id != principal {
return Err(rustical_dav::error::Error::Unauthorized);
}
let cal_store = req let cal_store = req
.app_data::<Data<RwLock<C>>>() .app_data::<Data<RwLock<C>>>()
.ok_or(anyhow!("no calendar store in app_data!"))? .ok_or(anyhow!("no calendar store in app_data!"))?
@@ -108,7 +111,7 @@ impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
Ok(Self { Ok(Self {
cal_store, cal_store,
path: req.path().to_owned(), path: req.path().to_owned(),
principal: auth_info.user_id, principal,
}) })
} }
@@ -129,9 +132,9 @@ impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
Ok(calendars Ok(calendars
.into_iter() .into_iter()
.map(|cal| CalendarFile { .map(|cal| CalendarFile {
path: format!("{}/{}", &self.path, &cal.id),
calendar: cal, calendar: cal,
principal: self.principal.to_owned(), principal: self.principal.to_owned(),
path: self.path.to_owned(),
}) })
.collect()) .collect())
} }