1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can update the content of the posts

This commit is contained in:
Pierre HUBERT 2020-07-09 09:27:47 +02:00
parent cb47b67dc6
commit 697a01b6df
4 changed files with 38 additions and 1 deletions

View File

@ -247,4 +247,16 @@ pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult {
// TODO : Depending on new level, delete (or not) notifications about the post // TODO : Depending on new level, delete (or not) notifications about the post
r.success("Visibility level updated") r.success("Visibility level updated")
}
/// Update the content of a post
pub fn update_content(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?;
let new_content = r.post_content("new_content", 2, true)?;
posts_helper::set_content(post.id, &new_content)?;
// TODO : Delete the notifications targeting the current user about this post
r.success("Content updated")
} }

View File

@ -210,6 +210,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/posts/set_visibility_level", Box::new(posts_controller::set_visibility_level)), Route::post("/posts/set_visibility_level", Box::new(posts_controller::set_visibility_level)),
Route::post("/posts/update_content", Box::new(posts_controller::update_content)),
// Movies controller // Movies controller
Route::post("/movies/get_list", Box::new(movies_controller::get_list)), Route::post("/movies/get_list", Box::new(movies_controller::get_list)),

View File

@ -21,7 +21,7 @@ use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper}; use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper};
use crate::helpers::virtual_directory_helper::VirtualDirType; use crate::helpers::virtual_directory_helper::VirtualDirType;
use crate::utils::pdf_utils::is_valid_pdf; use crate::utils::pdf_utils::is_valid_pdf;
use crate::utils::string_utils::{check_url, remove_html_nodes}; use crate::utils::string_utils::{check_string_before_insert, check_url, remove_html_nodes};
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path}; use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
use crate::utils::virtual_directories_utils::check_virtual_directory; use crate::utils::virtual_directories_utils::check_virtual_directory;
@ -595,4 +595,19 @@ impl HttpRequestHandler {
Ok(movie_id) Ok(movie_id)
} }
/// Get a content of a post and satinize it
pub fn post_content(&mut self, name: &str, min_len: usize, required: bool) -> ResultBoxError<String> {
let content = self.post_string_opt(name, min_len, required)?;
if content.contains("data:image") {
self.forbidden("Please do not include inline images!".to_string())?;
}
if !check_string_before_insert(&content) {
self.forbidden(format!("The content inside {} was rejected!", name))?;
}
Ok(remove_html_nodes(&content))
}
} }

View File

@ -391,6 +391,14 @@ pub fn set_level(post_id: u64, level: PostVisibilityLevel) -> ResultBoxError {
.exec() .exec()
} }
/// Set a new content to the post
pub fn set_content(post_id: u64, new_content: &str) -> ResultBoxError {
database::UpdateInfo::new(POSTS_TABLE)
.cond_u64("ID", post_id)
.set_str("texte", new_content)
.exec()
}
/// Turn a post into a database entry /// Turn a post into a database entry
fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> { fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
let user_id = if res.get_u64("ID_amis")? == 0 { let user_id = if res.get_u64("ID_amis")? == 0 {