From 3ef40ecc067a2f76c42aadc635ca0f09f2bae9ac Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 10 Oct 2024 13:38:03 -0400 Subject: [PATCH] QuestionValidator: Drop likes if it is not a list This appears to be an issue exclusive to refetching the object when refreshing a poll --- changelog.d/question-validator.fix | 1 + .../activity_pub/object_validators/question_validator.ex | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 changelog.d/question-validator.fix diff --git a/changelog.d/question-validator.fix b/changelog.d/question-validator.fix new file mode 100644 index 000000000..91093daee --- /dev/null +++ b/changelog.d/question-validator.fix @@ -0,0 +1 @@ +Polls could fail to refresh due to an incorrect data validation constraint. diff --git a/lib/pleroma/web/activity_pub/object_validators/question_validator.ex b/lib/pleroma/web/activity_pub/object_validators/question_validator.ex index 7f9d4d648..21754fa8a 100644 --- a/lib/pleroma/web/activity_pub/object_validators/question_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/question_validator.ex @@ -59,6 +59,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do end end + defp fix_likes(data) do + cond do + is_list(data["likes"]) -> data + true -> Map.drop(data, ["likes"]) + end + end + defp fix(data) do data |> CommonFixes.fix_actor() @@ -66,6 +73,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do |> CommonFixes.fix_quote_url() |> Transmogrifier.fix_emoji() |> fix_closed() + |> fix_likes() end def changeset(struct, data) do