feat: leave workspace
This commit is contained in:
parent
65491b921f
commit
b23fe2b9b1
|
|
@ -238,6 +238,26 @@ pub async fn invite_user_to_workspace(
|
||||||
check_response(resp).await
|
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(
|
pub async fn accept_workspace_invitation(
|
||||||
access_token: &str,
|
access_token: &str,
|
||||||
invite_id: &str,
|
invite_id: &str,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use crate::error::WebApiError;
|
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::{
|
use crate::models::{
|
||||||
WebApiAdminCreateUserRequest, WebApiChangePasswordRequest, WebApiCreateSSOProviderRequest,
|
WebApiAdminCreateUserRequest, WebApiChangePasswordRequest, WebApiCreateSSOProviderRequest,
|
||||||
WebApiInviteUserRequest, WebApiPutUserRequest,
|
WebApiInviteUserRequest, WebApiPutUserRequest,
|
||||||
|
|
@ -34,6 +36,7 @@ pub fn router() -> Router<AppState> {
|
||||||
.route("/oauth_login/:provider", post(post_oauth_login_handler))
|
.route("/oauth_login/:provider", post(post_oauth_login_handler))
|
||||||
.route("/invite", post(invite_handler))
|
.route("/invite", post(invite_handler))
|
||||||
.route("/workspace/:workspace_id/invite", post(workspace_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("/invite/:invite_id/accept", post(invite_accept_handler))
|
||||||
.route("/open_app", post(open_app_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()))
|
Ok(WebApiResponse::<()>::from_str("Invitation sent".into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn leave_workspace_handler(
|
||||||
|
State(state): State<AppState>,
|
||||||
|
session: UserSession,
|
||||||
|
Path(workspace_id): Path<String>,
|
||||||
|
) -> Result<WebApiResponse<()>, 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(
|
pub async fn invite_accept_handler(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
session: UserSession,
|
session: UserSession,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<td>
|
<td>
|
||||||
<button
|
<button
|
||||||
class="button red"
|
class="button red"
|
||||||
hx-delete="/web-api/workspace/{{ shared_workspace.workspace_id|escape }}/leave"
|
hx-post="/web-api/workspace/{{ shared_workspace.workspace_id|escape }}/leave"
|
||||||
hx-confirm="Are you sure?"
|
hx-confirm="Are you sure?"
|
||||||
hx-target="closest tr"
|
hx-target="closest tr"
|
||||||
hx-swap="delete"
|
hx-swap="delete"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue