diff --git a/Cargo.lock b/Cargo.lock index 00886f8..fc63227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -385,59 +385,44 @@ dependencies = [ [[package]] name = "askama" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543" dependencies = [ "askama_derive", - "askama_escape", - "humansize", - "num-traits", + "itoa", "percent-encoding", "serde", "serde_json", - "serde_yaml", -] - -[[package]] -name = "askama_actix" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4b0dd17cfe203b00ba3853a89fba459ecf24c759b738b244133330607c78e55" -dependencies = [ - "actix-web", - "askama", ] [[package]] name = "askama_derive" -version = "0.12.5" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6" dependencies = [ "askama_parser", "basic-toml", - "mime", - "mime_guess", + "memchr", "proc-macro2", "quote", + "rustc-hash", "serde", + "serde_derive", "syn", ] -[[package]] -name = "askama_escape" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" - [[package]] name = "askama_parser" -version = "0.2.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f" dependencies = [ - "nom", + "memchr", + "serde", + "serde_derive", + "winnow", ] [[package]] @@ -1396,15 +1381,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humansize" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" -dependencies = [ - "libm", -] - [[package]] name = "hyper" version = "1.6.0" @@ -1844,12 +1820,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.8.7" @@ -1877,16 +1847,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e94e1e6445d314f972ff7395df2de295fe51b71821694f0b0e1e79c4f12c8577" -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2868,7 +2828,6 @@ dependencies = [ "actix-session", "actix-web", "askama", - "askama_actix", "futures-core", "hex", "mime_guess", @@ -2886,7 +2845,6 @@ dependencies = [ "actix-session", "actix-web", "askama", - "askama_actix", "chrono", "futures-core", "hex", @@ -3096,19 +3054,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_yaml" -version = "0.9.34+deprecated" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" -dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", - "unsafe-libyaml", -] - [[package]] name = "sha1" version = "0.10.6" @@ -3901,12 +3846,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "unsafe-libyaml" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" - [[package]] name = "untrusted" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 5278f75..2d21899 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,13 +73,7 @@ derive_more = { version = "2.0", features = [ "deref", "constructor", ] } -askama = { version = "0.12", features = [ - "serde", - "with-actix-web", - "serde-json", - "serde-yaml", -] } -askama_actix = "0.14" +askama = { version = "0.13", features = ["serde_json"] } sqlx = { version = "0.8", default-features = false, features = [ "sqlx-sqlite", "uuid", diff --git a/crates/frontend/Cargo.toml b/crates/frontend/Cargo.toml index 842a90a..d9be442 100644 --- a/crates/frontend/Cargo.toml +++ b/crates/frontend/Cargo.toml @@ -8,7 +8,6 @@ publish = false [dependencies] askama.workspace = true -askama_actix = { workspace = true } actix-session = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/crates/frontend/public/templates/pages/addressbook.html b/crates/frontend/public/templates/pages/addressbook.html index f956a9e..9673939 100644 --- a/crates/frontend/public/templates/pages/addressbook.html +++ b/crates/frontend/public/templates/pages/addressbook.html @@ -8,7 +8,7 @@

{{ name }}

{% if let Some(description) = addressbook.description %}

{{ description }}

{% endif%} -
{{ addressbook|yaml }}
+
{{ addressbook|json }}
Back {% endblock %} diff --git a/crates/frontend/public/templates/pages/calendar.html b/crates/frontend/public/templates/pages/calendar.html index 832471c..d044145 100644 --- a/crates/frontend/public/templates/pages/calendar.html +++ b/crates/frontend/public/templates/pages/calendar.html @@ -8,7 +8,7 @@

{{ name }}

{% if let Some(description) = calendar.description %}

{{ description }}

{% endif%} -
{{ calendar|yaml }}
+
{{ calendar|json }}
Back {% endblock %} diff --git a/crates/frontend/src/lib.rs b/crates/frontend/src/lib.rs index a835772..5a45bd2 100644 --- a/crates/frontend/src/lib.rs +++ b/crates/frontend/src/lib.rs @@ -6,11 +6,10 @@ use actix_web::{ dev::ServiceResponse, http::{Method, StatusCode}, middleware::{ErrorHandlerResponse, ErrorHandlers}, - web::{self, Data, Path}, + web::{self, Data, Html, Path}, HttpRequest, HttpResponse, Responder, }; use askama::Template; -use askama_actix::TemplateToResponse; use assets::{Assets, EmbedService}; use routes::{ addressbook::{route_addressbook, route_addressbook_restore}, @@ -44,6 +43,7 @@ async fn route_user( cal_store: Data, addr_store: Data, user: User, + req: HttpRequest, ) -> impl Responder { // TODO: Check for authorization let user_id = path.into_inner(); @@ -51,14 +51,19 @@ async fn route_user( return actix_web::HttpResponse::Unauthorized().body("Unauthorized"); } - UserPage { - calendars: cal_store.get_calendars(&user.id).await.unwrap(), - deleted_calendars: cal_store.get_deleted_calendars(&user.id).await.unwrap(), - addressbooks: addr_store.get_addressbooks(&user.id).await.unwrap(), - deleted_addressbooks: addr_store.get_deleted_addressbooks(&user.id).await.unwrap(), - user_id: user.id, - } - .to_response() + Html::new( + UserPage { + calendars: cal_store.get_calendars(&user.id).await.unwrap(), + deleted_calendars: cal_store.get_deleted_calendars(&user.id).await.unwrap(), + addressbooks: addr_store.get_addressbooks(&user.id).await.unwrap(), + deleted_addressbooks: addr_store.get_deleted_addressbooks(&user.id).await.unwrap(), + user_id: user.id, + } + .render() + .unwrap(), + ) + .respond_to(&req) + .map_into_boxed_body() } async fn route_root(user: Option, req: HttpRequest) -> impl Responder { diff --git a/crates/frontend/src/routes/addressbook.rs b/crates/frontend/src/routes/addressbook.rs index 3d98dda..4c7e9fb 100644 --- a/crates/frontend/src/routes/addressbook.rs +++ b/crates/frontend/src/routes/addressbook.rs @@ -1,10 +1,9 @@ use actix_web::{ http::{header, StatusCode}, - web::{self, Data, Path}, + web::{self, Data, Html, Path}, HttpRequest, HttpResponse, Responder, }; use askama::Template; -use askama_actix::TemplateToResponse; use rustical_store::{auth::User, Addressbook, AddressbookStore}; #[derive(Template)] @@ -17,15 +16,21 @@ pub async fn route_addressbook( path: Path<(String, String)>, store: Data, user: User, + req: HttpRequest, ) -> Result { let (owner, addrbook_id) = path.into_inner(); if !user.is_principal(&owner) { return Ok(HttpResponse::Unauthorized().body("Unauthorized")); } - Ok(AddressbookPage { - addressbook: store.get_addressbook(&owner, &addrbook_id).await?, - } - .to_response()) + Ok(Html::new( + AddressbookPage { + addressbook: store.get_addressbook(&owner, &addrbook_id).await?, + } + .render() + .unwrap(), + ) + .respond_to(&req) + .map_into_boxed_body()) } pub async fn route_addressbook_restore( diff --git a/crates/frontend/src/routes/calendar.rs b/crates/frontend/src/routes/calendar.rs index f584eab..b70fad2 100644 --- a/crates/frontend/src/routes/calendar.rs +++ b/crates/frontend/src/routes/calendar.rs @@ -1,10 +1,9 @@ use actix_web::{ http::{header, StatusCode}, - web::{self, Data, Path}, + web::{self, Data, Html, Path}, HttpRequest, HttpResponse, Responder, }; use askama::Template; -use askama_actix::TemplateToResponse; use rustical_store::{auth::User, Calendar, CalendarStore}; #[derive(Template)] @@ -17,15 +16,21 @@ pub async fn route_calendar( path: Path<(String, String)>, store: Data, user: User, + req: HttpRequest, ) -> Result { let (owner, cal_id) = path.into_inner(); if !user.is_principal(&owner) { return Ok(HttpResponse::Unauthorized().body("Unauthorized")); } - Ok(CalendarPage { - calendar: store.get_calendar(&owner, &cal_id).await?, - } - .to_response()) + Ok(Html::new( + CalendarPage { + calendar: store.get_calendar(&owner, &cal_id).await?, + } + .render() + .unwrap(), + ) + .respond_to(&req) + .map_into_boxed_body()) } pub async fn route_calendar_restore( diff --git a/crates/frontend/src/routes/login.rs b/crates/frontend/src/routes/login.rs index 1c54466..44f1e58 100644 --- a/crates/frontend/src/routes/login.rs +++ b/crates/frontend/src/routes/login.rs @@ -1,7 +1,7 @@ use actix_session::Session; use actix_web::{ error::ErrorUnauthorized, - web::{Data, Form, Redirect}, + web::{Data, Form, Html, Redirect}, HttpRequest, HttpResponse, Responder, }; use askama::Template; @@ -12,8 +12,10 @@ use serde::Deserialize; #[template(path = "pages/login.html")] struct LoginPage; -pub async fn route_get_login() -> impl Responder { - LoginPage +pub async fn route_get_login(req: HttpRequest) -> impl Responder { + Html::new(LoginPage.render().unwrap()) + .respond_to(&req) + .map_into_boxed_body() } #[derive(Deserialize)] diff --git a/crates/nextcloud_login/Cargo.toml b/crates/nextcloud_login/Cargo.toml index 447016f..ea8330f 100644 --- a/crates/nextcloud_login/Cargo.toml +++ b/crates/nextcloud_login/Cargo.toml @@ -8,7 +8,6 @@ publish = false [dependencies] askama.workspace = true -askama_actix = { workspace = true } actix-session = { workspace = true } serde = { workspace = true } thiserror = { workspace = true } diff --git a/crates/nextcloud_login/src/lib.rs b/crates/nextcloud_login/src/lib.rs index 8a2f6d7..cef7beb 100644 --- a/crates/nextcloud_login/src/lib.rs +++ b/crates/nextcloud_login/src/lib.rs @@ -1,6 +1,6 @@ use actix_web::{ http::header::{self}, - web::{self, Data, Form, Json, Path, ServiceConfig}, + web::{self, Data, Form, Html, Json, Path, ServiceConfig}, HttpRequest, HttpResponse, Responder, }; use askama::Template; @@ -155,11 +155,16 @@ async fn get_nextcloud_flow( ) -> Result { let flow_id = path.into_inner(); if let Some(flow) = state.flows.read().await.get(&flow_id) { - Ok(NextcloudLoginPage { - username: user.displayname.unwrap_or(user.id), - app_name: flow.app_name.to_owned(), - } - .respond_to(&req)) + Ok(Html::new( + NextcloudLoginPage { + username: user.displayname.unwrap_or(user.id), + app_name: flow.app_name.to_owned(), + } + .render() + .unwrap(), + ) + .respond_to(&req) + .map_into_boxed_body()) } else { Ok(HttpResponse::NotFound().body("Login flow not found")) } @@ -191,10 +196,15 @@ async fn post_nextcloud_flow( login_name: user.id.to_owned(), app_password: generate_app_token(), }); - Ok(NextcloudLoginSuccessPage { - app_name: flow.app_name.to_owned(), - } - .respond_to(&req)) + Ok(Html::new( + NextcloudLoginSuccessPage { + app_name: flow.app_name.to_owned(), + } + .render() + .unwrap(), + ) + .respond_to(&req) + .map_into_boxed_body()) } else { Ok(HttpResponse::NotFound().body("Login flow not found")) }