ezidam: apps: handle when application is archived

This commit is contained in:
Philippe Loctaux 2023-04-02 02:12:22 +02:00
parent 4b8b82e577
commit 317dc23735
4 changed files with 30 additions and 0 deletions

View file

@ -31,4 +31,7 @@ impl App {
pub fn redirect_uri(&self) -> &str {
&self.redirect_uri
}
pub fn is_archived(&self) -> bool {
self.is_archived
}
}

View file

@ -52,4 +52,8 @@ impl Error {
pub fn forbidden<M: std::fmt::Display>(value: M) -> Self {
Self::new(Status::Forbidden, value)
}
pub fn gone<M: std::fmt::Display>(value: M) -> Self {
Self::new(Status::Gone, value)
}
}

View file

@ -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?;

View file

@ -97,7 +97,9 @@
</td>
<td class="sort-redirect-uri">{{ app.redirect_uri }}</td>
<td>
{% if app.is_archived == false %}
<a href="apps/{{ app.id }}">Details</a>
{% endif %}
</td>
</tr>
{% endfor %}