Ensure all routes check for authorization

This commit is contained in:
Lennart
2025-01-19 00:20:16 +01:00
parent 130f754cdd
commit 6485b89c73
9 changed files with 59 additions and 13 deletions

View File

@@ -1,8 +1,11 @@
use crate::calendar::resource::CalendarResource;
use crate::Error;
use actix_web::http::header;
use actix_web::web::{Data, Path};
use actix_web::{HttpRequest, HttpResponse};
use rustical_dav::privileges::UserPrivilege;
use rustical_dav::push::PushRegister;
use rustical_dav::resource::Resource;
use rustical_store::auth::User;
use rustical_store::{CalendarStore, Subscription, SubscriptionStore};
use rustical_xml::XmlDocument;
@@ -25,6 +28,18 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
}
let calendar = store.get_calendar(&principal, &cal_id).await?;
let calendar_resource = CalendarResource {
cal: calendar,
read_only: true,
};
if !calendar_resource
.get_user_privileges(&user)?
.has(&UserPrivilege::Read)
{
return Err(Error::Unauthorized);
}
let request = PushRegister::parse_str(&body)?;
let sub_id = uuid::Uuid::new_v4().to_string();
@@ -42,7 +57,7 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
.web_push_subscription
.push_resource
.to_owned(),
topic: calendar.push_topic,
topic: calendar_resource.cal.push_topic,
expiration: expires.naive_local(),
};
subscription_store.upsert_subscription(subscription).await?;