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

Can change the visibility level of a post

This commit is contained in:
Pierre HUBERT 2020-07-09 09:10:42 +02:00
parent 4a559f8222
commit dc5ad6aea4
4 changed files with 33 additions and 1 deletions

View File

@ -114,7 +114,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
time_create: time(), time_create: time(),
target_page, target_page,
content: Some(r.post_string_opt("content", 0, false)?), content: Some(r.post_string_opt("content", 0, false)?),
visibility: PostVisibilityLevel::VISIBILITY_PUBLIC, visibility: PostVisibilityLevel::VISIBILITY_PUBLIC, // TODO : fix
kind: PostKind::POST_KIND_TEXT, kind: PostKind::POST_KIND_TEXT,
}; };
@ -236,3 +236,15 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
// TODO : create a notification // TODO : create a notification
r.set_response(ResCreatePost::new(post_id)) r.set_response(ResCreatePost::new(post_id))
} }
/// Change the visibility level of a post
pub fn set_visibility_level(r: &mut HttpRequestHandler) -> RequestResult {
let post = r.post_post_with_access("postID", PostAccessLevel::FULL_ACCESS)?;
let new_visibility = PostVisibilityLevel::from_api(&r.post_string("new_level")?);
posts_helper::set_level(post.id, new_visibility)?;
// TODO : Depending on new level, delete (or not) notifications about the post
r.success("Visibility level updated")
}

View File

@ -208,6 +208,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/posts/create", Box::new(posts_controller::create_post)), Route::post("/posts/create", Box::new(posts_controller::create_post)),
Route::post("/posts/set_visibility_level", Box::new(posts_controller::set_visibility_level)),
// 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

@ -30,6 +30,16 @@ impl PostVisibilityLevel {
PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS => "members", PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS => "members",
}.to_string() }.to_string()
} }
pub fn from_api(level: &str) -> PostVisibilityLevel {
match level {
"private" => PostVisibilityLevel::VISIBILITY_USER,
"friends" => PostVisibilityLevel::VISIBILITY_FRIENDS,
"members" => PostVisibilityLevel::VISIBILITY_GROUP_MEMBERS,
"public" => PostVisibilityLevel::VISIBILITY_PUBLIC,
_ => PostVisibilityLevel::VISIBILITY_PUBLIC,
}
}
} }
/// Post access level (for a given user) /// Post access level (for a given user)

View File

@ -383,6 +383,14 @@ pub fn allow_comments_on_post(p: &Post) -> ResultBoxError<bool> {
user_helper::allow_comments(p.user_page_id().unwrap_or(&UserID::invalid()))?) user_helper::allow_comments(p.user_page_id().unwrap_or(&UserID::invalid()))?)
} }
/// Set a new visibility level to a post
pub fn set_level(post_id: u64, level: PostVisibilityLevel) -> ResultBoxError {
database::UpdateInfo::new(POSTS_TABLE)
.cond_u64("ID", post_id)
.set_u32("niveau_visibilite", level.to_db())
.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 {