Fix post like not decrementing vote totals. (#5941)

* Fix post like not decrementing vote totals.

- Issue was: reading the original post like didn't pass my user, so it
couldn't grab post_actions.like_score.
- Fixes #5940

* Add a few more local_user passes to PostView::read

* Forgot another
This commit is contained in:
Dessalines 2025-09-01 04:44:29 -04:00 committed by GitHub
parent 60b5bf5c0e
commit b7a9eb05da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 47 additions and 17 deletions

View file

@ -45,8 +45,14 @@ pub async fn like_post(
check_bot_account(&local_user_view.person)?;
// Check for a community ban
let orig_post =
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
let orig_post = PostView::read(
&mut context.pool(),
post_id,
Some(&local_user_view.local_user),
local_instance_id,
false,
)
.await?;
let previous_score = orig_post.post_actions.and_then(|p| p.like_score);
check_community_user_action(&local_user_view, &orig_post.community, &mut context.pool()).await?;

View file

@ -28,8 +28,14 @@ pub async fn lock_post(
let post_id = data.post_id;
let local_instance_id = local_user_view.person.instance_id;
let orig_post =
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
let orig_post = PostView::read(
&mut context.pool(),
post_id,
Some(&local_user_view.local_user),
local_instance_id,
false,
)
.await?;
check_community_mod_action(
&local_user_view,

View file

@ -37,8 +37,14 @@ pub async fn mod_update_post(
check_nsfw_allowed(data.nsfw, Some(&local_site))?;
let post_id = data.post_id;
let orig_post =
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
let orig_post = PostView::read(
&mut context.pool(),
post_id,
Some(&local_user_view.local_user),
local_instance_id,
false,
)
.await?;
let community = orig_post.community;
check_community_user_action(&local_user_view, &community, &mut context.pool()).await?;

View file

@ -34,19 +34,25 @@ pub async fn create_post_report(
let person = &local_user_view.person;
let post_id = data.post_id;
let local_instance_id = local_user_view.person.instance_id;
let post_view =
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
let orig_post = PostView::read(
&mut context.pool(),
post_id,
Some(&local_user_view.local_user),
local_instance_id,
false,
)
.await?;
check_community_user_action(&local_user_view, &post_view.community, &mut context.pool()).await?;
check_community_user_action(&local_user_view, &orig_post.community, &mut context.pool()).await?;
check_post_deleted_or_removed(&post_view.post)?;
check_post_deleted_or_removed(&orig_post.post)?;
let report_form = PostReportForm {
creator_id: person.id,
post_id,
original_post_name: post_view.post.name,
original_post_url: post_view.post.url,
original_post_body: post_view.post.body,
original_post_name: orig_post.post.name,
original_post_url: orig_post.post.url,
original_post_body: orig_post.post.body,
reason,
violates_instance_rules: data.violates_instance_rules.unwrap_or_default(),
};
@ -70,9 +76,9 @@ pub async fn create_post_report(
ActivityChannel::submit_activity(
SendActivityData::CreateReport {
object_id: post_view.post.ap_id.inner().clone(),
object_id: orig_post.post.ap_id.inner().clone(),
actor: local_user_view.person,
receiver: Either::Right(post_view.community),
receiver: Either::Right(orig_post.community),
reason: data.reason.clone(),
},
&context,

View file

@ -97,8 +97,14 @@ pub async fn update_post(
}
let post_id = data.post_id;
let orig_post =
PostView::read(&mut context.pool(), post_id, None, local_instance_id, false).await?;
let orig_post = PostView::read(
&mut context.pool(),
post_id,
Some(&local_user_view.local_user),
local_instance_id,
false,
)
.await?;
check_community_user_action(&local_user_view, &orig_post.community, &mut context.pool()).await?;