mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-10-11 21:59:59 +00:00
Add accepted organization data to sync response (#7666)
This commit is contained in:
@@ -162,6 +162,12 @@ async fn sync(data: SyncData, headers: Headers, client_version: Option<ClientVer
|
||||
let policies_json: Vec<Value> =
|
||||
OrgPolicy::find_confirmed_by_user(&headers.user.uuid, &conn).await.iter().map(OrgPolicy::to_json).collect();
|
||||
|
||||
let policies_new_json: Vec<Value> = OrgPolicy::find_accepted_and_confirmed_by_user(&headers.user.uuid, &conn)
|
||||
.await
|
||||
.iter()
|
||||
.map(OrgPolicy::to_json)
|
||||
.collect();
|
||||
|
||||
let domains_json = if data.exclude_domains {
|
||||
Value::Null
|
||||
} else {
|
||||
@@ -194,6 +200,7 @@ async fn sync(data: SyncData, headers: Headers, client_version: Option<ClientVer
|
||||
"folders": folders_json,
|
||||
"collections": collections_json,
|
||||
"policies": policies_json,
|
||||
"policiesNew": policies_new_json,
|
||||
"ciphers": ciphers_json,
|
||||
"domains": domains_json,
|
||||
"sends": sends_json,
|
||||
|
||||
@@ -187,6 +187,26 @@ impl OrgPolicy {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_accepted_and_confirmed_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<Self> {
|
||||
conn.run(move |conn| {
|
||||
org_policies::table
|
||||
.inner_join(
|
||||
users_organizations::table.on(users_organizations::org_uuid
|
||||
.eq(org_policies::org_uuid)
|
||||
.and(users_organizations::user_uuid.eq(user_uuid))),
|
||||
)
|
||||
.filter(
|
||||
users_organizations::status
|
||||
.eq(MembershipStatus::Accepted as i32)
|
||||
.or(users_organizations::status.eq(MembershipStatus::Confirmed as i32)),
|
||||
)
|
||||
.select(org_policies::all_columns)
|
||||
.load::<Self>(conn)
|
||||
.expect("Error loading org_policy")
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_by_org_and_type(
|
||||
org_uuid: &OrganizationId,
|
||||
policy_type: OrgPolicyType,
|
||||
|
||||
@@ -844,6 +844,21 @@ impl Membership {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_accepted_and_confirmed_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<Self> {
|
||||
conn.run(move |conn| {
|
||||
users_organizations::table
|
||||
.filter(users_organizations::user_uuid.eq(user_uuid))
|
||||
.filter(
|
||||
users_organizations::status
|
||||
.eq(MembershipStatus::Accepted as i32)
|
||||
.or(users_organizations::status.eq(MembershipStatus::Confirmed as i32)),
|
||||
)
|
||||
.load::<Self>(conn)
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn find_invited_by_user(user_uuid: &UserId, conn: &DbConn) -> Vec<Self> {
|
||||
conn.run(move |conn| {
|
||||
users_organizations::table
|
||||
|
||||
@@ -263,6 +263,11 @@ impl User {
|
||||
orgs_json.push(c.to_json(conn).await);
|
||||
}
|
||||
|
||||
let mut orgs_new_json = Vec::new();
|
||||
for c in Membership::find_accepted_and_confirmed_by_user(&self.uuid, conn).await {
|
||||
orgs_new_json.push(c.to_json(conn).await);
|
||||
}
|
||||
|
||||
let twofactor_enabled = !TwoFactor::find_by_user(&self.uuid, conn).await.is_empty();
|
||||
|
||||
// TODO: Might want to save the status field in the DB
|
||||
@@ -303,6 +308,7 @@ impl User {
|
||||
"privateKey": self.private_key,
|
||||
"securityStamp": self.security_stamp,
|
||||
"organizations": orgs_json,
|
||||
"organizationsNew": orgs_new_json,
|
||||
"providers": [],
|
||||
"providerOrganizations": [],
|
||||
"forcePasswordReset": false,
|
||||
|
||||
Reference in New Issue
Block a user