diff --git a/crates/frontend/public/templates/pages/addressbook.html b/crates/frontend/public/templates/pages/addressbook.html index 95f3ee3..3b0d2a2 100644 --- a/crates/frontend/public/templates/pages/addressbook.html +++ b/crates/frontend/public/templates/pages/addressbook.html @@ -10,4 +10,12 @@
{{ addressbook|json }}
+

Delete

+ +
+
+ +
+
+ {% endblock %} diff --git a/crates/frontend/public/templates/pages/calendar.html b/crates/frontend/public/templates/pages/calendar.html index f27d4b4..09b287f 100644 --- a/crates/frontend/public/templates/pages/calendar.html +++ b/crates/frontend/public/templates/pages/calendar.html @@ -29,6 +29,14 @@ {% endif %} -
{{ calendar|json }}
+ +

Delete

+ +
+
+ +
+
+ {%endblock %} diff --git a/crates/frontend/src/lib.rs b/crates/frontend/src/lib.rs index b739d9c..2aece05 100644 --- a/crates/frontend/src/lib.rs +++ b/crates/frontend/src/lib.rs @@ -32,9 +32,14 @@ use oidc_user_store::OidcUserStore; use crate::{ assets::{Assets, EmbedService}, routes::{ - addressbook::{route_addressbook, route_addressbook_restore, route_create_addressbook}, + addressbook::{ + route_addressbook, route_addressbook_restore, route_create_addressbook, + route_delete_addressbook, + }, app_token::{route_delete_app_token, route_post_app_token}, - calendar::{route_calendar, route_calendar_restore, route_create_calendar}, + calendar::{ + route_calendar, route_calendar_restore, route_create_calendar, route_delete_calendar, + }, login::{route_get_login, route_post_login, route_post_logout}, user::{route_get_home, route_root, route_user_named}, }, @@ -71,6 +76,10 @@ pub fn frontend_router< "/user/{user}/calendar/{calendar}", get(route_calendar::), ) + .route( + "/user/{user}/calendar/{calendar}/delete", + post(route_delete_calendar::), + ) .route( "/user/{user}/calendar/{calendar}/restore", post(route_calendar_restore::), @@ -84,6 +93,10 @@ pub fn frontend_router< "/user/{user}/addressbook/{addressbook}", get(route_addressbook::), ) + .route( + "/user/{user}/addressbook/{addressbook}/delete", + post(route_delete_addressbook::), + ) .route( "/user/{user}/addressbook/{addressbook}/restore", post(route_addressbook_restore::), diff --git a/crates/frontend/src/routes/addressbook.rs b/crates/frontend/src/routes/addressbook.rs index d4eada0..38a38d5 100644 --- a/crates/frontend/src/routes/addressbook.rs +++ b/crates/frontend/src/routes/addressbook.rs @@ -95,3 +95,19 @@ pub async fn route_addressbook_restore( None => (StatusCode::CREATED, "Restored").into_response(), }) } + +pub async fn route_delete_addressbook( + Path((owner, addressbook_id)): Path<(String, String)>, + Extension(store): Extension>, + user: User, +) -> Result { + if !user.is_principal(&owner) { + return Ok(StatusCode::UNAUTHORIZED.into_response()); + } + + store + .delete_addressbook(&owner, &addressbook_id, true) + .await?; + + Ok(Redirect::to(&format!("/frontend/user/{}", user.id)).into_response()) +} diff --git a/crates/frontend/src/routes/calendar.rs b/crates/frontend/src/routes/calendar.rs index fe69f21..cf4ae61 100644 --- a/crates/frontend/src/routes/calendar.rs +++ b/crates/frontend/src/routes/calendar.rs @@ -125,3 +125,17 @@ pub async fn route_calendar_restore( None => (StatusCode::CREATED, "Restored").into_response(), }) } + +pub async fn route_delete_calendar( + Path((owner, cal_id)): Path<(String, String)>, + Extension(store): Extension>, + user: User, +) -> Result { + if !user.is_principal(&owner) { + return Ok(StatusCode::UNAUTHORIZED.into_response()); + } + + store.delete_calendar(&owner, &cal_id, true).await?; + + Ok(Redirect::to(&format!("/frontend/user/{}", user.id)).into_response()) +}