summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/pleroma.ex2
-rw-r--r--lib/mix/tasks/pleroma/instance.ex2
-rw-r--r--lib/pleroma/activity.ex11
-rw-r--r--lib/pleroma/activity/search.ex5
-rw-r--r--lib/pleroma/config/holder.ex19
-rw-r--r--lib/pleroma/config/release_runtime_provider.ex50
-rw-r--r--lib/pleroma/emails/admin_email.ex3
-rw-r--r--lib/pleroma/user.ex12
-rw-r--r--lib/pleroma/user/search.ex8
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex35
-rw-r--r--lib/pleroma/web/activity_pub/utils.ex44
11 files changed, 148 insertions, 43 deletions
diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex
index 49ba2aae4..3de11efce 100644
--- a/lib/mix/pleroma.ex
+++ b/lib/mix/pleroma.ex
@@ -14,7 +14,7 @@ defmodule Mix.Pleroma do
:swoosh,
:timex
]
- @cachex_children ["object", "user", "scrubber"]
+ @cachex_children ["object", "user", "scrubber", "web_resp"]
@doc "Common functions to be reused in mix tasks"
def start_pleroma do
Pleroma.Config.Holder.save_default()
diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex
index fc21ae062..ac8688424 100644
--- a/lib/mix/tasks/pleroma/instance.ex
+++ b/lib/mix/tasks/pleroma/instance.ex
@@ -284,7 +284,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
defp upload_filters(filters) when is_map(filters) do
enabled_filters =
if filters.strip do
- [Pleroma.Upload.Filter.ExifTool]
+ [Pleroma.Upload.Filter.Exiftool]
else
[]
end
diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
index 17af04257..1dc777e3b 100644
--- a/lib/pleroma/activity.ex
+++ b/lib/pleroma/activity.ex
@@ -343,4 +343,15 @@ defmodule Pleroma.Activity do
actor = user_actor(activity)
activity.id in actor.pinned_activities
end
+
+ @spec get_by_object_ap_id_with_object(String.t()) :: t() | nil
+ def get_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) do
+ ap_id
+ |> Queries.by_object_id()
+ |> with_preloaded_object()
+ |> first()
+ |> Repo.one()
+ end
+
+ def get_by_object_ap_id_with_object(_), do: nil
end
diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex
index ceb365bb3..382c81118 100644
--- a/lib/pleroma/activity/search.ex
+++ b/lib/pleroma/activity/search.ex
@@ -27,7 +27,10 @@ defmodule Pleroma.Activity.Search do
|> maybe_restrict_local(user)
|> maybe_restrict_author(author)
|> maybe_restrict_blocked(user)
- |> Pagination.fetch_paginated(%{"offset" => offset, "limit" => limit}, :offset)
+ |> Pagination.fetch_paginated(
+ %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum},
+ :offset
+ )
|> maybe_fetch(user, search_query)
end
diff --git a/lib/pleroma/config/holder.ex b/lib/pleroma/config/holder.ex
index f037d5d48..a99fc0471 100644
--- a/lib/pleroma/config/holder.ex
+++ b/lib/pleroma/config/holder.ex
@@ -9,12 +9,7 @@ defmodule Pleroma.Config.Holder do
def save_default do
default_config =
if System.get_env("RELEASE_NAME") do
- release_config =
- [:code.root_dir(), "releases", System.get_env("RELEASE_VSN"), "releases.exs"]
- |> Path.join()
- |> Pleroma.Config.Loader.read()
-
- Pleroma.Config.Loader.merge(@config, release_config)
+ Pleroma.Config.Loader.merge(@config, release_defaults())
else
@config
end
@@ -32,4 +27,16 @@ defmodule Pleroma.Config.Holder do
def default_config(group, key), do: get_in(get_default(), [group, key])
defp get_default, do: Pleroma.Config.get(:default_config)
+
+ @spec release_defaults() :: keyword()
+ def release_defaults do
+ [
+ pleroma: [
+ {:instance, [static_dir: "/var/lib/pleroma/static"]},
+ {Pleroma.Uploaders.Local, [uploads: "/var/lib/pleroma/uploads"]},
+ {:modules, [runtime_dir: "/var/lib/pleroma/modules"]},
+ {:release, true}
+ ]
+ ]
+ end
end
diff --git a/lib/pleroma/config/release_runtime_provider.ex b/lib/pleroma/config/release_runtime_provider.ex
new file mode 100644
index 000000000..8227195dc
--- /dev/null
+++ b/lib/pleroma/config/release_runtime_provider.ex
@@ -0,0 +1,50 @@
+defmodule Pleroma.Config.ReleaseRuntimeProvider do
+ @moduledoc """
+ Imports `runtime.exs` and `{env}.exported_from_db.secret.exs` for elixir releases.
+ """
+ @behaviour Config.Provider
+
+ @impl true
+ def init(opts), do: opts
+
+ @impl true
+ def load(config, _opts) do
+ with_defaults = Config.Reader.merge(config, Pleroma.Config.Holder.release_defaults())
+
+ config_path = System.get_env("PLEROMA_CONFIG_PATH") || "/etc/pleroma/config.exs"
+
+ with_runtime_config =
+ if File.exists?(config_path) do
+ runtime_config = Config.Reader.read!(config_path)
+
+ with_defaults
+ |> Config.Reader.merge(pleroma: [config_path: config_path])
+ |> Config.Reader.merge(runtime_config)
+ else
+ warning = [
+ IO.ANSI.red(),
+ IO.ANSI.bright(),
+ "!!! #{config_path} not found! Please ensure it exists and that PLEROMA_CONFIG_PATH is unset or points to an existing file",
+ IO.ANSI.reset()
+ ]
+
+ IO.puts(warning)
+ with_defaults
+ end
+
+ exported_config_path =
+ config_path
+ |> Path.dirname()
+ |> Path.join("prod.exported_from_db.secret.exs")
+
+ with_exported =
+ if File.exists?(exported_config_path) do
+ exported_config = Config.Reader.read!(with_runtime_config)
+ Config.Reader.merge(with_runtime_config, exported_config)
+ else
+ with_runtime_config
+ end
+
+ with_exported
+ end
+end
diff --git a/lib/pleroma/emails/admin_email.ex b/lib/pleroma/emails/admin_email.ex
index 8979db2f8..423c294cb 100644
--- a/lib/pleroma/emails/admin_email.ex
+++ b/lib/pleroma/emails/admin_email.ex
@@ -52,6 +52,9 @@ defmodule Pleroma.Emails.AdminEmail do
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id)
"<li><a href=\"#{status_url}\">#{status_url}</li>"
+ %{"id" => id} when is_binary(id) ->
+ "<li><a href=\"#{id}\">#{id}</li>"
+
id when is_binary(id) ->
"<li><a href=\"#{id}\">#{id}</li>"
end)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index b56a5dfe2..0545b7445 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -462,6 +462,18 @@ defmodule Pleroma.User do
|> validate_length(:bio, max: bio_limit)
|> validate_length(:name, max: name_limit)
|> validate_fields(true)
+ |> validate_non_local()
+ end
+
+ defp validate_non_local(cng) do
+ local? = get_field(cng, :local)
+
+ if local? do
+ cng
+ |> add_error(:local, "User is local, can't update with this changeset.")
+ else
+ cng
+ end
end
def update_changeset(struct, params \\ %{}) do
diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex
index 35a828008..b54111090 100644
--- a/lib/pleroma/user/search.ex
+++ b/lib/pleroma/user/search.ex
@@ -85,7 +85,7 @@ defmodule Pleroma.User.Search do
|> base_query(following)
|> filter_blocked_user(for_user)
|> filter_invisible_users()
- |> filter_discoverable_users()
+ |> filter_non_discoverable_users()
|> filter_internal_users()
|> filter_blocked_domains(for_user)
|> fts_search(query_string)
@@ -163,8 +163,10 @@ defmodule Pleroma.User.Search do
from(q in query, where: q.invisible == false)
end
- defp filter_discoverable_users(query) do
- from(q in query, where: q.discoverable == true)
+ defp filter_non_discoverable_users(query) do
+ # Note: commented out — can't do it with users being non-discoverable by default
+ # from(q in query, where: q.is_discoverable == true)
+ query
end
defp filter_internal_users(query) do
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 3543f7f73..99c729473 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -332,15 +332,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
@spec flag(map()) :: {:ok, Activity.t()} | {:error, any()}
- def flag(
- %{
- actor: actor,
- context: _context,
- account: account,
- statuses: statuses,
- content: content
- } = params
- ) do
+ def flag(params) do
+ with {:ok, result} <- Repo.transaction(fn -> do_flag(params) end) do
+ result
+ end
+ end
+
+ defp do_flag(
+ %{
+ actor: actor,
+ context: _context,
+ account: account,
+ statuses: statuses,
+ content: content
+ } = params
+ ) do
# only accept false as false value
local = !(params[:local] == false)
forward = !(params[:forward] == false)
@@ -358,7 +364,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
{:ok, activity} <- insert(flag_data, local),
{:ok, stripped_activity} <- strip_report_status_data(activity),
_ <- notify_and_stream(activity),
- :ok <- maybe_federate(stripped_activity) do
+ :ok <-
+ maybe_federate(stripped_activity) do
User.all_superusers()
|> Enum.filter(fn user -> not is_nil(user.email) end)
|> Enum.each(fn superuser ->
@@ -368,6 +375,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end)
{:ok, activity}
+ else
+ {:error, error} -> Repo.rollback(error)
end
end
@@ -791,10 +800,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
where:
fragment(
"""
- ?->>'type' != 'Create' -- This isn't a Create
+ ?->>'type' != 'Create' -- This isn't a Create
OR ?->>'inReplyTo' is null -- this isn't a reply
- OR ? && array_remove(?, ?) -- The recipient is us or one of our friends,
- -- unless they are the author (because authors
+ OR ? && array_remove(?, ?) -- The recipient is us or one of our friends,
+ -- unless they are the author (because authors
-- are also part of the recipients). This leads
-- to a bug that self-replies by friends won't
-- show up.
diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex
index 713b0ca1f..d580c02a9 100644
--- a/lib/pleroma/web/activity_pub/utils.ex
+++ b/lib/pleroma/web/activity_pub/utils.ex
@@ -701,14 +701,30 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def make_flag_data(_, _), do: %{}
- defp build_flag_object(%{account: account, statuses: statuses} = _) do
- [account.ap_id] ++ build_flag_object(%{statuses: statuses})
+ defp build_flag_object(%{account: account, statuses: statuses}) do
+ [account.ap_id | build_flag_object(%{statuses: statuses})]
end
defp build_flag_object(%{statuses: statuses}) do
Enum.map(statuses || [], &build_flag_object/1)
end
+ defp build_flag_object(%Activity{data: %{"id" => id}, object: %{data: data}}) do
+ activity_actor = User.get_by_ap_id(data["actor"])
+
+ %{
+ "type" => "Note",
+ "id" => id,
+ "content" => data["content"],
+ "published" => data["published"],
+ "actor" =>
+ AccountView.render(
+ "show.json",
+ %{user: activity_actor, skip_visibility_check: true}
+ )
+ }
+ end
+
defp build_flag_object(act) when is_map(act) or is_binary(act) do
id =
case act do
@@ -719,22 +735,14 @@ defmodule Pleroma.Web.ActivityPub.Utils do
case Activity.get_by_ap_id_with_object(id) do
%Activity{} = activity ->
- activity_actor = User.get_by_ap_id(activity.object.data["actor"])
-
- %{
- "type" => "Note",
- "id" => activity.data["id"],
- "content" => activity.object.data["content"],
- "published" => activity.object.data["published"],
- "actor" =>
- AccountView.render(
- "show.json",
- %{user: activity_actor, skip_visibility_check: true}
- )
- }
-
- _ ->
- %{"id" => id, "deleted" => true}
+ build_flag_object(activity)
+
+ nil ->
+ if activity = Activity.get_by_object_ap_id_with_object(id) do
+ build_flag_object(activity)
+ else
+ %{"id" => id, "deleted" => true}
+ end
end
end