Skip to content

Commit

Permalink
fix invitations of new users when mail is disabled
Browse files Browse the repository at this point in the history
If you add a new user that has already been Invited to another
organization they will be Accepted automatically. This should not be
possible because they cannot be Confirmed until they have completed
their registration. It is also not necessary because their invitation
will be accepted automatically once they register.
  • Loading branch information
stefan0xC committed Sep 28, 2022
1 parent 6fa6eb1 commit 4fcb004
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ async fn send_invite(org_id: String, data: JsonUpcase<InviteData>, headers: Admi

for email in data.Emails.iter() {
let email = email.to_lowercase();
let mut user_org_status = if CONFIG.mail_enabled() {
UserOrgStatus::Invited as i32
} else {
UserOrgStatus::Accepted as i32 // Automatically mark user as accepted if no email invites
};
let mut user_org_status = UserOrgStatus::Invited as i32;
let user = match User::find_by_mail(&email, &conn).await {
None => {
if !CONFIG.invitations_allowed() {
Expand All @@ -622,13 +618,16 @@ async fn send_invite(org_id: String, data: JsonUpcase<InviteData>, headers: Admi

let mut user = User::new(email.clone());
user.save(&conn).await?;
user_org_status = UserOrgStatus::Invited as i32;
user
}
Some(user) => {
if UserOrganization::find_by_user_and_org(&user.uuid, &org_id, &conn).await.is_some() {
err!(format!("User already in organization: {}", email))
} else {
// automatically accept existing users if mail is disabled
if !CONFIG.mail_enabled() && !user.password_hash.is_empty() {
user_org_status = UserOrgStatus::Accepted as i32;
}
user
}
}
Expand Down

0 comments on commit 4fcb004

Please sign in to comment.