[#1149] Merge remote-tracking branch 'remotes/upstream/develop' into 1149-oban-job...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 22 Aug 2019 17:59:58 +0000 (20:59 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 22 Aug 2019 17:59:58 +0000 (20:59 +0300)
# Conflicts:
# lib/pleroma/application.ex
# lib/pleroma/scheduled_activity_worker.ex
# lib/pleroma/web/federator/retry_queue.ex
# lib/pleroma/web/oauth/token/clean_worker.ex
# test/user_test.exs
# test/web/federator_test.exs

23 files changed:
1  2 
config/config.exs
docs/config.md
lib/pleroma/application.ex
lib/pleroma/digest_email_worker.ex
lib/pleroma/scheduled_activity_worker.ex
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/publisher.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/oauth/token/clean_worker.ex
test/conversation_test.exs
test/tasks/digest_test.exs
test/user_test.exs
test/web/activity_pub/activity_pub_controller_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/digest_email_worker_test.exs
test/web/federator_test.exs
test/web/instances/instance_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs
test/web/twitter_api/twitter_api_controller_test.exs
test/web/twitter_api/util_controller_test.exs

Simple merge
diff --cc docs/config.md
Simple merge
index 7cf60f44a961d846fda1df23581ef85969135d01,25e56b9e2b2820c1d60254e4dac10e16f520faa4..2e2922d28b59ca1b46b31a42e81be4e3d445a9dd
@@@ -29,108 -30,18 +30,21 @@@ defmodule Pleroma.Application d
      # Define workers and child supervisors to be supervised
      children =
        [
-         # Start the Ecto repository
-         %{id: Pleroma.Repo, start: {Pleroma.Repo, :start_link, []}, type: :supervisor},
-         %{id: Pleroma.Config.TransferTask, start: {Pleroma.Config.TransferTask, :start_link, []}},
-         %{id: Pleroma.Emoji, start: {Pleroma.Emoji, :start_link, []}},
-         %{id: Pleroma.Captcha, start: {Pleroma.Captcha, :start_link, []}},
-         %{
-           id: :cachex_used_captcha_cache,
-           start:
-             {Cachex, :start_link,
-              [
-                :used_captcha_cache,
-                [
-                  ttl_interval:
-                    :timer.seconds(Pleroma.Config.get!([Pleroma.Captcha, :seconds_valid]))
-                ]
-              ]}
-         },
-         %{
-           id: :cachex_user,
-           start:
-             {Cachex, :start_link,
-              [
-                :user_cache,
-                [
-                  default_ttl: 25_000,
-                  ttl_interval: 1000,
-                  limit: 2500
-                ]
-              ]}
-         },
-         %{
-           id: :cachex_object,
-           start:
-             {Cachex, :start_link,
-              [
-                :object_cache,
-                [
-                  default_ttl: 25_000,
-                  ttl_interval: 1000,
-                  limit: 2500
-                ]
-              ]}
-         },
-         %{
-           id: :cachex_rich_media,
-           start:
-             {Cachex, :start_link,
-              [
-                :rich_media_cache,
-                [
-                  default_ttl: :timer.minutes(120),
-                  limit: 5000
-                ]
-              ]}
-         },
-         %{
-           id: :cachex_scrubber,
-           start:
-             {Cachex, :start_link,
-              [
-                :scrubber_cache,
-                [
-                  limit: 2500
-                ]
-              ]}
-         },
-         %{
-           id: :cachex_idem,
-           start:
-             {Cachex, :start_link,
-              [
-                :idempotency_cache,
-                [
-                  expiration:
-                    expiration(
-                      default: :timer.seconds(6 * 60 * 60),
-                      interval: :timer.seconds(60)
-                    ),
-                  limit: 2500
-                ]
-              ]}
-         },
-         %{id: Pleroma.FlakeId, start: {Pleroma.FlakeId, :start_link, []}},
-         %{
-           id: Pleroma.ScheduledActivityWorker,
-           start: {Pleroma.ScheduledActivityWorker, :start_link, []}
-         }
+         Pleroma.Repo,
+         Pleroma.Config.TransferTask,
+         Pleroma.Emoji,
+         Pleroma.Captcha,
+         Pleroma.FlakeId,
+         Pleroma.ScheduledActivityWorker
        ] ++
+         cachex_children() ++
          hackney_pool_children() ++
          [
 -          Pleroma.Web.Federator.RetryQueue,
+           Pleroma.Stats,
 +          %{
 +            id: Oban,
 +            start: {Oban, :start_link, [Application.get_env(:pleroma, Oban)]}
 +          },
-           %{
-             id: Pleroma.Web.OAuth.Token.CleanWorker,
-             start: {Pleroma.Web.OAuth.Token.CleanWorker, :start_link, []}
-           },
-           %{
-             id: Pleroma.Stats,
-             start: {Pleroma.Stats, :start_link, []}
-           },
            %{
              id: :web_push_init,
              start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
index 6e44cc955aa2b22d3008bdd54a28cd487e3f58d6,5644d6a678d7a34385a6044ee9017d0cf6fe577b..ffc48bfabd93c16318b1038d60f960671a906ba7
@@@ -1,10 -1,11 +1,14 @@@
+ # Pleroma: A lightweight social networking server
+ # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+ # SPDX-License-Identifier: AGPL-3.0-only
  defmodule Pleroma.DigestEmailWorker do
 +  alias Pleroma.Repo
 +  alias Pleroma.Workers.Mailer, as: MailerWorker
 +
    import Ecto.Query
  
 -  @queue_name :digest_emails
 +  defdelegate worker_args(queue), to: Pleroma.Workers.Helper
  
    def perform do
      config = Pleroma.Config.get([:email_notifications, :digest])
index cabea51ca98b7b67a88be061bc7b308dd3ad6575,8578cab5ed847b541d8710ba8e0eddd66069ba44..a01fb4fcb8db6a977bf59b1b1efa6b14ba364fed
@@@ -18,9 -16,7 +18,9 @@@ defmodule Pleroma.ScheduledActivityWork
  
    @schedule_interval :timer.minutes(1)
  
-   def start_link do
 +  defdelegate worker_args(queue), to: Pleroma.Workers.Helper
 +
+   def start_link(_) do
      GenServer.start_link(__MODULE__, nil)
    end
  
Simple merge
Simple merge
index c0c9c3653827f8036155d79de331bb4b2840e932,f50098302649b25873792a0dc885876c120951c7..943e732891be94e6a3535a426fbcd7c28670bb17
@@@ -6,30 -6,23 +6,27 @@@ defmodule Pleroma.Web.OAuth.Token.Clean
    @moduledoc """
    The module represents functions to clean an expired oauth tokens.
    """
+   use GenServer
+   @ten_seconds 10_000
+   @one_day 86_400_000
  
-   # 10 seconds
-   @start_interval 10_000
    @interval Pleroma.Config.get(
-               # 24 hours
                [:oauth2, :clean_expired_tokens_interval],
-               86_400_000
+               @one_day
              )
  
 +  alias Pleroma.Repo
    alias Pleroma.Web.OAuth.Token
 +  alias Pleroma.Workers.BackgroundWorker
 +
 +  defdelegate worker_args(queue), to: Pleroma.Workers.Helper
  
-   def start_link, do: GenServer.start_link(__MODULE__, nil)
+   def start_link(_), do: GenServer.start_link(__MODULE__, %{})
  
    def init(_) do
-     if Pleroma.Config.get([:oauth2, :clean_expired_tokens], false) do
-       Process.send_after(self(), :perform, @start_interval)
-       {:ok, nil}
-     else
-       :ignore
-     end
+     Process.send_after(self(), :perform, @ten_seconds)
+     {:ok, nil}
    end
  
    @doc false
@@@ -41,7 -32,4 +38,6 @@@
      Process.send_after(self(), :perform, @interval)
      {:noreply, state}
    end
-   # Job Worker Callbacks
 +
 +  def perform(:clean), do: Token.delete_expired_tokens()
  end
Simple merge
Simple merge
index 2b955ced0c73a9994921fe811a4c95c185fef483,b70133a94f5b746c1bfd1cce4c0839e34d7b3e87..3185cc1fb22b3f2a0717a0992ca2625c54053335
@@@ -13,9 -12,9 +13,10 @@@ defmodule Pleroma.UserTest d
    alias Pleroma.Web.CommonAPI
  
    use Pleroma.DataCase
 +  use Oban.Testing, repo: Pleroma.Repo
  
 -  import Pleroma.Factory
+   import Mock
 +  import Pleroma.Factory
  
    setup_all do
      Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
        refute Activity.get_by_id(activity.id)
      end
  
 -      assert {:ok, _} = User.delete(user)
+     test "it deletes deactivated user" do
+       {:ok, user} = insert(:user, info: %{deactivated: true}) |> User.set_cache()
++      {:ok, job} = User.delete(user)
++      {:ok, _user} = ObanHelpers.perform(job)
++
+       refute User.get_by_id(user.id)
+     end
      test "it deletes a user, all follow relationships and all activities", %{user: user} do
        follower = insert(:user)
        {:ok, follower} = User.follow(follower, user)
        {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
        {:ok, _} = User.follow(follower, user)
  
 -      {:ok, _user} = User.delete(user)
 -
 -      assert called(
 -               Pleroma.Web.ActivityPub.Publisher.publish_one(%{
 -                 inbox: "http://mastodon.example.org/inbox"
 -               })
 +      {:ok, job} = User.delete(user)
 +      {:ok, _user} = ObanHelpers.perform(job)
 +
 +      assert ObanHelpers.member?(
 +               %{
 +                 "op" => "publish_one",
 +                 "params" => %{
 +                   "inbox" => "http://mastodon.example.org/inbox",
 +                   "id" => "pleroma:fakeid"
 +                 }
 +               },
 +               all_enqueued(worker: Pleroma.Workers.Publisher)
               )
-       Pleroma.Config.put(config_path, initial_setting)
      end
    end
  
index d723f331f1f4f121b4c3f82adadb2d7408ddb835,f20cd28401f63d2ab2eac77eb9c7363ba5fef3ef..1515f4eb6a677d62602e673693e8b8266c758803
@@@ -538,6 -538,29 +538,29 @@@ defmodule Pleroma.Web.ActivityPub.Activ
      assert Enum.member?(activities, activity_one)
    end
  
 -    {:ok, activity_two} = CommonAPI.add_mute(user, activity_two)
+   test "doesn't return thread muted activities" do
+     user = insert(:user)
+     _activity_one = insert(:note_activity)
+     note_two = insert(:note, data: %{"context" => "suya.."})
+     activity_two = insert(:note_activity, note: note_two)
+     {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
+     assert [_activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
+   end
+   test "returns thread muted activities when with_muted is set" do
+     user = insert(:user)
+     _activity_one = insert(:note_activity)
+     note_two = insert(:note, data: %{"context" => "suya.."})
+     activity_two = insert(:note_activity, note: note_two)
++    {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
+     assert [_activity_two, _activity_one] =
+              ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+   end
    test "does include announces on request" do
      activity_three = insert(:note_activity)
      user = insert(:user)
index 0000000000000000000000000000000000000000,15002330fda040e395558f65aefd4ddec3f6d2f4..5dfd920fa8066d33d5cec9935d2f5e1ed45f32ef
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,31 +1,35 @@@
+ # Pleroma: A lightweight social networking server
+ # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+ # SPDX-License-Identifier: AGPL-3.0-only
+ defmodule Pleroma.DigestEmailWorkerTest do
+   use Pleroma.DataCase
+   import Pleroma.Factory
+   alias Pleroma.DigestEmailWorker
++  alias Pleroma.Tests.ObanHelpers
+   alias Pleroma.User
+   alias Pleroma.Web.CommonAPI
+   test "it sends digest emails" do
+     user = insert(:user)
+     date =
+       Timex.now()
+       |> Timex.shift(days: -10)
+       |> Timex.to_naive_datetime()
+     user2 = insert(:user, last_digest_emailed_at: date)
+     User.switch_email_notifications(user2, "digest", true)
+     CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+     DigestEmailWorker.perform()
++    ObanHelpers.perform_all()
++    # Performing job(s) enqueued at previous step
++    ObanHelpers.perform_all()
+     assert_received {:email, email}
+     assert email.to == [{user2.name, user2.email}]
+     assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
+   end
+ end
index 9ca341b6da988d710bde2325b54d1e641f999a42,09e54533fa1b25c6d42ff94a75121771be8a0bbb..5724672fdcc6933989b7723a1394b003bfe532d6
@@@ -21,12 -16,23 +21,14 @@@ defmodule Pleroma.Web.FederatorTest d
      :ok
    end
  
 -  describe "Publisher.perform" do
 -    test "call `perform` with unknown task" do
 -      assert {
 -               :error,
 -               "Don't know what to do with this"
 -             } = Pleroma.Web.Federator.Publisher.perform("test", :ok, :ok)
 -    end
 -  end
 -
+   clear_config_all([:instance, :federating]) do
+     Pleroma.Config.put([:instance, :federating], true)
+   end
+   clear_config([:instance, :allow_relay])
+   clear_config([:instance, :rewrite_policy])
+   clear_config([:mrf_keyword])
    describe "Publish an activity" do
      setup do
        user = insert(:user)
          File.read!("test/fixtures/mastodon-post-activity.json")
          |> Poison.decode!()
  
 -      assert Federator.incoming_ap_doc(params) == :error
 +      assert {:ok, job} = Federator.incoming_ap_doc(params)
 +      assert :error = ObanHelpers.perform(job)
-       Pleroma.Config.put([:instance, :rewrite_policy], policies)
-       Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
      end
    end
  end
Simple merge