mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 20:32:48 +00:00
add ownership to calendar
This commit is contained in:
@@ -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)?;
|
||||||
|
|
||||||
|
|||||||
@@ -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>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user