diff options
-rw-r--r-- | lib/mix/tasks/pleroma/user.ex | 10 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 4 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/representers/activity_representer.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/views/activity_view.ex | 2 | ||||
-rw-r--r-- | test/support/factory.ex | 13 | ||||
-rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 12 | ||||
-rw-r--r-- | test/web/twitter_api/views/activity_view_test.exs | 33 |
8 files changed, 71 insertions, 7 deletions
diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 217a52fdd..c311d48e0 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -22,6 +22,7 @@ defmodule Mix.Tasks.Pleroma.User do - `--password PASSWORD` - the user's password - `--moderator`/`--no-moderator` - whether the user is a moderator - `--admin`/`--no-admin` - whether the user is an admin + - `-y`, `--assume-yes`/`--no-assume-yes` - whether to assume yes to all questions ## Generate an invite link. @@ -61,7 +62,11 @@ defmodule Mix.Tasks.Pleroma.User do bio: :string, password: :string, moderator: :boolean, - admin: :boolean + admin: :boolean, + assume_yes: :boolean + ], + aliases: [ + y: :assume_yes ] ) @@ -79,6 +84,7 @@ defmodule Mix.Tasks.Pleroma.User do moderator? = Keyword.get(options, :moderator, false) admin? = Keyword.get(options, :admin, false) + assume_yes? = Keyword.get(options, :assume_yes, false) Mix.shell().info(""" A user will be created with the following information: @@ -93,7 +99,7 @@ defmodule Mix.Tasks.Pleroma.User do - admin: #{if(admin?, do: "true", else: "false")} """) - proceed? = Mix.shell().yes?("Continue?") + proceed? = assume_yes? or Mix.shell().yes?("Continue?") unless not proceed? do Common.start_pleroma() diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 4d754de13..4685f6d95 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -801,6 +801,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end + def is_public?(%Object{data: %{"type" => "Tombstone"}}) do + false + end + def is_public?(activity) do "https://www.w3.org/ns/activitystreams#Public" in (activity.data["to"] ++ (activity.data["cc"] || [])) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index e474653ff..bb3c38f00 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPI do Map.put( object, "emoji", - Formatter.get_emoji(status) + (Formatter.get_emoji(status) ++ Formatter.get_emoji(data["spoiler_text"])) |> Enum.reduce(%{}, fn {name, file}, acc -> Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") end) diff --git a/lib/pleroma/web/twitter_api/representers/activity_representer.ex b/lib/pleroma/web/twitter_api/representers/activity_representer.ex index 2a221cc66..245cd52fd 100644 --- a/lib/pleroma/web/twitter_api/representers/activity_representer.ex +++ b/lib/pleroma/web/twitter_api/representers/activity_representer.ex @@ -207,7 +207,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => object["summary"] + "summary" => HTML.strip_tags(object["summary"]) |> Formatter.emojify(object["emoji"]) } end diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index a0be5cfc5..ad0cc76ed 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -289,7 +289,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "activity_type" => "post", "possibly_sensitive" => possibly_sensitive, "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object), - "summary" => summary + "summary" => HTML.strip_tags(summary) |> Formatter.emojify(object["emoji"]) } end diff --git a/test/support/factory.ex b/test/support/factory.ex index e5c0c5bcc..57fa4a79d 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -57,6 +57,19 @@ defmodule Pleroma.Factory do %Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})} end + def tombstone_factory do + data = %{ + "type" => "Tombstone", + "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(), + "formerType" => "Note", + "deleted" => DateTime.utc_now() |> DateTime.to_iso8601() + } + + %Pleroma.Object{ + data: data + } + end + def direct_note_activity_factory do dm = insert(:direct_note) diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 620e03674..7d1fe184e 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -75,6 +75,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert json_response(conn, 404) end + + test "it returns 404 for tombstone objects", %{conn: conn} do + tombstone = insert(:tombstone) + uuid = String.split(tombstone.data["id"], "/") |> List.last() + + conn = + conn + |> put_req_header("accept", "application/activity+json") + |> get("/objects/#{uuid}") + + assert json_response(conn, 404) + end end describe "/inbox" do diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 013245033..05780a54a 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -41,6 +41,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg" end + test "a create activity with a summary containing emoji" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => ":woollysocks: meow", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = + "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow" + + assert result["summary"] == expected + end + + test "a create activity with a summary containing invalid HTML" do + {:ok, activity} = + CommonAPI.post(insert(:user), %{ + "spoiler_text" => "<span style=\"color: magenta; font-size: 32px;\">meow</span>", + "status" => "." + }) + + result = ActivityView.render("activity.json", activity: activity) + + expected = "meow" + + assert result["summary"] == expected + end + test "a create activity with a note" do user = insert(:user) other_user = insert(:user, %{nickname: "shp"}) @@ -73,14 +102,14 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "repeat_num" => 0, "repeated" => false, "statusnet_conversation_id" => convo_id, + "summary" => "", "statusnet_html" => "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!", "tags" => [], "text" => "Hey @shp!", "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), - "visibility" => "direct", - "summary" => nil + "visibility" => "direct" } assert result == expected |