# 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]},
+ # 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])
@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
@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
Process.send_after(self(), :perform, @interval)
{:noreply, state}
end
- # Job Worker Callbacks
+
+ def perform(:clean), do: Token.delete_expired_tokens()
end
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
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)
--- /dev/null
+ # 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
: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