From f8fb3b41f0e6072b9737f0597e04a0785597da4e Mon Sep 17 00:00:00 2001 From: Nutomic Date: Mon, 14 Mar 2022 18:20:18 +0000 Subject: [PATCH] Reject federated downvotes if downvotes are disabled (fixes #2124) (#2128) --- crates/apub/src/activities/voting/vote.rs | 7 ++++++- crates/apub/src/protocol/activities/voting/vote.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 789a4c67..11ed9b36 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -13,6 +13,7 @@ use crate::{ PostOrComment, }; use activitystreams_kinds::public; +use anyhow::anyhow; use lemmy_api_common::blocking; use lemmy_apub_lib::{ data::Data, @@ -21,7 +22,7 @@ use lemmy_apub_lib::{ }; use lemmy_db_schema::{ newtypes::CommunityId, - source::{community::Community, post::Post}, + source::{community::Community, post::Post, site::Site}, traits::Crud, }; use lemmy_utils::LemmyError; @@ -81,6 +82,10 @@ impl ActivityHandler for Vote { verify_activity(&self.id, self.actor.inner(), &context.settings())?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; + let site = blocking(context.pool(), Site::read_local_site).await??; + if self.kind == VoteType::Dislike && !site.enable_downvotes { + return Err(anyhow!("Downvotes disabled").into()); + } Ok(()) } diff --git a/crates/apub/src/protocol/activities/voting/vote.rs b/crates/apub/src/protocol/activities/voting/vote.rs index cafd6bbc..763d8623 100644 --- a/crates/apub/src/protocol/activities/voting/vote.rs +++ b/crates/apub/src/protocol/activities/voting/vote.rs @@ -27,7 +27,7 @@ pub struct Vote { pub(crate) unparsed: Unparsed, } -#[derive(Clone, Debug, Display, Deserialize, Serialize)] +#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq)] pub enum VoteType { Like, Dislike, -- 2.44.1