chore: add appflowy web url config
This commit is contained in:
parent
e33db6d8f7
commit
ab715aff7a
|
|
@ -294,6 +294,7 @@ async fn post_workspace_invite_handler(
|
||||||
&user_uuid,
|
&user_uuid,
|
||||||
&workspace_id,
|
&workspace_id,
|
||||||
invited_members,
|
invited_members,
|
||||||
|
state.config.appflowy_web_url.as_deref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(AppResponse::Ok().into())
|
Ok(AppResponse::Ok().into())
|
||||||
|
|
|
||||||
|
|
@ -327,6 +327,7 @@ pub async fn invite_workspace_members(
|
||||||
inviter: &Uuid,
|
inviter: &Uuid,
|
||||||
workspace_id: &Uuid,
|
workspace_id: &Uuid,
|
||||||
invitations: Vec<WorkspaceMemberInvitation>,
|
invitations: Vec<WorkspaceMemberInvitation>,
|
||||||
|
appflowy_web_url: Option<&str>,
|
||||||
) -> Result<(), AppError> {
|
) -> Result<(), AppError> {
|
||||||
let mut txn = pg_pool
|
let mut txn = pg_pool
|
||||||
.begin()
|
.begin()
|
||||||
|
|
@ -352,12 +353,17 @@ pub async fn invite_workspace_members(
|
||||||
let pending_invitations =
|
let pending_invitations =
|
||||||
database::workspace::select_workspace_pending_invitations(pg_pool, workspace_id).await?;
|
database::workspace::select_workspace_pending_invitations(pg_pool, workspace_id).await?;
|
||||||
|
|
||||||
for invitation in invitations {
|
// check if any of the invited users are already members of the workspace
|
||||||
|
for invitation in &invitations {
|
||||||
if workspace_members_by_email.contains_key(&invitation.email) {
|
if workspace_members_by_email.contains_key(&invitation.email) {
|
||||||
tracing::warn!("User already in workspace: {}", invitation.email);
|
return Err(AppError::InvalidRequest(format!(
|
||||||
continue;
|
"User with email {} is already a member of the workspace",
|
||||||
|
invitation.email
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for invitation in invitations {
|
||||||
let inviter_name = inviter_name.clone();
|
let inviter_name = inviter_name.clone();
|
||||||
let workspace_name = workspace_name.clone();
|
let workspace_name = workspace_name.clone();
|
||||||
let workspace_member_count = workspace_member_count.to_string();
|
let workspace_member_count = workspace_member_count.to_string();
|
||||||
|
|
@ -384,32 +390,39 @@ pub async fn invite_workspace_members(
|
||||||
.await?;
|
.await?;
|
||||||
invite_id
|
invite_id
|
||||||
},
|
},
|
||||||
Some(inv) => {
|
Some(invite_id) => {
|
||||||
tracing::warn!("User already invited: {}", invitation.email);
|
tracing::warn!("User already invited: {}", invitation.email);
|
||||||
*inv
|
*invite_id
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate a link such that when clicked, the user is added to the workspace.
|
// Generate a link such that when clicked, the user is added to the workspace.
|
||||||
let accept_url = gotrue_client
|
let accept_url = {
|
||||||
.admin_generate_link(
|
match appflowy_web_url {
|
||||||
&admin_token,
|
Some(appflowy_web_url) => format!("{}/accept-invitation?invitated_id={}", appflowy_web_url, invite_id),
|
||||||
&GenerateLinkParams {
|
None => {
|
||||||
type_: GenerateLinkType::MagicLink,
|
gotrue_client
|
||||||
email: invitation.email.clone(),
|
.admin_generate_link(
|
||||||
redirect_to: format!(
|
&admin_token,
|
||||||
"/web/login-callback?action=accept_workspace_invite&workspace_invitation_id={}&workspace_name={}&workspace_icon={}&user_name={}&user_icon={}&workspace_member_count={}",
|
&GenerateLinkParams {
|
||||||
invite_id, workspace_name,
|
type_: GenerateLinkType::MagicLink,
|
||||||
workspace_icon_url,
|
email: invitation.email.clone(),
|
||||||
inviter_name,
|
redirect_to: format!(
|
||||||
user_icon_url,
|
"/web/login-callback?action=accept_workspace_invite&workspace_invitation_id={}&workspace_name={}&workspace_icon={}&user_name={}&user_icon={}&workspace_member_count={}",
|
||||||
workspace_member_count,
|
invite_id, workspace_name,
|
||||||
),
|
workspace_icon_url,
|
||||||
..Default::default()
|
inviter_name,
|
||||||
|
user_icon_url,
|
||||||
|
workspace_member_count,
|
||||||
|
),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.action_link
|
||||||
},
|
},
|
||||||
)
|
}
|
||||||
.await?
|
};
|
||||||
.action_link;
|
|
||||||
|
|
||||||
// send email can be slow, so send email in background
|
// send email can be slow, so send email in background
|
||||||
let cloned_mailer = mailer.clone();
|
let cloned_mailer = mailer.clone();
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ pub struct Config {
|
||||||
pub published_collab: PublishedCollabSetting,
|
pub published_collab: PublishedCollabSetting,
|
||||||
pub mailer: MailerSetting,
|
pub mailer: MailerSetting,
|
||||||
pub apple_oauth: AppleOAuthSetting,
|
pub apple_oauth: AppleOAuthSetting,
|
||||||
|
pub appflowy_web_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Clone, Debug)]
|
#[derive(serde::Deserialize, Clone, Debug)]
|
||||||
|
|
@ -244,6 +245,7 @@ pub fn get_configuration() -> Result<Config, anyhow::Error> {
|
||||||
client_id: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_ID", ""),
|
client_id: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_ID", ""),
|
||||||
client_secret: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_SECRET", "").into(),
|
client_secret: get_env_var("APPFLOWY_APPLE_OAUTH_CLIENT_SECRET", "").into(),
|
||||||
},
|
},
|
||||||
|
appflowy_web_url: std::env::var("APPFLOWY_WEB_URL").ok(),
|
||||||
};
|
};
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ async fn invite_workspace_crud() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(invitation.inviter_email, Some(alice.email));
|
assert_eq!(invitation.inviter_email, Some(alice.email));
|
||||||
assert_eq!(invitation.status , AFWorkspaceInvitationStatus::Pending);
|
assert_eq!(invitation.status, AFWorkspaceInvitationStatus::Pending);
|
||||||
|
|
||||||
bob_client
|
bob_client
|
||||||
.accept_workspace_invitation(&invite_id)
|
.accept_workspace_invitation(&invite_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue