Merge branch 'relay-fix-admin-fe' into 'develop'
authorfeld <feld@feld.me>
Mon, 24 Aug 2020 17:03:18 +0000 (17:03 +0000)
committerfeld <feld@feld.me>
Mon, 24 Aug 2020 17:03:18 +0000 (17:03 +0000)
Relay fix for admin-fe

See merge request pleroma/pleroma!2902

25 files changed:
.gitlab-ci.yml
lib/mix/pleroma.ex
lib/mix/tasks/pleroma/emoji.ex
lib/pleroma/emails/user_email.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/object_validator.ex
lib/pleroma/web/activity_pub/object_validators/attachment_validator.ex
lib/pleroma/web/activity_pub/object_validators/audio_validator.ex
lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex
lib/pleroma/web/activity_pub/object_validators/event_validator.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/object_validators/note_validator.ex
lib/pleroma/web/activity_pub/object_validators/question_validator.ex
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/admin_api/views/account_view.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/emails/mailer_test.exs
test/fixtures/tesla_mock/funkwhale_create_audio.json [new file with mode: 0644]
test/tasks/digest_test.exs
test/tasks/email_test.exs
test/web/activity_pub/transmogrifier/audio_handling_test.exs
test/web/activity_pub/transmogrifier/event_handling_test.exs [new file with mode: 0644]
test/web/activity_pub/transmogrifier/question_handling_test.exs
test/web/admin_api/controllers/admin_api_controller_test.exs
test/web/mastodon_api/views/status_view_test.exs

index 9e9107ce370741d86570e970fb59a5e6731ea28d..be0dd4773cb7f5b4e12d25ec18bbf4631383d3d4 100644 (file)
@@ -194,7 +194,7 @@ amd64:
   variables: &release-variables
     MIX_ENV: prod
   before_script: &before-release
-  - apt install cmake -y
+  - apt-get update && apt-get install -y cmake
   - echo "import Mix.Config" > config/prod.secret.exs
   - mix local.hex --force
   - mix local.rebar --force
index 074492a4698eff861aec3d35cdc51eca50c6e52f..fe9b0d16c3b4f413303d7cbceb2d9cc212c7337b 100644 (file)
@@ -14,7 +14,7 @@ defmodule Mix.Pleroma do
     :swoosh,
     :timex
   ]
-  @cachex_children ["object", "user"]
+  @cachex_children ["object", "user", "scrubber"]
   @doc "Common functions to be reused in mix tasks"
   def start_pleroma do
     Pleroma.Config.Holder.save_default()
index f4eaeac98c2c5244679183af0b7ff1b2d227c392..8f52ee98d2245aa6db36206c735fabff6034e331 100644 (file)
@@ -15,7 +15,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do
     {options, [], []} = parse_global_opts(args)
 
     url_or_path = options[:manifest] || default_manifest()
-    manifest = fetch_and_decode(url_or_path)
+    manifest = fetch_and_decode!(url_or_path)
 
     Enum.each(manifest, fn {name, info} ->
       to_print = [
@@ -42,7 +42,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do
 
     url_or_path = options[:manifest] || default_manifest()
 
-    manifest = fetch_and_decode(url_or_path)
+    manifest = fetch_and_decode!(url_or_path)
 
     for pack_name <- pack_names do
       if Map.has_key?(manifest, pack_name) do
@@ -92,7 +92,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do
           ])
         )
 
-        files = fetch_and_decode(files_loc)
+        files = fetch_and_decode!(files_loc)
 
         IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name]))
 
@@ -243,9 +243,11 @@ defmodule Mix.Tasks.Pleroma.Emoji do
     IO.puts("Emoji packs have been reloaded.")
   end
 
-  defp fetch_and_decode(from) do
+  defp fetch_and_decode!(from) do
     with {:ok, json} <- fetch(from) do
       Jason.decode!(json)
+    else
+      {:error, error} -> raise "#{from} cannot be fetched. Error: #{error} occur."
     end
   end
 
index 3135338593fdc34da8733ad855cefdd574bfddf6..1d8c72ae93a5b057c106e34d45a31efcad8a2eaf 100644 (file)
@@ -107,25 +107,34 @@ defmodule Pleroma.Emails.UserEmail do
       |> Enum.filter(&(&1.activity.data["type"] == "Create"))
       |> Enum.map(fn notification ->
         object = Pleroma.Object.normalize(notification.activity)
-        object = update_in(object.data["content"], &format_links/1)
 
-        %{
-          data: notification,
-          object: object,
-          from: User.get_by_ap_id(notification.activity.actor)
-        }
+        if not is_nil(object) do
+          object = update_in(object.data["content"], &format_links/1)
+
+          %{
+            data: notification,
+            object: object,
+            from: User.get_by_ap_id(notification.activity.actor)
+          }
+        end
       end)
+      |> Enum.filter(& &1)
 
     followers =
       notifications
       |> Enum.filter(&(&1.activity.data["type"] == "Follow"))
       |> Enum.map(fn notification ->
-        %{
-          data: notification,
-          object: Pleroma.Object.normalize(notification.activity),
-          from: User.get_by_ap_id(notification.activity.actor)
-        }
+        from = User.get_by_ap_id(notification.activity.actor)
+
+        if not is_nil(from) do
+          %{
+            data: notification,
+            object: Pleroma.Object.normalize(notification.activity),
+            from: User.get_by_ap_id(notification.activity.actor)
+          }
+        end
       end)
+      |> Enum.filter(& &1)
 
     unless Enum.empty?(mentions) do
       styling = Config.get([__MODULE__, :styling])
index 04478bc33c01621342dd5d28e8107f848186b4ad..624a508ae3d907438d0df2301cdb1ea458580257 100644 (file)
@@ -85,7 +85,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp increase_replies_count_if_reply(_create_data), do: :noop
 
-  @object_types ["ChatMessage", "Question", "Answer"]
+  @object_types ~w[ChatMessage Question Answer Audio Event]
   @spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
   def persist(%{"type" => type} = object, meta) when type in @object_types do
     with {:ok, object} <- Object.create(object) do
index d770ce1be37df31c2ed691cb362bbbe8a59b0c2a..b77c063959672b7cb117f05342ebcd0a42f17950 100644 (file)
@@ -23,6 +23,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
   alias Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator
+  alias Pleroma.Web.ActivityPub.ObjectValidators.EventValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.FollowValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator
@@ -43,6 +44,16 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
     end
   end
 
+  def validate(%{"type" => "Event"} = object, meta) do
+    with {:ok, object} <-
+           object
+           |> EventValidator.cast_and_validate()
+           |> Ecto.Changeset.apply_action(:insert) do
+      object = stringify_keys(object)
+      {:ok, object, meta}
+    end
+  end
+
   def validate(%{"type" => "Follow"} = object, meta) do
     with {:ok, object} <-
            object
@@ -187,7 +198,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
         %{"type" => "Create", "object" => %{"type" => objtype} = object} = create_activity,
         meta
       )
-      when objtype in ~w[Question Answer Audio] do
+      when objtype in ~w[Question Answer Audio Event] do
     with {:ok, object_data} <- cast_and_apply(object),
          meta = Keyword.put(meta, :object_data, object_data |> stringify_keys),
          {:ok, create_activity} <-
@@ -225,6 +236,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do
     AudioValidator.cast_and_apply(object)
   end
 
+  def cast_and_apply(%{"type" => "Event"} = object) do
+    EventValidator.cast_and_apply(object)
+  end
+
   def cast_and_apply(o), do: {:error, {:validator_not_set, o}}
 
   # is_struct/1 isn't present in Elixir 1.8.x
index f53bb02bec8d3261ec76e00cf1948b4907fb5c9e..c8b1482802dd1b01202e3ced6e2d1ee23a46f88e 100644 (file)
@@ -41,34 +41,34 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator do
   end
 
   def fix_media_type(data) do
-    data =
-      data
-      |> Map.put_new("mediaType", data["mimeType"])
+    data = Map.put_new(data, "mediaType", data["mimeType"])
 
     if MIME.valid?(data["mediaType"]) do
       data
     else
-      data
-      |> Map.put("mediaType", "application/octet-stream")
+      Map.put(data, "mediaType", "application/octet-stream")
     end
   end
 
-  def fix_url(data) do
-    case data["url"] do
-      url when is_binary(url) ->
-        data
-        |> Map.put(
-          "url",
-          [
-            %{
-              "href" => url,
-              "type" => "Link",
-              "mediaType" => data["mediaType"]
-            }
-          ]
-        )
-
-      _ ->
+  defp handle_href(href, mediaType) do
+    [
+      %{
+        "href" => href,
+        "type" => "Link",
+        "mediaType" => mediaType
+      }
+    ]
+  end
+
+  defp fix_url(data) do
+    cond do
+      is_binary(data["url"]) ->
+        Map.put(data, "url", handle_href(data["url"], data["mediaType"]))
+
+      is_binary(data["href"]) and data["url"] == nil ->
+        Map.put(data, "url", handle_href(data["href"], data["mediaType"]))
+
+      true ->
         data
     end
   end
index 5d9bf345f512d9bf0a9a5e7c51cb08019a4fdbb2..d1869f18809ad7e8a068246546a9da004b7f841b 100644 (file)
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
     field(:like_count, :integer, default: 0)
     field(:announcement_count, :integer, default: 0)
     field(:inReplyTo, :string)
-    field(:uri, ObjectValidators.Uri)
+    field(:url, ObjectValidators.Uri)
     # short identifier for PleromaFE to group statuses by context
     field(:context_id, :integer)
 
@@ -66,10 +66,24 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
     |> changeset(data)
   end
 
+  defp fix_url(%{"url" => url} = data) when is_list(url) do
+    attachment =
+      Enum.find(url, fn x -> is_map(x) and String.starts_with?(x["mimeType"], "audio/") end)
+
+    link_element = Enum.find(url, fn x -> is_map(x) and x["mimeType"] == "text/html" end)
+
+    data
+    |> Map.put("attachment", [attachment])
+    |> Map.put("url", link_element["href"])
+  end
+
+  defp fix_url(data), do: data
+
   defp fix(data) do
     data
     |> CommonFixes.fix_defaults()
     |> CommonFixes.fix_attribution()
+    |> fix_url()
   end
 
   def changeset(struct, data) do
@@ -83,7 +97,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioValidator do
   def validate_data(data_cng) do
     data_cng
     |> validate_inclusion(:type, ["Audio"])
-    |> validate_required([:id, :actor, :attributedTo, :type, :context])
+    |> validate_required([:id, :actor, :attributedTo, :type, :context, :attachment])
     |> CommonValidations.validate_any_presence([:cc, :to])
     |> CommonValidations.validate_fields_match([:actor, :attributedTo])
     |> CommonValidations.validate_actor_presence()
index 60868eae08ac83c1fd326227bdae9548d97b777f..b3dbeea5720227abb7613382f2827c3936bace2b 100644 (file)
@@ -61,9 +61,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
     end
   end
 
+  defp fix_addressing(data, meta) do
+    if object = meta[:object_data] do
+      data
+      |> Map.put_new("to", object["to"] || [])
+      |> Map.put_new("cc", object["cc"] || [])
+    else
+      data
+    end
+  end
+
   defp fix(data, meta) do
     data
     |> fix_context(meta)
+    |> fix_addressing(meta)
   end
 
   def validate_data(cng, meta \\ []) do
diff --git a/lib/pleroma/web/activity_pub/object_validators/event_validator.ex b/lib/pleroma/web/activity_pub/object_validators/event_validator.ex
new file mode 100644 (file)
index 0000000..07e4821
--- /dev/null
@@ -0,0 +1,96 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.EventValidator do
+  use Ecto.Schema
+
+  alias Pleroma.EctoType.ActivityPub.ObjectValidators
+  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
+  alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
+  alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
+
+  import Ecto.Changeset
+
+  @primary_key false
+  @derive Jason.Encoder
+
+  # Extends from NoteValidator
+  embedded_schema do
+    field(:id, ObjectValidators.ObjectID, primary_key: true)
+    field(:to, ObjectValidators.Recipients, default: [])
+    field(:cc, ObjectValidators.Recipients, default: [])
+    field(:bto, ObjectValidators.Recipients, default: [])
+    field(:bcc, ObjectValidators.Recipients, default: [])
+    # TODO: Write type
+    field(:tag, {:array, :map}, default: [])
+    field(:type, :string)
+
+    field(:name, :string)
+    field(:summary, :string)
+    field(:content, :string)
+
+    field(:context, :string)
+    # short identifier for PleromaFE to group statuses by context
+    field(:context_id, :integer)
+
+    # TODO: Remove actor on objects
+    field(:actor, ObjectValidators.ObjectID)
+
+    field(:attributedTo, ObjectValidators.ObjectID)
+    field(:published, ObjectValidators.DateTime)
+    # TODO: Write type
+    field(:emoji, :map, default: %{})
+    field(:sensitive, :boolean, default: false)
+    embeds_many(:attachment, AttachmentValidator)
+    field(:replies_count, :integer, default: 0)
+    field(:like_count, :integer, default: 0)
+    field(:announcement_count, :integer, default: 0)
+    field(:inReplyTo, ObjectValidators.ObjectID)
+    field(:url, ObjectValidators.Uri)
+
+    field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
+    field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+  end
+
+  def cast_and_apply(data) do
+    data
+    |> cast_data
+    |> apply_action(:insert)
+  end
+
+  def cast_and_validate(data) do
+    data
+    |> cast_data()
+    |> validate_data()
+  end
+
+  def cast_data(data) do
+    %__MODULE__{}
+    |> changeset(data)
+  end
+
+  defp fix(data) do
+    data
+    |> CommonFixes.fix_defaults()
+    |> CommonFixes.fix_attribution()
+  end
+
+  def changeset(struct, data) do
+    data = fix(data)
+
+    struct
+    |> cast(data, __schema__(:fields) -- [:attachment])
+    |> cast_embed(:attachment)
+  end
+
+  def validate_data(data_cng) do
+    data_cng
+    |> validate_inclusion(:type, ["Event"])
+    |> validate_required([:id, :actor, :attributedTo, :type, :context, :context_id])
+    |> CommonValidations.validate_any_presence([:cc, :to])
+    |> CommonValidations.validate_fields_match([:actor, :attributedTo])
+    |> CommonValidations.validate_actor_presence()
+    |> CommonValidations.validate_host_match()
+  end
+end
index 14ae29cb6a7e58151ed59a9eee64e90d8ad92603..20e73561946996f4861cd409a1e57bd295a986a4 100644 (file)
@@ -20,11 +20,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator do
     # TODO: Write type
     field(:tag, {:array, :map}, default: [])
     field(:type, :string)
+
+    field(:name, :string)
+    field(:summary, :string)
     field(:content, :string)
+
     field(:context, :string)
+    # short identifier for PleromaFE to group statuses by context
+    field(:context_id, :integer)
+
     field(:actor, ObjectValidators.ObjectID)
     field(:attributedTo, ObjectValidators.ObjectID)
-    field(:summary, :string)
     field(:published, ObjectValidators.DateTime)
     # TODO: Write type
     field(:emoji, :map, default: %{})
@@ -35,13 +41,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator do
     field(:like_count, :integer, default: 0)
     field(:announcement_count, :integer, default: 0)
     field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:uri, ObjectValidators.Uri)
+    field(:url, ObjectValidators.Uri)
 
     field(:likes, {:array, :string}, default: [])
     field(:announcements, {:array, :string}, default: [])
-
-    # see if needed
-    field(:context_id, :string)
   end
 
   def cast_and_validate(data) do
index a7ca42b2fa3c71047f95edf18a45a76207085c14..712047424665ce5729423729d359575ed1397b83 100644 (file)
@@ -43,7 +43,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
     field(:like_count, :integer, default: 0)
     field(:announcement_count, :integer, default: 0)
     field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:uri, ObjectValidators.Uri)
+    field(:url, ObjectValidators.Uri)
     # short identifier for PleromaFE to group statuses by context
     field(:context_id, :integer)
 
index 3dc66c60b838e713ed252ed43ce3d17a84acab1b..a5e2323bd61d5f2299cb79b37c9c042b92847f26 100644 (file)
@@ -341,7 +341,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
   end
 
   def handle_object_creation(%{"type" => objtype} = object, meta)
-      when objtype in ~w[Audio Question] do
+      when objtype in ~w[Audio Question Event] do
     with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
       {:ok, object, meta}
     end
index 6be17e0eda7b30d8076b7489d4f04be27941791b..76298c4a0b840542f6906c447d1283f472d81ea9 100644 (file)
@@ -276,13 +276,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
     Map.put(object, "url", url["href"])
   end
 
-  def fix_url(%{"type" => object_type, "url" => url} = object)
-      when object_type in ["Video", "Audio"] and is_list(url) do
+  def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do
     attachment =
       Enum.find(url, fn x ->
         media_type = x["mediaType"] || x["mimeType"] || ""
 
-        is_map(x) and String.starts_with?(media_type, ["audio/", "video/"])
+        is_map(x) and String.starts_with?(media_type, "video/")
       end)
 
     link_element =
