From 317dc23735b0ed1c88c9b23ec007e80883b77266 Mon Sep 17 00:00:00 2001
From: Philippe Loctaux
Date: Sun, 2 Apr 2023 02:12:22 +0200
Subject: [PATCH] ezidam: apps: handle when application is archived
---
crates/apps/src/lib.rs | 3 +++
crates/ezidam/src/error.rs | 4 ++++
crates/ezidam/src/routes/admin/apps.rs | 21 +++++++++++++++++++
.../templates/pages/admin/apps/list.html.tera | 2 ++
4 files changed, 30 insertions(+)
diff --git a/crates/apps/src/lib.rs b/crates/apps/src/lib.rs
index b4d4278..a0bb7a0 100644
--- a/crates/apps/src/lib.rs
+++ b/crates/apps/src/lib.rs
@@ -31,4 +31,7 @@ impl App {
pub fn redirect_uri(&self) -> &str {
&self.redirect_uri
}
+ pub fn is_archived(&self) -> bool {
+ self.is_archived
+ }
}
diff --git a/crates/ezidam/src/error.rs b/crates/ezidam/src/error.rs
index 26659c8..687295d 100644
--- a/crates/ezidam/src/error.rs
+++ b/crates/ezidam/src/error.rs
@@ -52,4 +52,8 @@ impl Error {
pub fn forbidden(value: M) -> Self {
Self::new(Status::Forbidden, value)
}
+
+ pub fn gone(value: M) -> Self {
+ Self::new(Status::Gone, value)
+ }
}
diff --git a/crates/ezidam/src/routes/admin/apps.rs b/crates/ezidam/src/routes/admin/apps.rs
index feb7906..a34842b 100644
--- a/crates/ezidam/src/routes/admin/apps.rs
+++ b/crates/ezidam/src/routes/admin/apps.rs
@@ -86,6 +86,13 @@ pub async fn admin_apps_view(
.await?
.ok_or_else(|| Error::not_found(app_id.to_string()))?;
+ if app.is_archived() {
+ return Err(Error::gone(format!(
+ "Application \"{}\" is archived",
+ app.label()
+ )));
+ }
+
let page = Page::AdminAppsView(super::content::AdminAppsView { user: admin.0, app });
Ok(flash
@@ -144,6 +151,13 @@ pub async fn admin_apps_new_secret(
.await?
.ok_or_else(|| Error::not_found(app_id.to_string()))?;
+ if app.is_archived() {
+ return Err(Error::gone(format!(
+ "Application \"{}\" is archived",
+ app.label()
+ )));
+ }
+
// Generate secret
let app_secret = task::spawn_blocking(SecretString::default).await?;
let app_secret_string = app_secret.to_string();
@@ -191,6 +205,13 @@ pub async fn admin_apps_archive(
.await?
.ok_or_else(|| Error::not_found(app_id.to_string()))?;
+ if app.is_archived() {
+ return Err(Error::gone(format!(
+ "Application \"{}\" is archived",
+ app.label()
+ )));
+ }
+
// Archive
app.archive(&mut transaction).await?;
diff --git a/crates/ezidam/templates/pages/admin/apps/list.html.tera b/crates/ezidam/templates/pages/admin/apps/list.html.tera
index 7dbc18e..5fa6b7f 100644
--- a/crates/ezidam/templates/pages/admin/apps/list.html.tera
+++ b/crates/ezidam/templates/pages/admin/apps/list.html.tera
@@ -97,7 +97,9 @@
| {{ app.redirect_uri }} |
+ {% if app.is_archived == false %}
Details
+ {% endif %}
|
{% endfor %}