Check view permission when reposting a post

This commit is contained in:
silverpill 2022-01-06 15:35:59 +00:00
parent 2d2ec704a2
commit ba52cf0be1

View file

@ -281,12 +281,16 @@ async fn reblog(
) -> Result<HttpResponse, HttpError> { ) -> Result<HttpResponse, HttpError> {
let db_client = &mut **get_database_client(&db_pool).await?; let db_client = &mut **get_database_client(&db_pool).await?;
let current_user = get_current_user(db_client, auth.token()).await?; let current_user = get_current_user(db_client, auth.token()).await?;
let mut post = get_post_by_id(db_client, &status_id).await?;
if !can_view_post(db_client, Some(&current_user), &post).await? {
return Err(HttpError::NotFoundError("post"));
};
let repost_data = PostCreateData { let repost_data = PostCreateData {
repost_of_id: Some(status_id), repost_of_id: Some(status_id),
..Default::default() ..Default::default()
}; };
let repost = create_post(db_client, &current_user.id, repost_data).await?; let repost = create_post(db_client, &current_user.id, repost_data).await?;
let mut post = get_post_by_id(db_client, &status_id).await?; post.repost_count += 1;
get_reposted_posts(db_client, vec![&mut post]).await?; get_reposted_posts(db_client, vec![&mut post]).await?;
get_actions_for_posts(db_client, &current_user.id, vec![&mut post]).await?; get_actions_for_posts(db_client, &current_user.id, vec![&mut post]).await?;