mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 21:26:38 +00:00
Update revision for users on collection save
This commit is contained in:
parent
015bd28cc2
commit
54f54ee845
@ -42,13 +42,18 @@ use db::schema::*;
|
|||||||
|
|
||||||
/// Database methods
|
/// Database methods
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn save(&mut self, conn: &DbConn) -> bool {
|
pub fn save(&mut self, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::replace_into(collections::table)
|
// Update affected users revision
|
||||||
|
UserOrganization::find_by_collection_and_org(&self.uuid, &self.org_uuid, conn)
|
||||||
|
.iter()
|
||||||
|
.for_each(|user_org| {
|
||||||
|
User::update_uuid_revision(&user_org.user_uuid, conn);
|
||||||
|
});
|
||||||
|
|
||||||
|
diesel::replace_into(collections::table)
|
||||||
.values(&*self)
|
.values(&*self)
|
||||||
.execute(&**conn) {
|
.execute(&**conn)
|
||||||
Ok(1) => true, // One row inserted
|
.and(Ok(()))
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
@ -331,6 +331,22 @@ impl UserOrganization {
|
|||||||
.select(users_organizations::all_columns)
|
.select(users_organizations::all_columns)
|
||||||
.load::<Self>(&**conn).expect("Error loading user organizations")
|
.load::<Self>(&**conn).expect("Error loading user organizations")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_by_collection_and_org(collection_uuid: &str, org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
||||||
|
users_organizations::table
|
||||||
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
||||||
|
.left_join(users_collections::table.on(
|
||||||
|
users_collections::user_uuid.eq(users_organizations::user_uuid)
|
||||||
|
))
|
||||||
|
.filter(
|
||||||
|
users_organizations::access_all.eq(true).or( // AccessAll..
|
||||||
|
users_collections::collection_uuid.eq(&collection_uuid) // ..or access to collection with cipher
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.select(users_organizations::all_columns)
|
||||||
|
.load::<Self>(&**conn).expect("Error loading user organizations")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user