From b5f9fe4d3bb57cada7fa01371efc3978a5937173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sat, 7 Nov 2020 23:03:02 +0100 Subject: [PATCH] Fix #1206 --- src/db/models/collection.rs | 17 ++++++++++++----- src/db/models/organization.rs | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 888523f1..4b506a97 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -356,13 +356,20 @@ impl CollectionUser { }} } - pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - User::update_uuid_revision(&user_uuid, conn); + pub fn delete_all_by_user_and_org(user_uuid: &str, org_uuid: &str, conn: &DbConn) -> EmptyResult { + let collectionusers = Self::find_by_organization_and_user_uuid(org_uuid, user_uuid, conn); db_run! { conn: { - diesel::delete(users_collections::table.filter(users_collections::user_uuid.eq(user_uuid))) - .execute(conn) - .map_res("Error removing user from collections") + for user in collectionusers { + diesel::delete(users_collections::table.filter( + users_collections::user_uuid.eq(user_uuid) + .and(users_collections::collection_uuid.eq(user.collection_uuid)) + + )) + .execute(conn) + .map_res("Error removing user from collections")?; + } + Ok(()) }} } } diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 5378ad29..5fb4f36e 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -389,7 +389,7 @@ impl UserOrganization { pub fn delete(self, conn: &DbConn) -> EmptyResult { User::update_uuid_revision(&self.user_uuid, conn); - CollectionUser::delete_all_by_user(&self.user_uuid, &conn)?; + CollectionUser::delete_all_by_user_and_org(&self.user_uuid, &self.org_uuid, &conn)?; db_run! { conn: { diesel::delete(users_organizations::table.filter(users_organizations::uuid.eq(self.uuid)))