@@ -461,7 +460,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
         %{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
         options
       )
-      when objtype in ~w{Article Event Note Video Page} do
+      when objtype in ~w{Article Note Video Page} do
     actor = Containment.get_actor(data)
 
     with nil <- Activity.get_create_by_object_ap_id(object["id"]),
@@ -555,7 +554,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
         %{"type" => "Create", "object" => %{"type" => objtype}} = data,
         _options
       )
-      when objtype in ~w{Question Answer ChatMessage Audio} do
+      when objtype in ~w{Question Answer ChatMessage Audio Event} do
     with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
          {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
       {:ok, activity}
index 333e72e42ab083743378d14b969dfa5fee810183..9c477feabb49812c96dcade416a9f65b52431015 100644 (file)
@@ -79,7 +79,8 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
       "confirmation_pending" => user.confirmation_pending,
       "approval_pending" => user.approval_pending,
       "url" => user.uri || user.ap_id,
-      "registration_reason" => user.registration_reason
+      "registration_reason" => user.registration_reason,
+      "actor_type" => user.actor_type
     }
   end
 
index 91b41ef59cda66ddaa4cf5aa7c5d11cfdc4db083..01b8bb6bb1b1cfd8ac76adc5f04cb758b84257e2 100644 (file)
@@ -473,23 +473,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     end
   end
 
-  def render_content(%{data: %{"type" => object_type}} = object)
-      when object_type in ["Video", "Event", "Audio"] do
-    with name when not is_nil(name) and name != "" <- object.data["name"] do
-      "<p><a href=\"#{object.data["id"]}\">#{name}</a></p>#{object.data["content"]}"
-    else
-      _ -> object.data["content"] || ""
-    end
-  end
+  def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
+    url = object.data["url"] || object.data["id"]
 
-  def render_content(%{data: %{"type" => object_type}} = object)
-      when object_type in ["Article", "Page"] do
-    with summary when not is_nil(summary) and summary != "" <- object.data["name"],
-         url when is_bitstring(url) <- object.data["url"] do
-      "<p><a href=\"#{url}\">#{summary}</a></p>#{object.data["content"]}"
-    else
-      _ -> object.data["content"] || ""
-    end
+    "<p><a href=\"#{url}\">#{name}</a></p>#{object.data["content"]}"
   end
 
   def render_content(object), do: object.data["content"] || ""
index 3da45056bed564d0dbce77f7de2b6ba5f8c88e8d..9e232d2a0b8fab77b33e40633d377c0e3d11eeb8 100644 (file)
@@ -14,10 +14,10 @@ defmodule Pleroma.Emails.MailerTest do
     subject: "Pleroma test email",
     to: [{"Test User", "user1@example.com"}]
   }
-  setup do: clear_config([Pleroma.Emails.Mailer, :enabled])
+  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
 
   test "not send email when mailer is disabled" do
-    Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
+    clear_config([Pleroma.Emails.Mailer, :enabled], false)
     Mailer.deliver(@email)
     :timer.sleep(100)
 
diff --git a/test/fixtures/tesla_mock/funkwhale_create_audio.json b/test/fixtures/tesla_mock/funkwhale_create_audio.json
new file mode 100644 (file)
index 0000000..fe6059c
--- /dev/null
@@ -0,0 +1,58 @@
+{
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    "https://w3id.org/security/v1",
+    "https://funkwhale.audio/ns",
+    {
+      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+      "Hashtag": "as:Hashtag"
+    }
+  ],
+  "type": "Create",
+  "id": "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871/activity",
+  "actor": "https://channels.tests.funkwhale.audio/federation/actors/compositions",
+  "object": {
+    "id": "https://channels.tests.funkwhale.audio/federation/music/uploads/42342395-0208-4fee-a38d-259a6dae0871",
+    "type": "Audio",
+    "name": "Compositions - Test Audio for Pleroma",
+    "attributedTo": "https://channels.tests.funkwhale.audio/federation/actors/compositions",
+    "published": "2020-03-11T10:01:52.714918+00:00",
+    "to": "https://www.w3.org/ns/activitystreams#Public",
+    "url": [
+      {
+        "type": "Link",
+        "mimeType": "audio/ogg",
+        "href": "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false"
+      },
+      {
+        "type": "Link",
+        "mimeType": "text/html",
+        "href": "https://channels.tests.funkwhale.audio/library/tracks/74"
+      }
+    ],
+    "content": "<p>This is a test Audio for Pleroma.</p>",
+    "mediaType": "text/html",
+    "tag": [
+      {
+        "type": "Hashtag",
+        "name": "#funkwhale"
+      },
+      {
+        "type": "Hashtag",
+        "name": "#test"
+      },
+      {
+        "type": "Hashtag",
+        "name": "#tests"
+      }
+    ],
+    "summary": "#funkwhale #test #tests",
+    "@context": [
+      "https://www.w3.org/ns/activitystreams",
+      "https://w3id.org/security/v1",
+      {
+        "manuallyApprovesFollowers": "as:manuallyApprovesFollowers"
+      }
+    ]
+  }
+}
index eefbc893624d03eb545bb70f81656e39889e2120..0b444c86d8e9dd36469abe5f5ed5d6eb46cf4151 100644 (file)
@@ -17,6 +17,8 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
     :ok
   end
 
