aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-06-04 10:55:45 +0000
committerlain <lain@soykaf.club>2019-06-04 10:55:45 +0000
commit8ac104cde093991a77079186be02504c121a45fe (patch)
treed7f97c038673e7120de93eb0686213f885a94d89
parentd977d73b91dbf8e9129de0478c51114d7d462edf (diff)
parentbbff7554de7f8c3965387fb3509728c1f2c2d04b (diff)
downloadpleroma-8ac104cde093991a77079186be02504c121a45fe.tar.gz
Merge branch 'fix/fetch-votes-restrict-create' into 'develop'
Restrict `get_existing_votes` to only get Create activities See merge request pleroma/pleroma!1244
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex1
-rw-r--r--lib/pleroma/web/common_api/common_api.ex17
-rw-r--r--test/web/activity_pub/utils_test.exs43
3 files changed, 54 insertions, 7 deletions
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index b8159e9e5..faae7e747 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -794,6 +794,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
query =
from(
[activity, object: object] in Activity.with_preloaded_object(Activity),
+ where: fragment("(?)->>'type' = 'Create'", activity.data),
where: fragment("(?)->>'actor' = ?", activity.data, ^actor),
where:
fragment(
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index 5212d5ce5..ad3c03c55 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -132,13 +132,16 @@ defmodule Pleroma.Web.CommonAPI do
Enum.map(choices, fn index ->
answer_data = make_answer_data(user, object, Enum.at(options, index)["name"])
- ActivityPub.create(%{
- to: answer_data["to"],
- actor: user,
- context: object.data["context"],
- object: answer_data,
- additional: %{"cc" => answer_data["cc"]}
- })
+ {:ok, activity} =
+ ActivityPub.create(%{
+ to: answer_data["to"],
+ actor: user,
+ context: object.data["context"],
+ object: answer_data,
+ additional: %{"cc" => answer_data["cc"]}
+ })
+
+ activity
end)
object = Object.get_cached_by_ap_id(object.data["id"])
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index c57fae437..de741c64b 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,6 +1,7 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -204,4 +205,46 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
]
}
end
+
+ describe "get_existing_votes" do
+ test "fetches existing votes" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "How do I pronounce LaTeX?",
+ "poll" => %{
+ "options" => ["laytekh", "lahtekh", "latex"],
+ "expires_in" => 20,
+ "multiple" => true
+ }
+ })
+
+ object = Object.normalize(activity)
+ {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1])
+ assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes)
+ end
+
+ test "fetches only Create activities" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "Are we living in a society?",
+ "poll" => %{
+ "options" => ["yes", "no"],
+ "expires_in" => 20
+ }
+ })
+
+ object = Object.normalize(activity)
+ {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
+ vote_object = Object.normalize(vote)
+ {:ok, _activity, _object} = ActivityPub.like(user, vote_object)
+ [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
+ assert fetched_vote.id == vote.id
+ end
+ end
end