diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 81bfe79..79ae135 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -75,5 +75,15 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult { )?; } + // Update members list + if r.has_post_parameter("members") { + let members = r.post_numbers_list("members", 1); + let can_everyone_add_members = conversations_helper::can_everyone_add_members(conv_id)?; + + if !is_moderator && !can_everyone_add_members { + r.forbidden("You can not update the list of members of this conversation!".to_string())?; + } + } + r.success("Conversation information successfully updated!") } \ No newline at end of file diff --git a/src/helpers/conversations_helper.rs b/src/helpers/conversations_helper.rs index a62efeb..86f8859 100644 --- a/src/helpers/conversations_helper.rs +++ b/src/helpers/conversations_helper.rs @@ -115,6 +115,14 @@ pub fn is_user_moderator(user_id: UserID, conv_id: u64) -> ResultBoxError .exec_count()? > 0) } +/// Check out whether all the members of a conversation can add members to it or not +pub fn can_everyone_add_members(conv_id: u64) -> ResultBoxError { + database::QueryInfo::new(CONV_LIST_TABLE) + .cond_u64("id", conv_id) + .add_field("can_everyone_add_members") + .query_row(|f|f.get_legacy_bool("can_everyone_add_members")) +} + /// Set whether a user is following a conversation or not pub fn set_following(user_id: UserID, conv_id: u64, following: bool) -> ResultBoxError<()> { database::UpdateInfo::new(CONV_USERS_TABLE)