Skip to content

Commit

Permalink
allow re-invitations of existing users (dani-garcia#4768)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
stefan0xC and BlackDex authored Jul 23, 2024
1 parent 0e53f58 commit ecfebaf
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand All @@ -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."),
Expand All @@ -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(())
Expand Down

0 comments on commit ecfebaf

Please sign in to comment.