From de8f992377caa0b5fab7c34b802a7ef53e36a9c6 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Tue, 3 Sep 2024 02:24:38 +0800 Subject: [PATCH] feat: admin frontend delete account button --- admin_frontend/src/ext/api.rs | 15 +++++++++++++++ admin_frontend/src/ext/entities.rs | 7 ------- admin_frontend/src/ext/error.rs | 7 ------- admin_frontend/src/web_api.rs | 13 ++++++++++++- .../templates/components/top_menu_bar.html | 7 +++++++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/admin_frontend/src/ext/api.rs b/admin_frontend/src/ext/api.rs index 126e4ed2..b82428fb 100644 --- a/admin_frontend/src/ext/api.rs +++ b/admin_frontend/src/ext/api.rs @@ -278,3 +278,18 @@ pub async fn verify_token_cloud( let _: SignInTokenResponse = from_json_response(resp).await?; Ok(()) } + +pub async fn delete_current_user( + access_token: &str, + appflowy_cloud_base_url: &str, +) -> Result<(), Error> { + let http_client = reqwest::Client::new(); + let url = format!("{}/api/user", appflowy_cloud_base_url); + let resp = http_client + .delete(url) + .header("Authorization", format!("Bearer {}", access_token)) + .send() + .await?; + check_response(resp).await?; + Ok(()) +} diff --git a/admin_frontend/src/ext/entities.rs b/admin_frontend/src/ext/entities.rs index 02c14e63..1c2a17ef 100644 --- a/admin_frontend/src/ext/entities.rs +++ b/admin_frontend/src/ext/entities.rs @@ -27,13 +27,6 @@ pub struct WorkspaceMember { pub role: String, } -#[derive(Deserialize)] -pub struct WorkspaceUsageLimit { - pub total_blob_size: i64, - pub single_blob_size: i64, - pub member_count: i64, -} - #[derive(Deserialize, Serialize)] pub struct WorkspaceBlobUsage { pub consumed_capacity: u64, diff --git a/admin_frontend/src/ext/error.rs b/admin_frontend/src/ext/error.rs index 0942921f..ee683d48 100644 --- a/admin_frontend/src/ext/error.rs +++ b/admin_frontend/src/ext/error.rs @@ -1,13 +1,6 @@ use axum::response::{IntoResponse, Response}; -use serde::Deserialize; use shared_entity::response::AppResponseError; -#[derive(Deserialize, Debug)] -pub struct AppFlowyCloudError { - pub code: String, - pub message: String, -} - #[derive(Debug)] pub enum Error { NotOk(u16, String), // HTTP status code, payload diff --git a/admin_frontend/src/web_api.rs b/admin_frontend/src/web_api.rs index 6d06e8c0..6062a7f7 100644 --- a/admin_frontend/src/web_api.rs +++ b/admin_frontend/src/web_api.rs @@ -1,6 +1,7 @@ use crate::error::WebApiError; use crate::ext::api::{ - accept_workspace_invitation, invite_user_to_workspace, leave_workspace, verify_token_cloud, + accept_workspace_invitation, delete_current_user, invite_user_to_workspace, leave_workspace, + verify_token_cloud, }; use crate::models::{ WebApiAdminCreateUserRequest, WebApiChangePasswordRequest, WebApiCreateSSOProviderRequest, @@ -39,6 +40,7 @@ pub fn router() -> Router { .route("/workspace/:workspace_id/leave", post(leave_workspace_handler)) .route("/invite/:invite_id/accept", post(invite_accept_handler)) .route("/open_app", post(open_app_handler)) + .route("/delete-account", delete(delete_account_handler)) // admin .route("/admin/user", post(admin_add_user_handler)) @@ -115,6 +117,15 @@ async fn open_app_handler(session: UserSession) -> Result, + session: UserSession, +) -> Result> { + delete_current_user(&session.token.access_token, &state.appflowy_cloud_url).await?; + Ok(htmx_redirect("/web/login")) +} + // Invite another user, this will trigger email sending // to the target user async fn invite_handler( diff --git a/admin_frontend/templates/components/top_menu_bar.html b/admin_frontend/templates/components/top_menu_bar.html index 45e48603..65b71f29 100644 --- a/admin_frontend/templates/components/top_menu_bar.html +++ b/admin_frontend/templates/components/top_menu_bar.html @@ -10,6 +10,13 @@ > {{ user.email|escape }} +
+ Delete Account +