diff --git a/CHANGELOG.md b/CHANGELOG.md
index a71a9dae6..b42b13018 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Added
- Refreshing poll results for remote polls
+- Job queue stats to the healthcheck page
- Admin API: Add ability to require password reset
- Mastodon API: Account entities now include `follow_requests_count` (planned Mastodon 3.x addition)
- Pleroma API: `GET /api/v1/pleroma/accounts/:id/scrobbles` to get a list of recently scrobbled items
@@ -23,6 +24,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Mastodon API: Fix private and direct statuses not being filtered out from the public timeline for an authenticated user (`GET /api/v1/timelines/public`)
+- Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname`
+- Added `:instance, extended_nickname_format` setting to the default config
## [1.1.0] - 2019-??-??
### Security
@@ -74,6 +77,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- ActivityPub: Deactivated user deletion
- ActivityPub: Fix `/users/:nickname/inbox` crashing without an authenticated user
- MRF: fix ability to follow a relay when AntiFollowbotPolicy was enabled
+- Mastodon API: Blocks are now treated consistently between the Streaming API and the Timeline APIs
### Added
- Expiring/ephemeral activites. All activities can have expires_at value set, which controls when they should be deleted automatically.
diff --git a/config/config.exs b/config/config.exs
index 36bea19a0..ddbfb246a 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -279,7 +279,8 @@ config :pleroma, :instance,
max_remote_account_fields: 20,
account_field_name_length: 512,
account_field_value_length: 2048,
- external_user_synchronization: true
+ external_user_synchronization: true,
+ extended_nickname_format: false
config :pleroma, :markup,
# XXX - unfortunately, inline images must be enabled by default right now, because
diff --git a/docs/API/pleroma_api.md b/docs/API/pleroma_api.md
index 3a8ef4e2c..0517bbdd7 100644
--- a/docs/API/pleroma_api.md
+++ b/docs/API/pleroma_api.md
@@ -317,7 +317,8 @@ See [Admin-API](admin_api.md)
"active": 0, # active processes
"idle": 0, # idle processes
"memory_used": 0.00, # Memory used
- "healthy": true # Instance state
+ "healthy": true, # Instance state
+ "job_queue_stats": {} # Job queue stats
}
```
@@ -391,7 +392,7 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
### Update a file in a custom emoji pack
* Method `POST`
* Authentication: required
-* Params:
+* Params:
* if the `action` is `add`, adds an emoji named `shortcode` to the pack `pack_name`,
that means that the emoji file needs to be uploaded with the request
(thus requiring it to be a multipart request) and be named `file`.
@@ -408,7 +409,7 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
### Updates (replaces) pack metadata
* Method `POST`
* Authentication: required
-* Params:
+* Params:
* `new_data`: new metadata to replace the old one
* Response: JSON, updated "metadata" section of the pack and 200 status or 400 if there was a
problem with the new metadata (the error is specified in the "error" part of the response JSON)
@@ -417,7 +418,7 @@ The status posting endpoint takes an additional parameter, `in_reply_to_conversa
### Requests the instance to download the pack from another instance
* Method `POST`
* Authentication: required
-* Params:
+* Params:
* `instance_address`: the address of the instance to download from
* `pack_name`: the pack to download from that instance
* Response: JSON, "ok" and 200 status if the pack was downloaded, or 500 if there were
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index 9e35b02c0..0bf218bc7 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -42,6 +42,7 @@ defmodule Pleroma.Application do
hackney_pool_children() ++
[
Pleroma.Stats,
+ Pleroma.JobQueueMonitor,
{Oban, Pleroma.Config.get(Oban)}
] ++
task_children(@env) ++
diff --git a/lib/pleroma/healthcheck.ex b/lib/pleroma/healthcheck.ex
index 977b78c26..fc2129815 100644
--- a/lib/pleroma/healthcheck.ex
+++ b/lib/pleroma/healthcheck.ex
@@ -14,6 +14,7 @@ defmodule Pleroma.Healthcheck do
active: 0,
idle: 0,
memory_used: 0,
+ job_queue_stats: nil,
healthy: true
@type t :: %__MODULE__{
@@ -21,6 +22,7 @@ defmodule Pleroma.Healthcheck do
active: non_neg_integer(),
idle: non_neg_integer(),
memory_used: number(),
+ job_queue_stats: map(),
healthy: boolean()
}
@@ -30,6 +32,7 @@ defmodule Pleroma.Healthcheck do
memory_used: Float.round(:erlang.memory(:total) / 1024 / 1024, 2)
}
|> assign_db_info()
+ |> assign_job_queue_stats()
|> check_health()
end
@@ -55,6 +58,11 @@ defmodule Pleroma.Healthcheck do
Map.merge(healthcheck, db_info)
end
+ defp assign_job_queue_stats(healthcheck) do
+ stats = Pleroma.JobQueueMonitor.stats()
+ Map.put(healthcheck, :job_queue_stats, stats)
+ end
+
@spec check_health(Healthcheck.t()) :: Healthcheck.t()
def check_health(%{pool_size: pool_size, active: active} = check)
when active >= pool_size do
diff --git a/lib/pleroma/job_queue_monitor.ex b/lib/pleroma/job_queue_monitor.ex
new file mode 100644
index 000000000..3feea8381
--- /dev/null
+++ b/lib/pleroma/job_queue_monitor.ex
@@ -0,0 +1,78 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.JobQueueMonitor do
+ use GenServer
+
+ @initial_state %{workers: %{}, queues: %{}, processed_jobs: 0}
+ @queue %{processed_jobs: 0, success: 0, failure: 0}
+ @operation %{processed_jobs: 0, success: 0, failure: 0}
+
+ def start_link(_) do
+ GenServer.start_link(__MODULE__, @initial_state, name: __MODULE__)
+ end
+
+ @impl true
+ def init(state) do
+ :telemetry.attach("oban-monitor-failure", [:oban, :failure], &handle_event/4, nil)
+ :telemetry.attach("oban-monitor-success", [:oban, :success], &handle_event/4, nil)
+
+ {:ok, state}
+ end
+
+ def stats do
+ GenServer.call(__MODULE__, :stats)
+ end
+
+ def handle_event([:oban, status], %{duration: duration}, meta, _) do
+ GenServer.cast(__MODULE__, {:process_event, status, duration, meta})
+ end
+
+ @impl true
+ def handle_call(:stats, _from, state) do
+ {:reply, state, state}
+ end
+
+ @impl true
+ def handle_cast({:process_event, status, duration, meta}, state) do
+ state =
+ state
+ |> Map.update!(:workers, fn workers ->
+ workers
+ |> Map.put_new(meta.worker, %{})
+ |> Map.update!(meta.worker, &update_worker(&1, status, meta, duration))
+ end)
+ |> Map.update!(:queues, fn workers ->
+ workers
+ |> Map.put_new(meta.queue, @queue)
+ |> Map.update!(meta.queue, &update_queue(&1, status, meta, duration))
+ end)
+ |> Map.update!(:processed_jobs, &(&1 + 1))
+
+ {:noreply, state}
+ end
+
+ defp update_worker(worker, status, meta, duration) do
+ worker
+ |> Map.put_new(meta.args["op"], @operation)
+ |> Map.update!(meta.args["op"], &update_op(&1, status, meta, duration))
+ end
+
+ defp update_op(op, :enqueue, _meta, _duration) do
+ op
+ |> Map.update!(:enqueued, &(&1 + 1))
+ end
+
+ defp update_op(op, status, _meta, _duration) do
+ op
+ |> Map.update!(:processed_jobs, &(&1 + 1))
+ |> Map.update!(status, &(&1 + 1))
+ end
+
+ defp update_queue(queue, status, _meta, _duration) do
+ queue
+ |> Map.update!(:processed_jobs, &(&1 + 1))
+ |> Map.update!(status, &(&1 + 1))
+ end
+end
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 4c1cdd042..c2f8fa0d7 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -583,7 +583,7 @@ defmodule Pleroma.User do
is_integer(nickname_or_id) or FlakeId.flake_id?(nickname_or_id) ->
get_cached_by_id(nickname_or_id) || get_cached_by_nickname(nickname_or_id)
- restrict_to_local == false ->
+ restrict_to_local == false or not String.contains?(nickname_or_id, "@") ->
get_cached_by_nickname(nickname_or_id)
restrict_to_local == :unauthenticated and match?(%User{}, opts[:for]) ->
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index c52efb578..5052d1304 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -17,6 +17,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.User
alias Pleroma.Web.ActivityPub.MRF
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Streamer
alias Pleroma.Web.WebFinger
alias Pleroma.Workers.BackgroundWorker
@@ -291,8 +292,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
- # only accept false as false value
local = !(params[:local] == false)
+ activity_id = params[:activity_id]
with data <- %{
"to" => to,
@@ -301,6 +302,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
"actor" => actor,
"object" => object
},
+ data <- Utils.maybe_put(data, "id", activity_id),
{:ok, activity} <- insert(data, local),
:ok <- maybe_federate(activity) do
{:ok, activity}
diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
index 7cd13b4b8..080030eb5 100644
--- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex
@@ -82,38 +82,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
conn
end
- def object_likes(conn, %{"uuid" => uuid, "page" => page}) do
- with ap_id <- o_status_url(conn, :object, uuid),
- %Object{} = object <- Object.get_cached_by_ap_id(ap_id),
- {_, true} <- {:public?, Visibility.is_public?(object)},
- likes <- Utils.get_object_likes(object) do
- {page, _} = Integer.parse(page)
-
- conn
- |> put_resp_content_type("application/activity+json")
- |> put_view(ObjectView)
- |> render("likes.json", %{ap_id: ap_id, likes: likes, page: page})
- else
- {:public?, false} ->
- {:error, :not_found}
- end
- end
-
- def object_likes(conn, %{"uuid" => uuid}) do
- with ap_id <- o_status_url(conn, :object, uuid),
- %Object{} = object <- Object.get_cached_by_ap_id(ap_id),
- {_, true} <- {:public?, Visibility.is_public?(object)},
- likes <- Utils.get_object_likes(object) do
- conn
- |> put_resp_content_type("application/activity+json")
- |> put_view(ObjectView)
- |> render("likes.json", %{ap_id: ap_id, likes: likes})
- else
- {:public?, false} ->
- {:error, :not_found}
- end
- end
-
def activity(conn, %{"uuid" => uuid}) do
with ap_id <- o_status_url(conn, :activity, uuid),
%Activity{} = activity <- Activity.normalize(ap_id),
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 64c470fc8..c56d2dd11 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -621,7 +621,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
to: data["to"] || [],
cc: data["cc"] || [],
object: object,
- actor: actor_id
+ actor: actor_id,
+ activity_id: data["id"]
})
else
e ->
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 0828591ee..4ef479f96 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -251,16 +251,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Repo.one()
end
- @doc """
- Returns like activities targeting an object
- """
- def get_object_likes(%{data: %{"id" => id}}) do
- id
- |> Activity.Queries.by_object_id()
- |> Activity.Queries.by_type("Like")
- |> Repo.all()
- end
-
@spec make_like_data(User.t(), map(), String.t()) :: map()
def make_like_data(
%User{ap_id: ap_id} = actor,
@@ -461,14 +451,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
"""
def make_unannounce_data(
%User{ap_id: ap_id} = user,
- %Activity{data: %{"context" => context}} = activity,
+ %Activity{data: %{"context" => context, "object" => object}} = activity,
activity_id
) do
+ object = Object.normalize(object)
+
%{
"type" => "Undo",
"actor" => ap_id,
"object" => activity.data,
- "to" => [user.follower_address, activity.data["actor"]],
+ "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()],
"context" => context
}
@@ -477,14 +469,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def make_unlike_data(
%User{ap_id: ap_id} = user,
- %Activity{data: %{"context" => context}} = activity,
+ %Activity{data: %{"context" => context, "object" => object}} = activity,
activity_id
) do
+ object = Object.normalize(object)
+
%{
"type" => "Undo",
"actor" => ap_id,
"object" => activity.data,
- "to" => [user.follower_address, activity.data["actor"]],
+ "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()],
"context" => context
}
@@ -745,6 +739,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|> Repo.all()
end
- defp maybe_put(map, _key, nil), do: map
- defp maybe_put(map, key, value), do: Map.put(map, key, value)
+ def maybe_put(map, _key, nil), do: map
+ def maybe_put(map, key, value), do: Map.put(map, key, value)
end
diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex
index 88c55acdd..d8a3ec288 100644
--- a/lib/pleroma/web/activity_pub/views/object_view.ex
+++ b/lib/pleroma/web/activity_pub/views/object_view.ex
@@ -37,40 +37,4 @@ defmodule Pleroma.Web.ActivityPub.ObjectView do
Map.merge(base, additional)
end
-
- def render("likes.json", %{ap_id: ap_id, likes: likes, page: page}) do
- collection(likes, "#{ap_id}/likes", page)
- |> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header())
- end
-
- def render("likes.json", %{ap_id: ap_id, likes: likes}) do
- %{
- "id" => "#{ap_id}/likes",
- "type" => "OrderedCollection",
- "totalItems" => length(likes),
- "first" => collection(likes, "#{ap_id}/likes", 1)
- }
- |> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header())
- end
-
- def collection(collection, iri, page) do
- offset = (page - 1) * 10
- items = Enum.slice(collection, offset, 10)
- items = Enum.map(items, fn object -> Transmogrifier.prepare_object(object.data) end)
- total = length(collection)
-
- map = %{
- "id" => "#{iri}?page=#{page}",
- "type" => "OrderedCollectionPage",
- "partOf" => iri,
- "totalItems" => total,
- "orderedItems" => items
- }
-
- if offset + length(items) < total do
- Map.put(map, "next", "#{iri}?page=#{page + 1}")
- else
- map
- end
- end
end
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex
index ce73b3270..386408d51 100644
--- a/lib/pleroma/web/common_api/common_api.ex
+++ b/lib/pleroma/web/common_api/common_api.ex
@@ -16,6 +16,8 @@ defmodule Pleroma.Web.CommonAPI do
import Pleroma.Web.Gettext
import Pleroma.Web.CommonAPI.Utils
+ require Pleroma.Constants
+
def follow(follower, followed) do
timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout])
@@ -271,7 +273,7 @@ defmodule Pleroma.Web.CommonAPI do
ActivityPub.update(%{
local: true,
- to: [user.follower_address],
+ to: [Pleroma.Constants.as_public(), user.follower_address],
cc: [],
actor: user.ap_id,
object: Pleroma.Web.ActivityPub.UserView.render("user.json", %{user: user})
diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex
index 60b58dc90..5e3dbe728 100644
--- a/lib/pleroma/web/mastodon_api/views/notification_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex
@@ -25,40 +25,44 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
mastodon_type = Activity.mastodon_notification_type(activity)
- response = %{
- id: to_string(notification.id),
- type: mastodon_type,
- created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
- account: AccountView.render("show.json", %{user: actor, for: user}),
- pleroma: %{
- is_seen: notification.seen
+ with %{id: _} = account <- AccountView.render("show.json", %{user: actor, for: user}) do
+ response = %{
+ id: to_string(notification.id),
+ type: mastodon_type,
+ created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
+ account: account,
+ pleroma: %{
+ is_seen: notification.seen
+ }
}
- }
- case mastodon_type do
- "mention" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: activity, for: user})
- })
+ case mastodon_type do
+ "mention" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: activity, for: user})
+ })
- "favourite" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
+ "favourite" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: parent_activity, for: user})
+ })
- "reblog" ->
- response
- |> Map.merge(%{
- status: StatusView.render("show.json", %{activity: parent_activity, for: user})
- })
+ "reblog" ->
+ response
+ |> Map.merge(%{
+ status: StatusView.render("show.json", %{activity: parent_activity, for: user})
+ })
- "follow" ->
- response
+ "follow" ->
+ response
- _ ->
- nil
+ _ ->
+ nil
+ end
+ else
+ _ -> nil
end
end
end
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index e418dc70d..1cd7294e7 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -460,7 +460,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
# Special case: Local MastodonFE
- defp redirect_uri(%Plug.Conn{} = conn, "."), do: mastodon_api_url(conn, :login)
+ defp redirect_uri(%Plug.Conn{} = conn, "."), do: auth_url(conn, :login)
defp redirect_uri(%Plug.Conn{}, redirect_uri), do: redirect_uri
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index f91af8137..405ae724e 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -580,7 +580,6 @@ defmodule Pleroma.Web.Router do
pipe_through(:ostatus)
get("/users/:nickname/outbox", ActivityPubController, :outbox)
- get("/objects/:uuid/likes", ActivityPubController, :object_likes)
end
pipeline :activitypub_client do
diff --git a/lib/pleroma/web/streamer/ping.ex b/lib/pleroma/web/streamer/ping.ex
index f77cbb95c..db3e68abe 100644
--- a/lib/pleroma/web/streamer/ping.ex
+++ b/lib/pleroma/web/streamer/ping.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Streamer.Ping do
use GenServer
require Logger
diff --git a/lib/pleroma/web/streamer/state.ex b/lib/pleroma/web/streamer/state.ex
index c48752d95..5ce3ebb8a 100644
--- a/lib/pleroma/web/streamer/state.ex
+++ b/lib/pleroma/web/streamer/state.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Streamer.State do
use GenServer
require Logger
diff --git a/lib/pleroma/web/streamer/streamer_socket.ex b/lib/pleroma/web/streamer/streamer_socket.ex
index f006c0306..cf0fa3077 100644
--- a/lib/pleroma/web/streamer/streamer_socket.ex
+++ b/lib/pleroma/web/streamer/streamer_socket.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Streamer.StreamerSocket do
defstruct transport_pid: nil, user: nil
diff --git a/lib/pleroma/web/streamer/supervisor.ex b/lib/pleroma/web/streamer/supervisor.ex
index 6afe19323..ec5985085 100644
--- a/lib/pleroma/web/streamer/supervisor.ex
+++ b/lib/pleroma/web/streamer/supervisor.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Streamer.Supervisor do
use Supervisor
diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex
index 5804508eb..0ea224874 100644
--- a/lib/pleroma/web/streamer/worker.ex
+++ b/lib/pleroma/web/streamer/worker.ex
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.Streamer.Worker do
use GenServer
@@ -128,11 +132,14 @@ defmodule Pleroma.Web.Streamer.Worker do
blocks = user.info.blocks || []
mutes = user.info.mutes || []
reblog_mutes = user.info.muted_reblogs || []
+ recipient_blocks = MapSet.new(blocks ++ mutes)
+ recipients = MapSet.new(item.recipients)
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.info.domain_blocks)
with parent when not is_nil(parent) <- Object.normalize(item),
true <- Enum.all?([blocks, mutes, reblog_mutes], &(item.actor not in &1)),
true <- Enum.all?([blocks, mutes], &(parent.data["actor"] not in &1)),
+ true <- MapSet.disjoint?(recipients, recipient_blocks),
%{host: item_host} <- URI.parse(item.actor),
%{host: parent_host} <- URI.parse(parent.data["actor"]),
false <- Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, item_host),
@@ -194,11 +201,8 @@ defmodule Pleroma.Web.Streamer.Worker do
# Get the current user so we have up-to-date blocks etc.
if socket_user do
user = User.get_cached_by_ap_id(socket_user.ap_id)
- blocks = user.info.blocks || []
- mutes = user.info.mutes || []
- with true <- Enum.all?([blocks, mutes], &(item.actor not in &1)),
- true <- thread_containment(item, user) do
+ if should_send?(user, item) do
send(transport_pid, {:text, StreamerView.render("update.json", item, user)})
end
else
diff --git a/test/healthcheck_test.exs b/test/healthcheck_test.exs
index 6bb8d5b7f..66d5026ff 100644
--- a/test/healthcheck_test.exs
+++ b/test/healthcheck_test.exs
@@ -9,7 +9,14 @@ defmodule Pleroma.HealthcheckTest do
test "system_info/0" do
result = Healthcheck.system_info() |> Map.from_struct()
- assert Map.keys(result) == [:active, :healthy, :idle, :memory_used, :pool_size]
+ assert Map.keys(result) == [
+ :active,
+ :healthy,
+ :idle,
+ :job_queue_stats,
+ :memory_used,
+ :pool_size
+ ]
end
describe "check_health/1" do
diff --git a/test/job_queue_monitor_test.exs b/test/job_queue_monitor_test.exs
new file mode 100644
index 000000000..17c6f3246
--- /dev/null
+++ b/test/job_queue_monitor_test.exs
@@ -0,0 +1,70 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.JobQueueMonitorTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.JobQueueMonitor
+
+ @success {:process_event, :success, 1337,
+ %{
+ args: %{"op" => "refresh_subscriptions"},
+ attempt: 1,
+ id: 339,
+ max_attempts: 5,
+ queue: "federator_outgoing",
+ worker: "Pleroma.Workers.SubscriberWorker"
+ }}
+
+ @failure {:process_event, :failure, 22_521_134,
+ %{
+ args: %{"op" => "force_password_reset", "user_id" => "9nJG6n6Nbu7tj9GJX6"},
+ attempt: 1,
+ error: %RuntimeError{message: "oops"},
+ id: 345,
+ kind: :exception,
+ max_attempts: 1,
+ queue: "background",
+ stack: [
+ {Pleroma.Workers.BackgroundWorker, :perform, 2,
+ [file: 'lib/pleroma/workers/background_worker.ex', line: 31]},
+ {Oban.Queue.Executor, :safe_call, 1,
+ [file: 'lib/oban/queue/executor.ex', line: 42]},
+ {:timer, :tc, 3, [file: 'timer.erl', line: 197]},
+ {Oban.Queue.Executor, :call, 2, [file: 'lib/oban/queue/executor.ex', line: 23]},
+ {Task.Supervised, :invoke_mfa, 2, [file: 'lib/task/supervised.ex', line: 90]},
+ {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
+ ],
+ worker: "Pleroma.Workers.BackgroundWorker"
+ }}
+
+ test "stats/0" do
+ assert %{processed_jobs: _, queues: _, workers: _} = JobQueueMonitor.stats()
+ end
+
+ test "handle_cast/2" do
+ state = %{workers: %{}, queues: %{}, processed_jobs: 0}
+
+ assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
+ assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
+ assert {:noreply, state} = JobQueueMonitor.handle_cast(@success, state)
+ assert {:noreply, state} = JobQueueMonitor.handle_cast(@failure, state)
+
+ assert state == %{
+ processed_jobs: 4,
+ queues: %{
+ "background" => %{failure: 2, processed_jobs: 2, success: 0},
+ "federator_outgoing" => %{failure: 0, processed_jobs: 2, success: 2}
+ },
+ workers: %{
+ "Pleroma.Workers.BackgroundWorker" => %{
+ "force_password_reset" => %{failure: 2, processed_jobs: 2, success: 0}
+ },
+ "Pleroma.Workers.SubscriberWorker" => %{
+ "refresh_subscriptions" => %{failure: 0, processed_jobs: 2, success: 2}
+ }
+ }
+ }
+ end
+end
diff --git a/test/user_test.exs b/test/user_test.exs
index 126bd69e8..1bc853c94 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1725,4 +1725,61 @@ defmodule Pleroma.UserTest do
assert %{info: %{hide_follows: true}} = Repo.get(User, user.id)
assert {:ok, %{info: %{hide_follows: true}}} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
end
+
+ describe "get_cached_by_nickname_or_id" do
+ setup do
+ limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
+ local_user = insert(:user)
+ remote_user = insert(:user, nickname: "nickname@example.com", local: false)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
+ end)
+
+ [local_user: local_user, remote_user: remote_user]
+ end
+
+ test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
+ remote_user: remote_user
+ } do
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
+ end
+
+ test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
+ %{remote_user: remote_user} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
+ end
+
+ test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
+ %{remote_user: remote_user, local_user: local_user} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
+ end
+
+ test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
+ %{remote_user: remote_user} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
+ end
+
+ test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
+ %{local_user: local_user} do
+ Pleroma.Config.put([:instance, :limit_to_local_content], false)
+ assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], true)
+ assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
+
+ Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
+ assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
+ end
+ end
end
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 1ffa91b70..6a3e48b5e 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -225,69 +225,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
end
- describe "/object/:uuid/likes" do
- setup do
- like = insert(:like_activity)
- like_object_ap_id = Object.normalize(like).data["id"]
-
- uuid =
- like_object_ap_id
- |> String.split("/")
- |> List.last()
-
- [id: like.data["id"], uuid: uuid]
- end
-
- test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
- result =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/objects/#{uuid}/likes")
- |> json_response(200)
-
- assert List.first(result["first"]["orderedItems"])["id"] == id
- assert result["type"] == "OrderedCollection"
- assert result["totalItems"] == 1
- refute result["first"]["next"]
- end
-
- test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
- result =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/objects/#{uuid}/likes?page=2")
- |> json_response(200)
-
- assert result["type"] == "OrderedCollectionPage"
- assert result["totalItems"] == 1
- refute result["next"]
- assert Enum.empty?(result["orderedItems"])
- end
-
- test "it contains the next key when likes count is more than 10", %{conn: conn} do
- note = insert(:note_activity)
- insert_list(11, :like_activity, note_activity: note)
-
- uuid =
- note
- |> Object.normalize()
- |> Map.get(:data)
- |> Map.get("id")
- |> String.split("/")
- |> List.last()
-
- result =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/objects/#{uuid}/likes?page=1")
- |> json_response(200)
-
- assert result["totalItems"] == 11
- assert length(result["orderedItems"]) == 10
- assert result["next"]
- end
- end
-
describe "/activities/:uuid" do
test "it returns a json representation of the activity", %{conn: conn} do
activity = insert(:note_activity)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f29497847..c9f2a92e7 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -811,10 +811,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, like_activity, object} = ActivityPub.like(user, object)
assert object.data["like_count"] == 1
- {:ok, _, _, object} = ActivityPub.unlike(user, object)
+ {:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
assert object.data["like_count"] == 0
assert Activity.get_by_id(like_activity.id) == nil
+ assert note_activity.actor in unlike_activity.recipients
end
end
@@ -890,7 +891,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert unannounce_activity.data["to"] == [
User.ap_followers(user),
- announce_activity.data["actor"]
+ object.data["actor"]
]
assert unannounce_activity.data["type"] == "Undo"
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6c208bdc0..475313316 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -546,6 +546,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
+ assert data["id"] == update_data["id"]
+
user = User.get_cached_by_ap_id(data["actor"])
assert user.name == "gargle"
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index b1c1d6f71..c57ea7eb9 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -106,11 +106,13 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
user = insert(:user)
like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"})
+ object = Object.normalize(like_activity.data["object"])
+
assert Utils.make_unlike_data(user, like_activity, nil) == %{
"type" => "Undo",
"actor" => user.ap_id,
"object" => like_activity.data,
- "to" => [user.follower_address, like_activity.data["actor"]],
+ "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()],
"context" => like_activity.data["context"]
}
@@ -119,7 +121,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
"type" => "Undo",
"actor" => user.ap_id,
"object" => like_activity.data,
- "to" => [user.follower_address, like_activity.data["actor"]],
+ "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()],
"context" => like_activity.data["context"],
"id" => "9mJEZK0tky1w2xD2vY"
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 2d3c41e82..83df44c36 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -14,6 +14,8 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ require Pleroma.Constants
+
clear_config([:instance, :safe_dm_mentions])
clear_config([:instance, :limit])
clear_config([:instance, :max_pinned_statuses])
@@ -96,11 +98,13 @@ defmodule Pleroma.Web.CommonAPITest do
test "it adds emoji when updating profiles" do
user = insert(:user, %{name: ":firefox:"})
- CommonAPI.update(user)
+ {:ok, activity} = CommonAPI.update(user)
user = User.get_cached_by_ap_id(user.ap_id)
[firefox] = user.info.source_data["tag"]
assert firefox["name"] == ":firefox:"
+
+ assert Pleroma.Constants.as_public() in activity.recipients
end
describe "posting" do
diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs
index 81ab82e2b..c9043a69a 100644
--- a/test/web/mastodon_api/views/notification_view_test.exs
+++ b/test/web/mastodon_api/views/notification_view_test.exs
@@ -100,5 +100,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
NotificationView.render("index.json", %{notifications: [notification], for: followed})
assert [expected] == result
+
+ User.perform(:delete, follower)
+ notification = Notification |> Repo.one() |> Repo.preload(:activity)
+
+ assert [] ==
+ NotificationView.render("index.json", %{notifications: [notification], for: followed})
end
end
diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs
index b8fcd41fa..d33eb1e42 100644
--- a/test/web/streamer/streamer_test.exs
+++ b/test/web/streamer/streamer_test.exs
@@ -233,30 +233,68 @@ defmodule Pleroma.Web.StreamerTest do
end
end
- test "it doesn't send to blocked users" do
- user = insert(:user)
- blocked_user = insert(:user)
- {:ok, user} = User.block(user, blocked_user)
+ describe "blocks" do
+ test "it doesn't send messages involving blocked users" do
+ user = insert(:user)
+ blocked_user = insert(:user)
+ {:ok, user} = User.block(user, blocked_user)
- task =
- Task.async(fn ->
- refute_receive {:text, _}, 1_000
- end)
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
- fake_socket = %StreamerSocket{
- transport_pid: task.pid,
- user: user
- }
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: user
+ }
- {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
+ {:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
- topics = %{
- "public" => [fake_socket]
- }
+ topics = %{
+ "public" => [fake_socket]
+ }
- Worker.push_to_socket(topics, "public", activity)
+ Worker.push_to_socket(topics, "public", activity)
- Task.await(task)
+ Task.await(task)
+ end
+
+ test "it doesn't send messages transitively involving blocked users" do
+ blocker = insert(:user)
+ blockee = insert(:user)
+ friend = insert(:user)
+
+ task =
+ Task.async(fn ->
+ refute_receive {:text, _}, 1_000
+ end)
+
+ fake_socket = %StreamerSocket{
+ transport_pid: task.pid,
+ user: blocker
+ }
+
+ topics = %{
+ "public" => [fake_socket]
+ }
+
+ {:ok, blocker} = User.block(blocker, blockee)
+
+ {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
+
+ Worker.push_to_socket(topics, "public", activity_one)
+
+ {:ok, activity_two} = CommonAPI.post(blockee, %{"status" => "hey! @#{friend.nickname}"})
+
+ Worker.push_to_socket(topics, "public", activity_two)
+
+ {:ok, activity_three} = CommonAPI.post(blockee, %{"status" => "hey! @#{blocker.nickname}"})
+
+ Worker.push_to_socket(topics, "public", activity_three)
+
+ Task.await(task)
+ end
end
test "it doesn't send unwanted DMs to list" do