From b23fe2b9b1c40e433a035c2d8ceac8b9965e469b Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Thu, 21 Mar 2024 02:03:27 +0800 Subject: [PATCH] feat: leave workspace --- admin_frontend/src/ext/api.rs | 20 +++++++++++++++++++ admin_frontend/src/web_api.rs | 20 ++++++++++++++++++- .../components/shared_workspaces.html | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/admin_frontend/src/ext/api.rs b/admin_frontend/src/ext/api.rs index 4fdd6d4d..c4c1d883 100644 --- a/admin_frontend/src/ext/api.rs +++ b/admin_frontend/src/ext/api.rs @@ -238,6 +238,26 @@ pub async fn invite_user_to_workspace( check_response(resp).await } +pub async fn leave_workspace( + access_token: &str, + workspace_id: &str, + appflowy_cloud_base_url: &str, +) -> Result<(), Error> { + let http_client = reqwest::Client::new(); + let url = format!( + "{}/api/workspace/{}/leave", + appflowy_cloud_base_url, workspace_id + ); + let resp = http_client + .post(url) + .header("Authorization", format!("Bearer {}", access_token)) + .json(&()) + .send() + .await?; + + check_response(resp).await +} + pub async fn accept_workspace_invitation( access_token: &str, invite_id: &str, diff --git a/admin_frontend/src/web_api.rs b/admin_frontend/src/web_api.rs index e91159c5..3eed0e94 100644 --- a/admin_frontend/src/web_api.rs +++ b/admin_frontend/src/web_api.rs @@ -1,5 +1,7 @@ use crate::error::WebApiError; -use crate::ext::api::{accept_workspace_invitation, invite_user_to_workspace, verify_token_cloud}; +use crate::ext::api::{ + accept_workspace_invitation, invite_user_to_workspace, leave_workspace, verify_token_cloud, +}; use crate::models::{ WebApiAdminCreateUserRequest, WebApiChangePasswordRequest, WebApiCreateSSOProviderRequest, WebApiInviteUserRequest, WebApiPutUserRequest, @@ -34,6 +36,7 @@ pub fn router() -> Router { .route("/oauth_login/:provider", post(post_oauth_login_handler)) .route("/invite", post(invite_handler)) .route("/workspace/:workspace_id/invite", post(workspace_invite_handler)) + .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)) @@ -148,6 +151,21 @@ pub async fn workspace_invite_handler( Ok(WebApiResponse::<()>::from_str("Invitation sent".into())) } +pub async fn leave_workspace_handler( + State(state): State, + session: UserSession, + Path(workspace_id): Path, +) -> Result, WebApiError<'static>> { + leave_workspace( + &session.token.access_token, + &workspace_id, + &state.appflowy_cloud_url, + ) + .await?; + + Ok(WebApiResponse::<()>::from_str("Left workspace".into())) +} + pub async fn invite_accept_handler( State(state): State, session: UserSession, diff --git a/admin_frontend/templates/components/shared_workspaces.html b/admin_frontend/templates/components/shared_workspaces.html index 781ac61f..3e148a8d 100644 --- a/admin_frontend/templates/components/shared_workspaces.html +++ b/admin_frontend/templates/components/shared_workspaces.html @@ -13,7 +13,7 @@