Browse Source

Add accepted organization data to sync response

pull/7666/head
Tom 7 days ago
parent
commit
4c9deb4837
  1. 7
      src/api/core/ciphers.rs
  2. 20
      src/db/models/org_policy.rs
  3. 15
      src/db/models/organization.rs
  4. 6
      src/db/models/user.rs

7
src/api/core/ciphers.rs

@ -161,6 +161,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 {
@ -193,6 +199,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,

20
src/db/models/org_policy.rs

@ -186,6 +186,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,

15
src/db/models/organization.rs

@ -861,6 +861,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

6
src/db/models/user.rs

@ -259,6 +259,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
@ -299,6 +304,7 @@ impl User {
"privateKey": self.private_key,
"securityStamp": self.security_stamp,
"organizations": orgs_json,
"organizationsNew": orgs_new_json,
"providers": [],
"providerOrganizations": [],
"forcePasswordReset": false,

Loading…
Cancel
Save