+  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
+
   describe "pleroma.digest test" do
     test "Sends digest to the given user" do
       user1 = insert(:user)
index 944c070641f7f878e136ac5ecebb89031f88c6c3..c3af7ef68ab3a2c7dc9b91844257660f59795789 100644 (file)
@@ -16,6 +16,8 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
     :ok
   end
 
+  setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
+
   describe "pleroma.email test" do
     test "Sends test email with no given address" do
       mail_to = Config.get([:instance, :email])
index c74a9c45d32dbeb7d4709df42d9fca7d417aaeec..0636d00c5bd5b9cf646dee332df67388459cc286 100644 (file)
@@ -42,4 +42,42 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
     assert object.data["album"] == "lain radio"
     assert object.data["length"] == 180_000
   end
+
+  test "Funkwhale Audio object" do
+    Tesla.Mock.mock(fn
+      %{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
+        %Tesla.Env{
+          status: 200,
+          body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")
+        }
+    end)
+
+    data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Poison.decode!()
+
+    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+    assert object = Object.normalize(activity, false)
+
+    assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+
+    assert object.data["cc"] == []
+
+    assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
+
+    assert object.data["attachment"] == [
+             %{
+               "mediaType" => "audio/ogg",
+               "type" => "Link",
+               "name" => nil,
+               "url" => [
+                 %{
+                   "href" =>
+                     "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
+                   "mediaType" => "audio/ogg",
+                   "type" => "Link"
+                 }
+               ]
+             }
+           ]
+  end
 end
diff --git a/test/web/activity_pub/transmogrifier/event_handling_test.exs b/test/web/activity_pub/transmogrifier/event_handling_test.exs
new file mode 100644 (file)
index 0000000..7f1ef2c
--- /dev/null
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
+  use Oban.Testing, repo: Pleroma.Repo
+  use Pleroma.DataCase
+
+  alias Pleroma.Object.Fetcher
+
+  test "Mobilizon Event object" do
+    Tesla.Mock.mock(fn
+      %{url: "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"} ->
+        %Tesla.Env{
+          status: 200,
+          body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
+        }
+
+      %{url: "https://mobilizon.org/@tcit"} ->
+        %Tesla.Env{
+          status: 200,
+          body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
+        }
+    end)
+
+    assert {:ok, object} =
+             Fetcher.fetch_object_from_id(
+               "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
+             )
+
+    assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
+    assert object.data["cc"] == []
+
+    assert object.data["url"] ==
+             "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
+
+    assert object.data["published"] == "2019-12-17T11:33:56Z"
+    assert object.data["name"] == "Mobilizon Launching Party"
+  end
+end
index 9fb965d7facda0efba6daf8658fc5fb9673d8451..c82361828883ef0b17fb7ede4f46a6194b52ec7d 100644 (file)
@@ -24,6 +24,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
 
     object = Object.normalize(activity, false)
 
+    assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304"
+
     assert object.data["closed"] == "2019-05-11T09:03:36Z"
 
     assert object.data["context"] == activity.data["context"]
index 2eb698807118ab78f3b6464458c79a3823c56cf8..dbf478edf0dd2c9fb87299fb7a5595774d87726a 100644 (file)
@@ -381,7 +381,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
         "confirmation_pending" => false,
         "approval_pending" => false,
         "url" => user.ap_id,
-        "registration_reason" => nil
+        "registration_reason" => nil,
+        "actor_type" => "Person"
       }
 
       assert expected == json_response(conn, 200)
