forked from dani-garcia/vaultwarden
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Group/Organization mapping to trigger invitation
- Loading branch information
Showing
12 changed files
with
359 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod organization_logic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use crate::{ | ||
api::{core::log_event, core::organizations::CollectionData, ApiResult}, | ||
auth::ClientIp, | ||
db::models::*, | ||
db::DbConn, | ||
mail, CONFIG, | ||
}; | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub async fn invite( | ||
user: &User, | ||
device: &Device, | ||
ip: &ClientIp, | ||
org: &Organization, | ||
user_org_type: UserOrgType, | ||
groups: &Vec<String>, | ||
access_all: bool, | ||
collections: &Vec<CollectionData>, | ||
invited_by_email: String, | ||
conn: &mut DbConn, | ||
) -> ApiResult<()> { | ||
let mut user_org_status = UserOrgStatus::Invited; | ||
|
||
// automatically accept existing users if mail is disabled | ||
if (!CONFIG.mail_enabled() && !user.password_hash.is_empty()) | ||
|| (CONFIG.sso_enabled() && CONFIG.sso_acceptall_invites()) | ||
{ | ||
user_org_status = UserOrgStatus::Accepted; | ||
} | ||
|
||
let mut new_uo = UserOrganization::new(user.uuid.clone(), org.uuid.clone(), Some(invited_by_email.clone())); | ||
new_uo.access_all = access_all; | ||
new_uo.atype = user_org_type as i32; | ||
new_uo.status = user_org_status as i32; | ||
|
||
// If no accessAll, add the collections received | ||
if !access_all { | ||
for col in collections { | ||
match Collection::find_by_uuid_and_org(&col.Id, &org.uuid, conn).await { | ||
None => err!("Collection not found in Organization"), | ||
Some(collection) => { | ||
CollectionUser::save(&user.uuid, &collection.uuid, col.ReadOnly, col.HidePasswords, conn).await?; | ||
} | ||
} | ||
} | ||
} | ||
|
||
new_uo.save(conn).await?; | ||
|
||
for group in groups { | ||
let mut group_entry = GroupUser::new(group.clone(), user.uuid.clone()); | ||
group_entry.save(conn).await?; | ||
} | ||
|
||
log_event( | ||
EventType::OrganizationUserInvited as i32, | ||
&new_uo.uuid, | ||
&org.uuid, | ||
&user.uuid, | ||
device.atype, | ||
&ip.ip, | ||
conn, | ||
) | ||
.await; | ||
|
||
if CONFIG.mail_enabled() { | ||
match user_org_status { | ||
UserOrgStatus::Invited => { | ||
mail::send_invite( | ||
&user.email, | ||
&user.uuid, | ||
Some(org.uuid.clone()), | ||
Some(new_uo.uuid), | ||
&org.name, | ||
new_uo.invited_by_email.clone(), | ||
) | ||
.await? | ||
} | ||
UserOrgStatus::Accepted => { | ||
mail::send_org_enrolled(&user.email, &org.name, Some(invited_by_email.clone())).await?; | ||
mail::send_invite_accepted(&user.email, &invited_by_email, &org.name).await?; | ||
} | ||
UserOrgStatus::Revoked | UserOrgStatus::Confirmed => (), | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.