add ownership to calendar

This commit is contained in:
Lennart
2023-09-07 19:05:13 +02:00
parent 3ea88f2f3c
commit 0d460cb983
2 changed files with 14 additions and 12 deletions

View File

@@ -103,7 +103,7 @@ pub async fn route_propfind_principal<A: CheckAuthentication, C: CalendarStore>(
.store .store
.read() .read()
.await .await
.get_calendars() .get_calendars(user)
.await .await
.map_err(|_e| Error::InternalError)?; .map_err(|_e| Error::InternalError)?;

View File

@@ -32,6 +32,7 @@ impl Event {
pub struct Calendar { pub struct Calendar {
pub id: String, pub id: String,
pub name: Option<String>, pub name: Option<String>,
pub owner: String,
pub ics: String, pub ics: String,
} }
@@ -40,12 +41,12 @@ impl Calendar {}
#[async_trait] #[async_trait]
pub trait CalendarStore: Send + Sync + 'static { pub trait CalendarStore: Send + Sync + 'static {
async fn get_calendar(&self, id: &str) -> Result<Calendar>; async fn get_calendar(&self, id: &str) -> Result<Calendar>;
async fn get_calendars(&self) -> Result<Vec<Calendar>>; async fn get_calendars(&self, owner: &str) -> Result<Vec<Calendar>>;
async fn get_events(&self, cid: &str) -> Result<Vec<Event>>; async fn get_events(&self, cid: &str) -> Result<Vec<Event>>;
async fn get_event(&self, uid: &str) -> Result<Event>; async fn get_event(&self, cid: &str, uid: &str) -> Result<Event>;
async fn upsert_event(&mut self, uid: String, ics: String) -> Result<()>; async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()>;
async fn delete_event(&mut self, uid: &str) -> Result<()>; async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()>;
} }
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
@@ -73,17 +74,18 @@ impl TomlCalendarStore {
} }
#[async_trait] #[async_trait]
impl CalendarStore for JsonCalendarStore { impl CalendarStore for TomlCalendarStore {
async fn get_calendar(&self, id: &str) -> Result<Calendar> { async fn get_calendar(&self, id: &str) -> Result<Calendar> {
Ok(self.calendars.get(id).ok_or(anyhow!("not found"))?.clone()) Ok(self.calendars.get(id).ok_or(anyhow!("not found"))?.clone())
} }
async fn get_calendars(&self) -> Result<Vec<Calendar>> { async fn get_calendars(&self, user: &str) -> Result<Vec<Calendar>> {
Ok(vec![Calendar { Ok(self
id: "test".to_string(), .calendars
name: Some("test".to_string()), .values()
ics: "asd".to_string(), .filter(|Calendar { owner, .. }| owner == user)
}]) .cloned()
.collect())
} }
async fn get_events(&self, _cid: &str) -> Result<Vec<Event>> { async fn get_events(&self, _cid: &str) -> Result<Vec<Event>> {