mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Automatically delete reports on associated resources deletion
This commit is contained in:
parent
55b13fc0f6
commit
fbeb66f70e
@ -11,6 +11,7 @@ use crate::data::lang_settings::LangSettings;
|
|||||||
use crate::data::new_account::NewAccount;
|
use crate::data::new_account::NewAccount;
|
||||||
use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
|
use crate::data::new_data_conservation_policy::NewDataConservationPolicy;
|
||||||
use crate::data::new_notifications_settings::NewNotificationsSettings;
|
use crate::data::new_notifications_settings::NewNotificationsSettings;
|
||||||
|
use crate::data::report::ReportTarget;
|
||||||
use crate::data::security_settings::SecuritySettings;
|
use crate::data::security_settings::SecuritySettings;
|
||||||
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageVisibility};
|
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageVisibility};
|
||||||
use crate::data::user_token::{PushNotificationToken, UserAccessToken};
|
use crate::data::user_token::{PushNotificationToken, UserAccessToken};
|
||||||
@ -408,6 +409,9 @@ pub async fn delete(user_id: &UserID) -> ResultBoxError {
|
|||||||
// Delete all the reports of the user
|
// Delete all the reports of the user
|
||||||
reports_helper::delete_all_from_user(user_id)?;
|
reports_helper::delete_all_from_user(user_id)?;
|
||||||
|
|
||||||
|
// Delete all the reports targeting the user
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::User(user_id.clone()))?;
|
||||||
|
|
||||||
// Delete all forez presences
|
// Delete all forez presences
|
||||||
forez_presence_helper::delete_all_user(user_id)?;
|
forez_presence_helper::delete_all_user(user_id)?;
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
use crate::constants::database_tables_names::COMMENTS_TABLE;
|
use crate::constants::database_tables_names::COMMENTS_TABLE;
|
||||||
use crate::data::comment::Comment;
|
use crate::data::comment::Comment;
|
||||||
use crate::data::error::{ExecError, Res, ResultBoxError};
|
use crate::data::error::{ExecError, Res, ResultBoxError};
|
||||||
|
use crate::data::report::ReportTarget;
|
||||||
use crate::data::user::{User, UserID};
|
use crate::data::user::{User, UserID};
|
||||||
use crate::helpers::{database, events_helper, likes_helper};
|
use crate::helpers::{database, events_helper, likes_helper, reports_helper};
|
||||||
use crate::helpers::events_helper::Event;
|
use crate::helpers::events_helper::Event;
|
||||||
use crate::helpers::likes_helper::LikeType;
|
use crate::helpers::likes_helper::LikeType;
|
||||||
use crate::utils::date_utils::{mysql_date, time};
|
use crate::utils::date_utils::{mysql_date, time};
|
||||||
@ -81,6 +82,12 @@ pub async fn edit(comment_id: u64, new_content: &str) -> ResultBoxError {
|
|||||||
|
|
||||||
/// Delete a single comment
|
/// Delete a single comment
|
||||||
pub async fn delete(c: &Comment) -> ResultBoxError {
|
pub async fn delete(c: &Comment) -> ResultBoxError {
|
||||||
|
// Delete associated reports
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::Comment(c.id))?;
|
||||||
|
|
||||||
|
// Remove the likes associated with the comment
|
||||||
|
likes_helper::delete_all(c.id, LikeType::COMMENT)?;
|
||||||
|
|
||||||
// Delete associated image (if any)
|
// Delete associated image (if any)
|
||||||
if let Some(image) = &c.image_path {
|
if let Some(image) = &c.image_path {
|
||||||
let path = user_data_path(image.as_ref());
|
let path = user_data_path(image.as_ref());
|
||||||
@ -89,9 +96,6 @@ pub async fn delete(c: &Comment) -> ResultBoxError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the likes associated with the comment
|
|
||||||
likes_helper::delete_all(c.id, LikeType::COMMENT)?;
|
|
||||||
|
|
||||||
// Remove the comment from the database
|
// Remove the comment from the database
|
||||||
database::DeleteQuery::new(COMMENTS_TABLE)
|
database::DeleteQuery::new(COMMENTS_TABLE)
|
||||||
.cond_u64("ID", c.id)
|
.cond_u64("ID", c.id)
|
||||||
|
@ -10,8 +10,9 @@ use crate::data::group_id::GroupID;
|
|||||||
use crate::data::group_member::GroupMembershipLevel;
|
use crate::data::group_member::GroupMembershipLevel;
|
||||||
use crate::data::new_conversation::NewConversation;
|
use crate::data::new_conversation::NewConversation;
|
||||||
use crate::data::new_conversation_message::NewConversationMessage;
|
use crate::data::new_conversation_message::NewConversationMessage;
|
||||||
|
use crate::data::report::ReportTarget;
|
||||||
use crate::data::user::{User, UserID};
|
use crate::data::user::{User, UserID};
|
||||||
use crate::helpers::{database, events_helper, groups_helper};
|
use crate::helpers::{database, events_helper, groups_helper, reports_helper};
|
||||||
use crate::helpers::database::{InsertQuery, UpdateInfo};
|
use crate::helpers::database::{InsertQuery, UpdateInfo};
|
||||||
use crate::helpers::events_helper::Event;
|
use crate::helpers::events_helper::Event;
|
||||||
use crate::utils::date_utils::time;
|
use crate::utils::date_utils::time;
|
||||||
@ -407,6 +408,9 @@ pub async fn update_message_content(msg_id: u64, new_content: &str) -> ResultBox
|
|||||||
/// Remove a message from a conversation
|
/// Remove a message from a conversation
|
||||||
pub async fn delete_message(msg: &ConversationMessage) -> ResultBoxError<()> {
|
pub async fn delete_message(msg: &ConversationMessage) -> ResultBoxError<()> {
|
||||||
|
|
||||||
|
// Delete associated reports
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::ConversationMessage(msg.id))?;
|
||||||
|
|
||||||
// Delete associated files
|
// Delete associated files
|
||||||
if let Some(file) = &msg.file {
|
if let Some(file) = &msg.file {
|
||||||
delete_user_data_file_if_exists(&file.path)?;
|
delete_user_data_file_if_exists(&file.path)?;
|
||||||
@ -531,6 +535,9 @@ pub async fn update_members_list_for_group_conversation(conv_id: ConvID) -> Res
|
|||||||
|
|
||||||
/// Remove permanently a conversation
|
/// Remove permanently a conversation
|
||||||
pub async fn delete_conversation(conv: &Conversation) -> ResultBoxError<()> {
|
pub async fn delete_conversation(conv: &Conversation) -> ResultBoxError<()> {
|
||||||
|
// Delete associated reports
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::Conversation(conv.id))?;
|
||||||
|
|
||||||
// Delete all the messages of the conversations
|
// Delete all the messages of the conversations
|
||||||
for message in get_all_messages(conv.id)? {
|
for message in get_all_messages(conv.id)? {
|
||||||
delete_message(&message).await?;
|
delete_message(&message).await?;
|
||||||
|
@ -8,8 +8,9 @@ use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, Group
|
|||||||
use crate::data::group_id::GroupID;
|
use crate::data::group_id::GroupID;
|
||||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
|
||||||
use crate::data::new_group::NewGroup;
|
use crate::data::new_group::NewGroup;
|
||||||
|
use crate::data::report::ReportTarget;
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::{conversations_helper, database, forez_presence_helper, likes_helper, notifications_helper, posts_helper};
|
use crate::helpers::{conversations_helper, database, forez_presence_helper, likes_helper, notifications_helper, posts_helper, reports_helper};
|
||||||
use crate::helpers::likes_helper::LikeType;
|
use crate::helpers::likes_helper::LikeType;
|
||||||
use crate::utils::date_utils::time;
|
use crate::utils::date_utils::time;
|
||||||
|
|
||||||
@ -490,6 +491,9 @@ pub fn can_user_create_posts(group_id: &GroupID, user_id: &UserID) -> ResultBoxE
|
|||||||
|
|
||||||
/// Delete a group
|
/// Delete a group
|
||||||
pub async fn delete(group_id: &GroupID) -> ResultBoxError {
|
pub async fn delete(group_id: &GroupID) -> ResultBoxError {
|
||||||
|
// Delete associated reports
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::Group(group_id.clone()))?;
|
||||||
|
|
||||||
// Delete all likes of the group
|
// Delete all likes of the group
|
||||||
likes_helper::delete_all(group_id.id(), LikeType::GROUP)?;
|
likes_helper::delete_all(group_id.id(), LikeType::GROUP)?;
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ use crate::data::group_id::GroupID;
|
|||||||
use crate::data::group_member::GroupMembershipLevel;
|
use crate::data::group_member::GroupMembershipLevel;
|
||||||
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
|
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
|
||||||
use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
|
use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
|
||||||
|
use crate::data::report::ReportTarget;
|
||||||
use crate::data::user::{User, UserID};
|
use crate::data::user::{User, UserID};
|
||||||
use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, survey_helper, user_helper};
|
use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, reports_helper, survey_helper, user_helper};
|
||||||
use crate::helpers::likes_helper::LikeType;
|
use crate::helpers::likes_helper::LikeType;
|
||||||
use crate::utils::date_utils::{mysql_date, time};
|
use crate::utils::date_utils::{mysql_date, time};
|
||||||
use crate::utils::user_data_utils::user_data_path;
|
use crate::utils::user_data_utils::user_data_path;
|
||||||
@ -422,6 +423,9 @@ pub async fn delete(p: &Post) -> ResultBoxError {
|
|||||||
// Delete all the comments associated to the post
|
// Delete all the comments associated to the post
|
||||||
comments_helper::delete_all(p.id).await?;
|
comments_helper::delete_all(p.id).await?;
|
||||||
|
|
||||||
|
// Delete associated reports
|
||||||
|
reports_helper::delete_all_for_target(ReportTarget::Post(p.id))?;
|
||||||
|
|
||||||
// Delete associated file / resource (if any)
|
// Delete associated file / resource (if any)
|
||||||
match &p.kind {
|
match &p.kind {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::constants::database_tables_names::REPORTS_TABLE;
|
use crate::constants::database_tables_names::REPORTS_TABLE;
|
||||||
use crate::data::error::Res;
|
use crate::data::error::Res;
|
||||||
use crate::data::report::{Report, ReportID};
|
use crate::data::report::{Report, ReportID, ReportTarget};
|
||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::database;
|
use crate::helpers::database;
|
||||||
|
|
||||||
@ -35,4 +35,13 @@ pub fn delete_all_from_user(user: &UserID) -> Res {
|
|||||||
database::DeleteQuery::new(REPORTS_TABLE)
|
database::DeleteQuery::new(REPORTS_TABLE)
|
||||||
.cond_user_id("user_id", user)
|
.cond_user_id("user_id", user)
|
||||||
.exec()
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Delete all the reports targeting a specific resource
|
||||||
|
pub fn delete_all_for_target(target: ReportTarget) -> Res {
|
||||||
|
let (target_type, target_id) = target.to_db();
|
||||||
|
database::DeleteQuery::new(REPORTS_TABLE)
|
||||||
|
.cond_str("target_type", target_type)
|
||||||
|
.cond_u64("target_id", target_id)
|
||||||
|
.exec()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user