@@ -663,7 +664,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => admin.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => user.deactivated,
@@ -677,7 +679,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => user.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => user2.deactivated,
@@ -691,7 +694,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => true,
             "url" => user2.ap_id,
-            "registration_reason" => "I'm a chill dude"
+            "registration_reason" => "I'm a chill dude",
+            "actor_type" => "Person"
           }
         ]
         |> Enum.sort_by(& &1["nickname"])
@@ -766,7 +770,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -794,7 +799,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -822,7 +828,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -850,7 +857,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -878,7 +886,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -906,7 +915,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -929,7 +939,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user2.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -964,7 +975,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -992,7 +1004,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => user.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => admin.deactivated,
@@ -1006,7 +1019,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => admin.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => false,
@@ -1020,7 +1034,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => old_admin.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           }
         ]
         |> Enum.sort_by(& &1["nickname"])
@@ -1058,7 +1073,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => true,
             "url" => user.ap_id,
-            "registration_reason" => "Plz let me in!"
+            "registration_reason" => "Plz let me in!",
+            "actor_type" => "Person"
           }
         ]
         |> Enum.sort_by(& &1["nickname"])
@@ -1091,7 +1107,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => admin.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => false,
@@ -1105,7 +1122,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => second_admin.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           }
         ]
         |> Enum.sort_by(& &1["nickname"])
@@ -1140,7 +1158,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => moderator.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -1168,7 +1187,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => user1.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           },
           %{
             "deactivated" => false,
@@ -1182,7 +1202,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
             "confirmation_pending" => false,
             "approval_pending" => false,
             "url" => user2.ap_id,
-            "registration_reason" => nil
+            "registration_reason" => nil,
+            "actor_type" => "Person"
           }
         ]
         |> Enum.sort_by(& &1["nickname"])
@@ -1245,7 +1266,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => user.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -1272,7 +1294,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "confirmation_pending" => false,
                    "approval_pending" => false,
                    "url" => admin.ap_id,
-                   "registration_reason" => nil
+                   "registration_reason" => nil,
+                   "actor_type" => "Person"
                  }
                ]
              }
@@ -1357,7 +1380,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                "confirmation_pending" => false,
                "approval_pending" => false,
                "url" => user.ap_id,
-               "registration_reason" => nil
+               "registration_reason" => nil,
+               "actor_type" => "Person"
              }
 
     log_entry = Repo.one(ModerationLog)
index 8703d5ba7689a3cb6fb70c97c2be336715acf61c..70d829979bb0cde71f47aec6fee8c92be1158196 100644 (file)
@@ -517,6 +517,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     represented = StatusView.render("show.json", %{for: user, activity: activity})
 
     assert represented[:id] == to_string(activity.id)
+
+    assert represented[:url] ==
+             "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"
+
+    assert represented[:content] ==
+             "<p><a href=\"https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39\">Mobilizon Launching Party</a></p><p>Mobilizon is now federated! 🎉</p><p></p><p>You can view this event from other instances if they are subscribed to mobilizon.org, and soon directly from Mastodon and Pleroma. It is possible that you may see some comments from other instances, including Mastodon ones, just below.</p><p></p><p>With a Mobilizon account on an instance, you may <strong>participate</strong> at events from other instances and <strong>add comments</strong> on events.</p><p></p><p>Of course, it&#39;s still <u>a work in progress</u>: if reports made from an instance on events and comments can be federated, you can&#39;t block people right now, and moderators actions are rather limited, but this <strong>will definitely get fixed over time</strong> until first stable version next year.</p><p></p><p>Anyway, if you want to come up with some feedback, head over to our forum or - if you feel you have technical skills and are familiar with it - on our Gitlab repository.</p><p></p><p>Also, to people that want to set Mobilizon themselves even though we really don&#39;t advise to do that for now, we have a little documentation but it&#39;s quite the early days and you&#39;ll probably need some help. No worries, you can chat with us on our Forum or though our Matrix channel.</p><p></p><p>Check our website for more informations and follow us on Twitter or Mastodon.</p>"
   end
 
   describe "build_tags/1" do