mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Can delete group
This commit is contained in:
		@@ -300,7 +300,7 @@ pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete a user's account
 | 
			
		||||
pub fn delete(user_id: &UserID) -> ResultBoxError {
 | 
			
		||||
pub fn delete(_user_id: &UserID) -> ResultBoxError {
 | 
			
		||||
    // TODO : close all websockets of user
 | 
			
		||||
 | 
			
		||||
    // TODO : Delete all group membership
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,8 @@ use crate::data::group_id::GroupID;
 | 
			
		||||
use crate::data::group_member::{GroupMember, GroupMembershipLevel};
 | 
			
		||||
use crate::data::new_group::NewGroup;
 | 
			
		||||
use crate::data::user::UserID;
 | 
			
		||||
use crate::helpers::{database, posts_helper};
 | 
			
		||||
use crate::helpers::{database, likes_helper, notifications_helper, posts_helper};
 | 
			
		||||
use crate::helpers::likes_helper::LikeType;
 | 
			
		||||
use crate::utils::date_utils::time;
 | 
			
		||||
 | 
			
		||||
impl GroupVisibilityLevel {
 | 
			
		||||
@@ -462,6 +463,32 @@ pub fn can_user_create_posts(group_id: &GroupID, user_id: &UserID) -> ResultBoxE
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete a group
 | 
			
		||||
pub fn delete(group_id: &GroupID) -> ResultBoxError {
 | 
			
		||||
    // Delete all likes of the group
 | 
			
		||||
    likes_helper::delete_all(group_id.id(), LikeType::GROUP)?;
 | 
			
		||||
 | 
			
		||||
    // Delete the logo of the group
 | 
			
		||||
    delete_logo(group_id)?;
 | 
			
		||||
 | 
			
		||||
    // Delete all group posts
 | 
			
		||||
    posts_helper::delete_all_group(group_id)?;
 | 
			
		||||
 | 
			
		||||
    // Delete all group related notifications
 | 
			
		||||
    notifications_helper::delete_all_related_with_group(group_id)?;
 | 
			
		||||
 | 
			
		||||
    // Delete all group members
 | 
			
		||||
    database::DeleteQuery::new(GROUPS_MEMBERS_TABLE)
 | 
			
		||||
        .cond_group_id("groups_id", group_id)
 | 
			
		||||
        .exec()?;
 | 
			
		||||
 | 
			
		||||
    // Delete group information
 | 
			
		||||
    database::DeleteQuery::new(GROUPS_LIST_TABLE)
 | 
			
		||||
        .cond_group_id("id", group_id)
 | 
			
		||||
        .exec()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/// Turn a database entry into a group struct
 | 
			
		||||
fn db_to_group(row: &database::RowResult) -> ResultBoxError<Group> {
 | 
			
		||||
    let group_id = row.get_group_id("id")?;
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ use std::collections::HashMap;
 | 
			
		||||
 | 
			
		||||
use crate::constants::database_tables_names::NOTIFICATIONS_TABLE;
 | 
			
		||||
use crate::data::error::ResultBoxError;
 | 
			
		||||
use crate::data::group_id::GroupID;
 | 
			
		||||
use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibility, Notification, PartialNotification};
 | 
			
		||||
use crate::data::user::UserID;
 | 
			
		||||
use crate::helpers::database;
 | 
			
		||||
@@ -26,6 +27,19 @@ pub fn delete_all_user(user_id: &UserID) -> ResultBoxError {
 | 
			
		||||
    delete(&PartialNotification::new().set_dest_user_id(user_id))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete all the notifications related with a group
 | 
			
		||||
pub fn delete_all_related_with_group(group_id: &GroupID) -> ResultBoxError {
 | 
			
		||||
    delete(&PartialNotification::new()
 | 
			
		||||
        .set_on_elem_type(NotifElemType::GROUP_MEMBERSHIP)
 | 
			
		||||
        .set_on_elem_id(group_id.id())
 | 
			
		||||
    )?;
 | 
			
		||||
 | 
			
		||||
    delete(&PartialNotification::new()
 | 
			
		||||
        .set_on_elem_type(NotifElemType::GROUP_PAGE)
 | 
			
		||||
        .set_on_elem_id(group_id.id())
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Check out whether a similar notification exists for given specifications
 | 
			
		||||
pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
 | 
			
		||||
    database::QueryInfo::new(NOTIFICATIONS_TABLE)
 | 
			
		||||
 
 | 
			
		||||
@@ -334,6 +334,13 @@ pub fn export_all_posts_user(user_id: &UserID) -> ResultBoxError<Vec<Post>> {
 | 
			
		||||
        .exec(db_to_post)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the entire list of posts of a given group
 | 
			
		||||
pub fn export_all_posts_group(group_id: &GroupID) -> ResultBoxError<Vec<Post>> {
 | 
			
		||||
    database::QueryInfo::new(POSTS_TABLE)
 | 
			
		||||
        .cond_group_id("group_id", group_id)
 | 
			
		||||
        .exec(db_to_post)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the access level of a user over a post
 | 
			
		||||
pub fn get_access_level(p: &Post, user_id: &Option<UserID>) -> ResultBoxError<PostAccessLevel> {
 | 
			
		||||
    if user_id == &p.user_id.as_option() {
 | 
			
		||||
@@ -450,6 +457,15 @@ pub fn delete(p: &Post) -> ResultBoxError {
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete all the posts related with a group
 | 
			
		||||
pub fn delete_all_group(group_id: &GroupID) -> ResultBoxError {
 | 
			
		||||
    for post in export_all_posts_group(group_id)? {
 | 
			
		||||
        delete(&post)?;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get all the posts that use of movie
 | 
			
		||||
pub fn get_posts_for_movie(m: &Movie) -> ResultBoxError<Vec<Post>> {
 | 
			
		||||
    database::QueryInfo::new(POSTS_TABLE)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user