Browse Source

fix cargo fmt

pull/2667/head
MFijak 3 years ago
committed by Maximilian Fijak
parent
commit
c6a707a352
  1. 2
      src/api/core/ciphers.rs
  2. 169
      src/api/core/organizations.rs
  3. 23
      src/db/models/cipher.rs
  4. 2
      src/db/models/collection.rs
  5. 30
      src/db/models/group.rs
  6. 4
      src/db/models/mod.rs
  7. 2
      src/db/models/organization.rs

2
src/api/core/ciphers.rs

@ -1565,7 +1565,7 @@ impl CipherSyncData {
user_organizations, user_organizations,
user_collections, user_collections,
user_collections_groups, user_collections_groups,
user_groups user_groups,
} }
} }
} }

169
src/api/core/organizations.rs

@ -301,7 +301,8 @@ async fn post_organization_collections(
for group in data.Groups { for group in data.Groups {
CollectionGroup::new(collection.uuid.clone(), group.Id, group.ReadOnly, group.HidePasswords) CollectionGroup::new(collection.uuid.clone(), group.Id, group.ReadOnly, group.HidePasswords)
.save(&conn).await?; .save(&conn)
.await?;
} }
// If the user doesn't have access to all collections, only in case of a Manger, // If the user doesn't have access to all collections, only in case of a Manger,
@ -355,8 +356,7 @@ async fn post_organization_collection_update(
CollectionGroup::delete_all_by_collection(&col_id, &conn).await?; CollectionGroup::delete_all_by_collection(&col_id, &conn).await?;
for group in data.Groups { for group in data.Groups {
CollectionGroup::new(col_id.clone(), group.Id, group.ReadOnly, group.HidePasswords) CollectionGroup::new(col_id.clone(), group.Id, group.ReadOnly, group.HidePasswords).save(&conn).await?;
.save(&conn).await?;
} }
Ok(Json(collection.to_json())) Ok(Json(collection.to_json()))
@ -454,9 +454,12 @@ async fn get_org_collection_detail(
err!("Collection is not owned by organization") err!("Collection is not owned by organization")
} }
let groups: Vec<Value> = CollectionGroup::find_by_collection(&collection.uuid, &conn).await let groups: Vec<Value> = CollectionGroup::find_by_collection(&collection.uuid, &conn)
.await
.iter() .iter()
.map(|collection_group| SelectionReadOnly::to_collection_group_details_read_only(collection_group).to_json()) .map(|collection_group| {
SelectionReadOnly::to_collection_group_details_read_only(collection_group).to_json()
})
.collect(); .collect();
let mut json_object = collection.to_json(); let mut json_object = collection.to_json();
@ -1532,10 +1535,7 @@ async fn import(org_id: String, data: JsonUpcase<OrgImportData>, headers: Header
#[get("/organizations/<org_id>/groups")] #[get("/organizations/<org_id>/groups")]
async fn get_groups(org_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn get_groups(org_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult {
let groups = Group::find_by_organization(&org_id, &conn).await let groups = Group::find_by_organization(&org_id, &conn).await.iter().map(Group::to_json).collect::<Value>();
.iter()
.map(Group::to_json)
.collect::<Value>();
Ok(Json(json!({ Ok(Json(json!({
"Data": groups, "Data": groups,
@ -1550,28 +1550,23 @@ struct GroupRequest {
Name: String, Name: String,
AccessAll: Option<bool>, AccessAll: Option<bool>,
ExternalId: String, ExternalId: String,
Collections: Vec<SelectionReadOnly> Collections: Vec<SelectionReadOnly>,
} }
impl GroupRequest { impl GroupRequest {
pub fn to_group(&self, organizations_uuid: &str) -> Result<Group, String> { pub fn to_group(&self, organizations_uuid: &str) -> Result<Group, String> {
let access_all_value = match self.AccessAll { let access_all_value = match self.AccessAll {
Some(value) => value, Some(value) => value,
_ => return Err(String::from("Could not convert GroupRequest to Group, because AccessAll has no value!")) _ => return Err(String::from("Could not convert GroupRequest to Group, because AccessAll has no value!")),
}; };
Ok(Group::new( Ok(Group::new(organizations_uuid.to_owned(), self.Name.clone(), access_all_value, self.ExternalId.clone()))
organizations_uuid.to_owned(),
self.Name.clone(),
access_all_value,
self.ExternalId.clone()
))
} }
pub fn update_group(&self, mut group: Group) -> Result<Group, String> { pub fn update_group(&self, mut group: Group) -> Result<Group, String> {
let access_all_value = match self.AccessAll { let access_all_value = match self.AccessAll {
Some(value) => value, Some(value) => value,
_ => return Err(String::from("Could not update group, because AccessAll has no value!")) _ => return Err(String::from("Could not update group, because AccessAll has no value!")),
}; };
group.name = self.Name.clone(); group.name = self.Name.clone();
@ -1587,67 +1582,79 @@ impl GroupRequest {
struct SelectionReadOnly { struct SelectionReadOnly {
Id: String, Id: String,
ReadOnly: bool, ReadOnly: bool,
HidePasswords: bool HidePasswords: bool,
} }
impl SelectionReadOnly { impl SelectionReadOnly {
pub fn to_collection_group (&self, groups_uuid: String) -> CollectionGroup { pub fn to_collection_group(&self, groups_uuid: String) -> CollectionGroup {
CollectionGroup::new ( CollectionGroup::new(self.Id.clone(), groups_uuid, self.ReadOnly, self.HidePasswords)
self.Id.clone(),
groups_uuid,
self.ReadOnly,
self.HidePasswords
)
} }
pub fn to_group_details_read_only (collection_group: &CollectionGroup) -> SelectionReadOnly { pub fn to_group_details_read_only(collection_group: &CollectionGroup) -> SelectionReadOnly {
SelectionReadOnly { SelectionReadOnly {
Id: collection_group.collections_uuid.clone(), Id: collection_group.collections_uuid.clone(),
ReadOnly: collection_group.read_only, ReadOnly: collection_group.read_only,
HidePasswords: collection_group.hide_passwords HidePasswords: collection_group.hide_passwords,
} }
} }
pub fn to_collection_group_details_read_only (collection_group: &CollectionGroup) -> SelectionReadOnly { pub fn to_collection_group_details_read_only(collection_group: &CollectionGroup) -> SelectionReadOnly {
SelectionReadOnly { SelectionReadOnly {
Id: collection_group.groups_uuid.clone(), Id: collection_group.groups_uuid.clone(),
ReadOnly: collection_group.read_only, ReadOnly: collection_group.read_only,
HidePasswords: collection_group.hide_passwords HidePasswords: collection_group.hide_passwords,
} }
} }
pub fn to_json (&self) -> Value { pub fn to_json(&self) -> Value {
json!(self) json!(self)
} }
} }
#[post("/organizations/<_org_id>/groups/<group_id>", data = "<data>")] #[post("/organizations/<_org_id>/groups/<group_id>", data = "<data>")]
async fn post_group(_org_id: String, group_id: String, data: JsonUpcase<GroupRequest>, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn post_group(
_org_id: String,
group_id: String,
data: JsonUpcase<GroupRequest>,
_headers: AdminHeaders,
conn: DbConn,
) -> JsonResult {
put_group(_org_id, group_id, data, _headers, conn).await put_group(_org_id, group_id, data, _headers, conn).await
} }
#[post("/organizations/<org_id>/groups", data = "<data>")] #[post("/organizations/<org_id>/groups", data = "<data>")]
async fn post_groups(org_id: String, _headers: AdminHeaders, data: JsonUpcase<GroupRequest>, conn: DbConn) -> JsonResult { async fn post_groups(
org_id: String,
_headers: AdminHeaders,
data: JsonUpcase<GroupRequest>,
conn: DbConn,
) -> JsonResult {
let group_request = data.into_inner().data; let group_request = data.into_inner().data;
let group = match group_request.to_group(&org_id) { let group = match group_request.to_group(&org_id) {
Ok(group) => group, Ok(group) => group,
Err(err) => err!(&err) Err(err) => err!(&err),
}; };
add_update_group(group, group_request.Collections, &conn).await add_update_group(group, group_request.Collections, &conn).await
} }
#[put("/organizations/<_org_id>/groups/<group_id>", data = "<data>")] #[put("/organizations/<_org_id>/groups/<group_id>", data = "<data>")]
async fn put_group(_org_id: String, group_id: String, data: JsonUpcase<GroupRequest>, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn put_group(
_org_id: String,
group_id: String,
data: JsonUpcase<GroupRequest>,
_headers: AdminHeaders,
conn: DbConn,
) -> JsonResult {
let group = match Group::find_by_uuid(&group_id, &conn).await { let group = match Group::find_by_uuid(&group_id, &conn).await {
Some(group) => group, Some(group) => group,
None => err!("Group not found") None => err!("Group not found"),
}; };
let group_request = data.into_inner().data; let group_request = data.into_inner().data;
let updated_group = match group_request.update_group(group) { let updated_group = match group_request.update_group(group) {
Ok(group) => group, Ok(group) => group,
Err(err) => err!(&err) Err(err) => err!(&err),
}; };
CollectionGroup::delete_all_by_group(&group_id, &conn).await?; CollectionGroup::delete_all_by_group(&group_id, &conn).await?;
@ -1677,10 +1684,11 @@ async fn add_update_group(mut group: Group, collections: Vec<SelectionReadOnly>,
async fn get_group_details(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn get_group_details(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult {
let group = match Group::find_by_uuid(&group_id, &conn).await { let group = match Group::find_by_uuid(&group_id, &conn).await {
Some(group) => group, Some(group) => group,
_ => err!("Group could not be found!") _ => err!("Group could not be found!"),
}; };
let collections_groups = CollectionGroup::find_by_group(&group_id, &conn).await let collections_groups = CollectionGroup::find_by_group(&group_id, &conn)
.await
.iter() .iter()
.map(|entry| SelectionReadOnly::to_group_details_read_only(entry).to_json()) .map(|entry| SelectionReadOnly::to_group_details_read_only(entry).to_json())
.collect::<Value>(); .collect::<Value>();
@ -1704,7 +1712,7 @@ async fn post_delete_group(org_id: String, group_id: String, _headers: AdminHead
async fn delete_group(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { async fn delete_group(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult {
let group = match Group::find_by_uuid(&group_id, &conn).await { let group = match Group::find_by_uuid(&group_id, &conn).await {
Some(group) => group, Some(group) => group,
_ => err!("Group not found") _ => err!("Group not found"),
}; };
group.delete(&conn).await group.delete(&conn).await
@ -1714,7 +1722,7 @@ async fn delete_group(_org_id: String, group_id: String, _headers: AdminHeaders,
async fn get_group(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn get_group(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult {
let group = match Group::find_by_uuid(&group_id, &conn).await { let group = match Group::find_by_uuid(&group_id, &conn).await {
Some(group) => group, Some(group) => group,
_ => err!("Group not found") _ => err!("Group not found"),
}; };
Ok(Json(group.to_json())) Ok(Json(group.to_json()))
@ -1723,11 +1731,12 @@ async fn get_group(_org_id: String, group_id: String, _headers: AdminHeaders, co
#[get("/organizations/<_org_id>/groups/<group_id>/users")] #[get("/organizations/<_org_id>/groups/<group_id>/users")]
async fn get_group_users(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn get_group_users(_org_id: String, group_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult {
match Group::find_by_uuid(&group_id, &conn).await { match Group::find_by_uuid(&group_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("Group could not be found!") _ => err!("Group could not be found!"),
}; };
let group_users: Vec<String> = GroupUser::find_by_group(&group_id, &conn).await let group_users: Vec<String> = GroupUser::find_by_group(&group_id, &conn)
.await
.iter() .iter()
.map(|entry| entry.users_organizations_uuid.clone()) .map(|entry| entry.users_organizations_uuid.clone())
.collect(); .collect();
@ -1736,10 +1745,16 @@ async fn get_group_users(_org_id: String, group_id: String, _headers: AdminHeade
} }
#[put("/organizations/<_org_id>/groups/<group_id>/users", data = "<data>")] #[put("/organizations/<_org_id>/groups/<group_id>/users", data = "<data>")]
async fn put_group_users(_org_id: String, group_id: String, _headers: AdminHeaders, data: JsonVec<String>, conn: DbConn) -> EmptyResult { async fn put_group_users(
_org_id: String,
group_id: String,
_headers: AdminHeaders,
data: JsonVec<String>,
conn: DbConn,
) -> EmptyResult {
match Group::find_by_uuid(&group_id, &conn).await { match Group::find_by_uuid(&group_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("Group could not be found!") _ => err!("Group could not be found!"),
}; };
GroupUser::delete_all_by_group(&group_id, &conn).await?; GroupUser::delete_all_by_group(&group_id, &conn).await?;
@ -1756,14 +1771,12 @@ async fn put_group_users(_org_id: String, group_id: String, _headers: AdminHeade
#[get("/organizations/<_org_id>/users/<user_id>/groups")] #[get("/organizations/<_org_id>/users/<user_id>/groups")]
async fn get_user_groups(_org_id: String, user_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult { async fn get_user_groups(_org_id: String, user_id: String, _headers: AdminHeaders, conn: DbConn) -> JsonResult {
match UserOrganization::find_by_uuid(&user_id, &conn).await { match UserOrganization::find_by_uuid(&user_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("User could not be found!") _ => err!("User could not be found!"),
}; };
let user_groups: Vec<String> = GroupUser::find_by_user(&user_id, &conn).await let user_groups: Vec<String> =
.iter() GroupUser::find_by_user(&user_id, &conn).await.iter().map(|entry| entry.groups_uuid.clone()).collect();
.map(|entry| entry.groups_uuid.clone())
.collect();
Ok(Json(json!(user_groups))) Ok(Json(json!(user_groups)))
} }
@ -1771,19 +1784,31 @@ async fn get_user_groups(_org_id: String, user_id: String, _headers: AdminHeader
#[derive(Deserialize)] #[derive(Deserialize)]
#[allow(non_snake_case)] #[allow(non_snake_case)]
struct OrganizationUserUpdateGroupsRequest { struct OrganizationUserUpdateGroupsRequest {
GroupIds: Vec<String> GroupIds: Vec<String>,
} }
#[post("/organizations/<_org_id>/users/<user_id>/groups", data ="<data>")] #[post("/organizations/<_org_id>/users/<user_id>/groups", data = "<data>")]
async fn post_user_groups(_org_id: String, user_id: String, data: JsonUpcase<OrganizationUserUpdateGroupsRequest>, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { async fn post_user_groups(
_org_id: String,
user_id: String,
data: JsonUpcase<OrganizationUserUpdateGroupsRequest>,
_headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
put_user_groups(_org_id, user_id, data, _headers, conn).await put_user_groups(_org_id, user_id, data, _headers, conn).await
} }
#[put("/organizations/<_org_id>/users/<user_id>/groups", data ="<data>")] #[put("/organizations/<_org_id>/users/<user_id>/groups", data = "<data>")]
async fn put_user_groups(_org_id: String, user_id: String, data: JsonUpcase<OrganizationUserUpdateGroupsRequest>, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { async fn put_user_groups(
_org_id: String,
user_id: String,
data: JsonUpcase<OrganizationUserUpdateGroupsRequest>,
_headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
match UserOrganization::find_by_uuid(&user_id, &conn).await { match UserOrganization::find_by_uuid(&user_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("User could not be found!") _ => err!("User could not be found!"),
}; };
GroupUser::delete_all_by_user(&user_id, &conn).await?; GroupUser::delete_all_by_user(&user_id, &conn).await?;
@ -1798,20 +1823,32 @@ async fn put_user_groups(_org_id: String, user_id: String, data: JsonUpcase<Orga
} }
#[post("/organizations/<org_id>/groups/<group_id>/delete-user/<user_id>")] #[post("/organizations/<org_id>/groups/<group_id>/delete-user/<user_id>")]
async fn post_delete_group_user(org_id: String, group_id: String, user_id: String, headers: AdminHeaders, conn: DbConn) -> EmptyResult { async fn post_delete_group_user(
org_id: String,
group_id: String,
user_id: String,
headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
delete_group_user(org_id, group_id, user_id, headers, conn).await delete_group_user(org_id, group_id, user_id, headers, conn).await
} }
#[delete("/organizations/<_org_id>/groups/<group_id>/users/<user_id>")] #[delete("/organizations/<_org_id>/groups/<group_id>/users/<user_id>")]
async fn delete_group_user(_org_id: String, group_id: String, user_id: String, _headers: AdminHeaders, conn: DbConn) -> EmptyResult { async fn delete_group_user(
_org_id: String,
group_id: String,
user_id: String,
_headers: AdminHeaders,
conn: DbConn,
) -> EmptyResult {
match UserOrganization::find_by_uuid(&user_id, &conn).await { match UserOrganization::find_by_uuid(&user_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("User could not be found!") _ => err!("User could not be found!"),
}; };
match Group::find_by_uuid(&group_id, &conn).await { match Group::find_by_uuid(&group_id, &conn).await {
Some(_) => { /* Do nothing */ }, Some(_) => { /* Do nothing */ }
_ => err!("Group could not be found!") _ => err!("Group could not be found!"),
}; };
GroupUser::delete_by_group_id_and_user_id(&group_id, &user_id, &conn).await GroupUser::delete_by_group_id_and_user_id(&group_id, &user_id, &conn).await

23
src/db/models/cipher.rs

@ -2,7 +2,9 @@ use crate::CONFIG;
use chrono::{Duration, NaiveDateTime, Utc}; use chrono::{Duration, NaiveDateTime, Utc};
use serde_json::Value; use serde_json::Value;
use super::{Attachment, CollectionCipher, Favorite, FolderCipher, User, UserOrgStatus, UserOrgType, UserOrganization, Group}; use super::{
Attachment, CollectionCipher, Favorite, FolderCipher, Group, User, UserOrgStatus, UserOrgType, UserOrganization,
};
use crate::api::core::CipherSyncData; use crate::api::core::CipherSyncData;
@ -362,12 +364,8 @@ impl Cipher {
conn: &DbConn, conn: &DbConn,
) -> bool { ) -> bool {
match cipher_sync_data { match cipher_sync_data {
Some(cipher_sync_data) => { Some(cipher_sync_data) => cipher_sync_data.user_groups.iter().any(|group| group.access_all),
cipher_sync_data.user_groups.iter().any(|group| group.access_all) None => Group::is_in_full_access_group(user_uuid, conn).await,
},
None => {
Group::is_in_full_access_group(user_uuid, conn).await
}
} }
} }
@ -385,7 +383,10 @@ impl Cipher {
// Check whether this cipher is directly owned by the user, or is in // Check whether this cipher is directly owned by the user, or is in
// a collection that the user has full access to. If so, there are no // a collection that the user has full access to. If so, there are no
// access restrictions. // access restrictions.
if self.is_owned_by_user(user_uuid) || self.is_in_full_access_org(user_uuid, cipher_sync_data, conn).await || self.is_in_full_access_group(user_uuid, cipher_sync_data, conn).await { if self.is_owned_by_user(user_uuid)
|| self.is_in_full_access_org(user_uuid, cipher_sync_data, conn).await
|| self.is_in_full_access_group(user_uuid, cipher_sync_data, conn).await
{
return Some((false, false)); return Some((false, false));
} }
@ -399,9 +400,11 @@ impl Cipher {
} }
//Group permissions //Group permissions
if let Some(gc) = cipher_sync_data.user_collections_groups if let Some(gc) = cipher_sync_data
.user_collections_groups
.iter() .iter()
.find(|collection_group| collection_group.collections_uuid == collection.clone()) { .find(|collection_group| collection_group.collections_uuid == collection.clone())
{
rows.push((gc.read_only, gc.hide_passwords)); rows.push((gc.read_only, gc.hide_passwords));
} }
} }

2
src/db/models/collection.rs

@ -1,6 +1,6 @@
use serde_json::Value; use serde_json::Value;
use super::{User, UserOrgStatus, UserOrgType, UserOrganization, CollectionGroup}; use super::{CollectionGroup, User, UserOrgStatus, UserOrgType, UserOrganization};
db_object! { db_object! {
#[derive(Identifiable, Queryable, Insertable, AsChangeset)] #[derive(Identifiable, Queryable, Insertable, AsChangeset)]

30
src/db/models/group.rs

@ -1,5 +1,5 @@
use serde_json::Value;
use chrono::{NaiveDateTime, Utc}; use chrono::{NaiveDateTime, Utc};
use serde_json::Value;
db_object! { db_object! {
#[derive(Identifiable, Queryable, Insertable, AsChangeset)] #[derive(Identifiable, Queryable, Insertable, AsChangeset)]
@ -46,7 +46,7 @@ impl Group {
access_all, access_all,
external_id, external_id,
creation_date: now, creation_date: now,
revision_date: now revision_date: now,
} }
} }
@ -71,16 +71,16 @@ impl CollectionGroup {
collections_uuid, collections_uuid,
groups_uuid, groups_uuid,
read_only, read_only,
hide_passwords hide_passwords,
} }
} }
} }
impl GroupUser { impl GroupUser {
pub fn new (groups_uuid: String, users_organizations_uuid: String) -> Self { pub fn new(groups_uuid: String, users_organizations_uuid: String) -> Self {
Self { Self {
groups_uuid, groups_uuid,
users_organizations_uuid users_organizations_uuid,
} }
} }
} }
@ -90,7 +90,7 @@ use crate::db::DbConn;
use crate::api::EmptyResult; use crate::api::EmptyResult;
use crate::error::MapResult; use crate::error::MapResult;
use super::{UserOrganization, User}; use super::{User, UserOrganization};
/// Database methods /// Database methods
impl Group { impl Group {
@ -128,7 +128,7 @@ impl Group {
} }
} }
pub async fn find_by_organization (organizations_uuid: &str, conn: &DbConn) -> Vec<Self> { pub async fn find_by_organization(organizations_uuid: &str, conn: &DbConn) -> Vec<Self> {
db_run! { conn: { db_run! { conn: {
groups::table groups::table
.filter(groups::organizations_uuid.eq(organizations_uuid)) .filter(groups::organizations_uuid.eq(organizations_uuid))
@ -138,7 +138,7 @@ impl Group {
}} }}
} }
pub async fn find_by_uuid (uuid: &str, conn: &DbConn) -> Option<Self> { pub async fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
db_run! { conn: { db_run! { conn: {
groups::table groups::table
.filter(groups::uuid.eq(uuid)) .filter(groups::uuid.eq(uuid))
@ -267,7 +267,7 @@ impl CollectionGroup {
} }
} }
pub async fn find_by_group (group_uuid: &str, conn: &DbConn) -> Vec<Self> { pub async fn find_by_group(group_uuid: &str, conn: &DbConn) -> Vec<Self> {
db_run! { conn: { db_run! { conn: {
collections_groups::table collections_groups::table
.filter(collections_groups::groups_uuid.eq(group_uuid)) .filter(collections_groups::groups_uuid.eq(group_uuid))
@ -422,14 +422,18 @@ impl GroupUser {
pub async fn update_user_revision(&self, conn: &DbConn) { pub async fn update_user_revision(&self, conn: &DbConn) {
match UserOrganization::find_by_uuid(&self.users_organizations_uuid, conn).await { match UserOrganization::find_by_uuid(&self.users_organizations_uuid, conn).await {
Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await, Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await,
None => warn!("User could not be found!") None => warn!("User could not be found!"),
} }
} }
pub async fn delete_by_group_id_and_user_id(group_uuid: &str, users_organizations_uuid: &str, conn: &DbConn) -> EmptyResult { pub async fn delete_by_group_id_and_user_id(
group_uuid: &str,
users_organizations_uuid: &str,
conn: &DbConn,
) -> EmptyResult {
match UserOrganization::find_by_uuid(users_organizations_uuid, conn).await { match UserOrganization::find_by_uuid(users_organizations_uuid, conn).await {
Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await, Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await,
None => warn!("User could not be found!") None => warn!("User could not be found!"),
}; };
db_run! { conn: { db_run! { conn: {
@ -458,7 +462,7 @@ impl GroupUser {
pub async fn delete_all_by_user(users_organizations_uuid: &str, conn: &DbConn) -> EmptyResult { pub async fn delete_all_by_user(users_organizations_uuid: &str, conn: &DbConn) -> EmptyResult {
match UserOrganization::find_by_uuid(users_organizations_uuid, conn).await { match UserOrganization::find_by_uuid(users_organizations_uuid, conn).await {
Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await, Some(user) => User::update_uuid_revision(&user.user_uuid, conn).await,
None => warn!("User could not be found!") None => warn!("User could not be found!"),
} }
db_run! { conn: { db_run! { conn: {

4
src/db/models/mod.rs

@ -5,13 +5,13 @@ mod device;
mod emergency_access; mod emergency_access;
mod favorite; mod favorite;
mod folder; mod folder;
mod group;
mod org_policy; mod org_policy;
mod organization; mod organization;
mod send; mod send;
mod two_factor; mod two_factor;
mod two_factor_incomplete; mod two_factor_incomplete;
mod user; mod user;
mod group;
pub use self::attachment::Attachment; pub use self::attachment::Attachment;
pub use self::cipher::Cipher; pub use self::cipher::Cipher;
@ -20,10 +20,10 @@ pub use self::device::Device;
pub use self::emergency_access::{EmergencyAccess, EmergencyAccessStatus, EmergencyAccessType}; pub use self::emergency_access::{EmergencyAccess, EmergencyAccessStatus, EmergencyAccessType};
pub use self::favorite::Favorite; pub use self::favorite::Favorite;
pub use self::folder::{Folder, FolderCipher}; pub use self::folder::{Folder, FolderCipher};
pub use self::group::{CollectionGroup, Group, GroupUser};
pub use self::org_policy::{OrgPolicy, OrgPolicyType}; pub use self::org_policy::{OrgPolicy, OrgPolicyType};
pub use self::organization::{Organization, UserOrgStatus, UserOrgType, UserOrganization}; pub use self::organization::{Organization, UserOrgStatus, UserOrgType, UserOrganization};
pub use self::send::{Send, SendType}; pub use self::send::{Send, SendType};
pub use self::two_factor::{TwoFactor, TwoFactorType}; pub use self::two_factor::{TwoFactor, TwoFactorType};
pub use self::two_factor_incomplete::TwoFactorIncomplete; pub use self::two_factor_incomplete::TwoFactorIncomplete;
pub use self::user::{Invitation, User, UserStampException}; pub use self::user::{Invitation, User, UserStampException};
pub use self::group::{Group, CollectionGroup, GroupUser};

2
src/db/models/organization.rs

@ -2,7 +2,7 @@ use num_traits::FromPrimitive;
use serde_json::Value; use serde_json::Value;
use std::cmp::Ordering; use std::cmp::Ordering;
use super::{CollectionUser, OrgPolicy, OrgPolicyType, User, GroupUser}; use super::{CollectionUser, GroupUser, OrgPolicy, OrgPolicyType, User};
db_object! { db_object! {
#[derive(Identifiable, Queryable, Insertable, AsChangeset)] #[derive(Identifiable, Queryable, Insertable, AsChangeset)]

Loading…
Cancel
Save