1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-09-19 19:38:47 +00:00

Can delete group members

This commit is contained in:
2020-06-27 18:28:38 +02:00
parent c28196f80e
commit 926892a29b
3 changed files with 60 additions and 6 deletions

View File

@@ -297,6 +297,20 @@ pub fn count_members(group_id: &GroupID) -> ResultBoxError<usize> {
.exec_count()
}
/// Count the number of group's members at a specific level
pub fn count_members_at_level(group_id: &GroupID, level: GroupMembershipLevel) -> ResultBoxError<usize> {
database::QueryInfo::new(GROUPS_MEMBERS_TABLE)
.cond_group_id("groups_id", group_id)
.cond_u32("level", level.to_db())
.exec_count()
}
/// Check out whether a user is the last administrator of a group
pub fn is_last_admin(group_id: &GroupID, user_id: &UserID) -> ResultBoxError<bool> {
Ok(get_membership_level(group_id, Some(user_id.clone()))? == GroupMembershipLevel::ADMINISTRATOR &&
count_members_at_level(&group_id, GroupMembershipLevel::ADMINISTRATOR)? == 1)
}
/// Check the availability of a virtual directory for a group
pub fn check_directory_availability(dir: &str, group_id: Option<GroupID>) -> ResultBoxError<bool> {
let group = find_by_virtual_directory(dir);