1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 07:19:22 +00:00

Can send an invitation

This commit is contained in:
Pierre HUBERT 2020-06-27 12:56:03 +02:00
parent 1d4e3dba5a
commit e7a13f7181
2 changed files with 25 additions and 1 deletions

View File

@ -13,6 +13,7 @@ use crate::constants::{DEFAULT_GROUP_LOGO, PATH_GROUPS_LOGOS};
use crate::controllers::routes::RequestResult;
use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel};
use crate::data::group_id::GroupID;
use crate::data::group_member::GroupMembershipLevel;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::data::new_group::NewGroup;
use crate::helpers::{groups_helper, virtual_directory_helper};
@ -159,5 +160,16 @@ pub fn get_members(r: &mut HttpRequestHandler) -> RequestResult {
/// Invite a user to join a group
pub fn invite_user(r: &mut HttpRequestHandler) -> RequestResult {
r.success("Ready to implement")
let group_id = r.post_group_id_with_access("group_id", GroupAccessLevel::MODERATOR_ACCESS)?;
let user_id = r.post_user_id("userID")?;
if groups_helper::get_membership_level(&group_id, Some(user_id.clone()))? != GroupMembershipLevel::VISITOR {
r.bad_request("The user is not a visitor of the group!".to_string())?;
}
groups_helper::send_invitation(&group_id, &user_id)?;
// TODO : send a notification
r.success("The user has been successfully invited to join the group!")
}

View File

@ -331,6 +331,18 @@ pub fn get_list_members(g: &GroupID) -> ResultBoxError<Vec<GroupMember>> {
.exec(db_to_group_member)
}
/// Send an invitation to a user
pub fn send_invitation(group_id: &GroupID, user_id: &UserID) -> ResultBoxError {
insert_member(&GroupMember {
id: 0,
user_id: user_id.clone(),
group_id: group_id.clone(),
time_create: time(),
level: GroupMembershipLevel::INVITED,
following: true,
})
}
/// 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")?;