aboutsummaryrefslogtreecommitdiff
path: root/src/db/models/collection.rs
diff options
context:
space:
mode:
authorMiroslav Prasil <[email protected]>2019-02-06 13:39:32 +0000
committerMiroslav Prasil <[email protected]>2019-02-06 13:39:32 +0000
commit5272b465cc9255280dff5c493a92354513ba7222 (patch)
tree29fcdf290f47a8b6582c3382a4430956f0e26b36 /src/db/models/collection.rs
parentb75f38033b7f18157c4db493087ef72fd36e7b01 (diff)
downloadvaultwarden-5272b465cc9255280dff5c493a92354513ba7222.tar.gz
vaultwarden-5272b465cc9255280dff5c493a92354513ba7222.zip
Update revision of affected users when deleting Collection
Diffstat (limited to 'src/db/models/collection.rs')
-rw-r--r--src/db/models/collection.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs
index 42d78314..905ca41e 100644
--- a/src/db/models/collection.rs
+++ b/src/db/models/collection.rs
@@ -44,12 +44,7 @@ use crate::error::MapResult;
/// Database methods
impl Collection {
pub fn save(&mut self, conn: &DbConn) -> EmptyResult {
- // 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);
- });
+ self.update_users_revision(conn);
diesel::replace_into(collections::table)
.values(&*self)
@@ -58,6 +53,7 @@ impl Collection {
}
pub fn delete(self, conn: &DbConn) -> EmptyResult {
+ self.update_users_revision(conn);
CollectionCipher::delete_all_by_collection(&self.uuid, &conn)?;
CollectionUser::delete_all_by_collection(&self.uuid, &conn)?;
@@ -73,6 +69,14 @@ impl Collection {
Ok(())
}
+ pub fn update_users_revision(&self, conn: &DbConn) {
+ 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);
+ });
+ }
+
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
collections::table
.filter(collections::uuid.eq(uuid))