summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Melmuk <[email protected]>2024-07-24 00:32:46 +0200
committerGitHub <[email protected]>2024-07-24 00:32:46 +0200
commitecfebaf3c77a211952c790e9d8214b6320e6956f (patch)
tree2b845cec9f3d149d060a7c29d8d5241742afce52
parent0e53f582889eef28a2bde76f22d3ffa42608eac9 (diff)
downloadvaultwarden-ecfebaf3c77a211952c790e9d8214b6320e6956f.tar.gz
vaultwarden-ecfebaf3c77a211952c790e9d8214b6320e6956f.zip
allow re-invitations of existing users (#4768)
* allow re-invitations of existing users * auto-accept existing user if mail is disabled Apply suggestions from code review Co-authored-by: Mathijs van Veluw <[email protected]> --------- Co-authored-by: Mathijs van Veluw <[email protected]>
-rw-r--r--src/api/core/organizations.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs
index 204dd56f..7b7f5896 100644
--- a/src/api/core/organizations.rs
+++ b/src/api/core/organizations.rs
@@ -997,14 +997,6 @@ async fn reinvite_user(org_id: &str, user_org: &str, headers: AdminHeaders, mut
}
async fn _reinvite_user(org_id: &str, user_org: &str, invited_by_email: &str, conn: &mut DbConn) -> EmptyResult {
- if !CONFIG.invitations_allowed() {
- err!("Invitations are not allowed.")
- }
-
- if !CONFIG.mail_enabled() {
- err!("SMTP is not configured.")
- }
-
let user_org = match UserOrganization::find_by_uuid(user_org, conn).await {
Some(user_org) => user_org,
None => err!("The user hasn't been invited to the organization."),
@@ -1019,6 +1011,10 @@ async fn _reinvite_user(org_id: &str, user_org: &str, invited_by_email: &str, co
None => err!("User not found."),
};
+ if !CONFIG.invitations_allowed() && user.password_hash.is_empty() {
+ err!("Invitations are not allowed.")
+ }
+
let org_name = match Organization::find_by_uuid(org_id, conn).await {
Some(org) => org.name,
None => err!("Error looking up organization."),
@@ -1034,9 +1030,14 @@ async fn _reinvite_user(org_id: &str, user_org: &str, invited_by_email: &str, co
Some(invited_by_email.to_string()),
)
.await?;
- } else {
+ } else if user.password_hash.is_empty() {
let invitation = Invitation::new(&user.email);
invitation.save(conn).await?;
+ } else {
+ let _ = Invitation::take(&user.email, conn).await;
+ let mut user_org = user_org;
+ user_org.status = UserOrgStatus::Accepted as i32;
+ user_org.save(conn).await?;
}
Ok(())