Add .ics and .vcf suffix to object resources

This fixes #61
This commit is contained in:
Lennart
2025-05-02 14:55:11 +02:00
parent 99388cf992
commit a78dd4a451
10 changed files with 49 additions and 70 deletions

View File

@@ -1,9 +1,9 @@
use crate::Error;
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use actix_web::http::header;
use actix_web::http::header::HeaderValue;
use actix_web::web::{Data, Path};
use actix_web::HttpRequest;
use actix_web::HttpResponse;
use rustical_store::auth::User;
use rustical_store::{CalendarObject, CalendarStore};
use tracing::instrument;
@@ -20,7 +20,7 @@ pub async fn get_event<C: CalendarStore>(
) -> Result<HttpResponse, Error> {
let CalendarObjectPathComponents {
principal,
cal_id,
calendar_id,
object_id,
} = path.into_inner();
@@ -28,12 +28,14 @@ pub async fn get_event<C: CalendarStore>(
return Ok(HttpResponse::Unauthorized().body(""));
}
let calendar = store.get_calendar(&principal, &cal_id).await?;
let calendar = store.get_calendar(&principal, &calendar_id).await?;
if !user.is_principal(&calendar.principal) {
return Ok(HttpResponse::Unauthorized().body(""));
}
let event = store.get_object(&principal, &cal_id, &object_id).await?;
let event = store
.get_object(&principal, &calendar_id, &object_id)
.await?;
Ok(HttpResponse::Ok()
.insert_header(("ETag", event.get_etag()))
@@ -52,7 +54,7 @@ pub async fn put_event<C: CalendarStore>(
) -> Result<HttpResponse, Error> {
let CalendarObjectPathComponents {
principal,
cal_id,
calendar_id,
object_id,
} = path.into_inner();
@@ -65,7 +67,7 @@ pub async fn put_event<C: CalendarStore>(
let object = CalendarObject::from_ics(object_id, body)?;
store
.put_object(principal, cal_id, object, overwrite)
.put_object(principal, calendar_id, object, overwrite)
.await?;
Ok(HttpResponse::Created().body(""))

View File

@@ -105,31 +105,13 @@ impl Resource for CalendarObjectResource {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize)]
pub struct CalendarObjectPathComponents {
pub principal: String,
pub cal_id: String,
pub calendar_id: String,
pub object_id: String,
}
impl<'de> Deserialize<'de> for CalendarObjectPathComponents {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
type Inner = (String, String, String);
let (principal, calendar, mut object) = Inner::deserialize(deserializer)?;
if object.ends_with(".ics") {
object.truncate(object.len() - 4);
}
Ok(Self {
principal,
cal_id: calendar,
object_id: object,
})
}
}
#[async_trait(?Send)]
impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
type PathComponents = CalendarObjectPathComponents;
@@ -142,13 +124,13 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
&self,
CalendarObjectPathComponents {
principal,
cal_id,
calendar_id,
object_id,
}: &Self::PathComponents,
) -> Result<Self::Resource, Self::Error> {
let object = self
.cal_store
.get_object(principal, cal_id, object_id)
.get_object(principal, calendar_id, object_id)
.await?;
Ok(CalendarObjectResource {
object,
@@ -160,13 +142,13 @@ impl<C: CalendarStore> ResourceService for CalendarObjectResourceService<C> {
&self,
CalendarObjectPathComponents {
principal,
cal_id,
calendar_id,
object_id,
}: &Self::PathComponents,
use_trashbin: bool,
) -> Result<(), Self::Error> {
self.cal_store
.delete_object(principal, cal_id, object_id, use_trashbin)
.delete_object(principal, calendar_id, object_id, use_trashbin)
.await?;
Ok(())
}