1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Delete server messages related with user when user delete its account

This commit is contained in:
Pierre HUBERT 2021-03-07 16:02:13 +01:00
parent e0d2022438
commit 7ae8fb2fad
2 changed files with 11 additions and 3 deletions

View File

@ -258,6 +258,15 @@ pub fn delete_all_user_messages(user_id: &UserID) -> ResultBoxError {
delete_message(msg)?; delete_message(msg)?;
} }
// Remove all server messages related with the user
database::DeleteQuery::new(CONV_MESSAGES_TABLE)
.set_custom_where(&format!(
"user_id IS NULL AND ((message LIKE \"%-{}-%\") OR (message LIKE \"%-{}\"))",
user_id.id(),
user_id.id()
))
.exec()?;
Ok(()) Ok(())
} }

View File

@ -9,10 +9,10 @@ use mysql::{Binary, Pool, ResultSet, Value};
use mysql::prelude::Queryable; use mysql::prelude::Queryable;
use crate::data::config::{conf, DatabaseConfig}; use crate::data::config::{conf, DatabaseConfig};
use crate::data::conversation::ConvID;
use crate::data::error::{ExecError, ResultBoxError}; use crate::data::error::{ExecError, ResultBoxError};
use crate::data::group_id::GroupID; use crate::data::group_id::GroupID;
use crate::data::user::UserID; use crate::data::user::UserID;
use crate::data::conversation::ConvID;
/// Database access helper /// Database access helper
/// ///
@ -662,7 +662,6 @@ impl InsertQuery {
} }
/// Legacy database boolean (1 = true / 0 = false) /// Legacy database boolean (1 = true / 0 = false)
pub fn add_legacy_bool(mut self, key: &str, value: bool) -> InsertQuery { pub fn add_legacy_bool(mut self, key: &str, value: bool) -> InsertQuery {
let num = match value { let num = match value {
@ -814,7 +813,7 @@ impl DeleteQuery {
/// Delete an entry from the database /// Delete an entry from the database
pub fn delete(query: DeleteQuery) -> ResultBoxError<()> { pub fn delete(query: DeleteQuery) -> ResultBoxError<()> {
if query.conditions.is_empty() { if query.conditions.is_empty() && query.custom_where.is_none() {
return Err(ExecError::boxed_new("DELETE without WHERE condition blocked for security reasons!")); return Err(ExecError::boxed_new("DELETE without WHERE condition blocked for security reasons!"));
} }