From d195979c185b4eac555260403fdd0b21308dc53c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 30 Jun 2020 14:54:45 +0200 Subject: [PATCH] Update can_post_texts parameter --- src/controllers/friends_controller.rs | 10 ++++++++++ src/controllers/routes.rs | 2 ++ src/helpers/friends_helper.rs | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/src/controllers/friends_controller.rs b/src/controllers/friends_controller.rs index ab62ce3..06214be 100644 --- a/src/controllers/friends_controller.rs +++ b/src/controllers/friends_controller.rs @@ -137,4 +137,14 @@ pub fn set_following(r: &mut HttpRequestHandler) -> RequestResult { friends_helper::set_following(r.user_id_ref()?, &friend_id, follow)?; r.success("Following status updated!") +} + +/// Update post texts authorization status +pub fn set_can_post_texts(r: &mut HttpRequestHandler) -> RequestResult { + let friend_id = r.post_friend_id("friendID")?; + let allow = r.post_bool("allow")?; + + friends_helper::set_can_post_texts(r.user_id_ref()?, &friend_id, allow)?; + + r.success("Updated status!") } \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index 9934886..a0fb629 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -107,6 +107,8 @@ pub fn get_routes() -> Vec { Route::post("/friends/setFollowing", Box::new(friends_controller::set_following)), + Route::post("/friends/set_can_post_texts", Box::new(friends_controller::set_can_post_texts)), + // Conversations controller Route::post("/conversations/create", Box::new(conversations_controller::create)), diff --git a/src/helpers/friends_helper.rs b/src/helpers/friends_helper.rs index 4c1abb6..d52539d 100644 --- a/src/helpers/friends_helper.rs +++ b/src/helpers/friends_helper.rs @@ -172,6 +172,15 @@ pub fn set_following(user_id: &UserID, friend_id: &UserID, follow: bool) -> Resu .exec() } +/// Specify whether a friend is allowed to create posts on current user's page or not +pub fn set_can_post_texts(user_id: &UserID, friend_id: &UserID, allow: bool) -> ResultBoxError { + database::UpdateInfo::new(FRIENDS_TABLE) + .cond_user_id("ID_personne", user_id) + .cond_user_id("ID_amis", friend_id) + .set_legacy_bool("autoriser_post_page", allow) + .exec() +} + /// Get the status of a friendship pub fn get_status(user_id: &UserID, friend_id: &UserID) -> ResultBoxError { let mut status = FriendshipStatus {