From 5e6399d94e2e10c7672973db1711ab6bc2f0de48 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 17 Mar 2022 17:33:38 +0100 Subject: [PATCH] Delete all the reports from a user on its deletion --- src/helpers/account_helper.rs | 5 ++++- src/helpers/reports_helper.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/helpers/account_helper.rs b/src/helpers/account_helper.rs index dd37d94..9c8a341 100644 --- a/src/helpers/account_helper.rs +++ b/src/helpers/account_helper.rs @@ -14,7 +14,7 @@ use crate::data::new_notifications_settings::NewNotificationsSettings; use crate::data::security_settings::SecuritySettings; use crate::data::user::{AccountImageVisibility, User, UserID, UserPageVisibility}; use crate::data::user_token::{PushNotificationToken, UserAccessToken}; -use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, forez_presence_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, push_notifications_helper, survey_helper, user_helper}; +use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, forez_presence_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, push_notifications_helper, reports_helper, survey_helper, user_helper}; use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo, RowResult, UpdateInfo}; use crate::helpers::events_helper::Event; use crate::helpers::likes_helper::LikeType; @@ -405,6 +405,9 @@ pub async fn delete(user_id: &UserID) -> ResultBoxError { // Delete all custom user emojies custom_emojies_helper::delete_all_user(user_id)?; + // Delete all the reports of the user + reports_helper::delete_all_from_user(user_id)?; + // Delete all forez presences forez_presence_helper::delete_all_user(user_id)?; diff --git a/src/helpers/reports_helper.rs b/src/helpers/reports_helper.rs index a4fa340..4322d43 100644 --- a/src/helpers/reports_helper.rs +++ b/src/helpers/reports_helper.rs @@ -1,6 +1,7 @@ use crate::constants::database_tables_names::REPORTS_TABLE; use crate::data::error::Res; use crate::data::report::{Report, ReportID}; +use crate::data::user::UserID; use crate::helpers::database; /// Check if a report has already been saved by the same user on the same resource @@ -27,4 +28,11 @@ pub fn save_report(r: Report) -> Res { .add_opt_str("comment", r.comment.as_ref()) .insert_expect_result() .map(|i| ReportID(i)) +} + +/// Delete all the reports created by a user +pub fn delete_all_from_user(user: &UserID) -> Res { + database::DeleteQuery::new(REPORTS_TABLE) + .cond_user_id("user_id", user) + .exec() } \ No newline at end of file