Merge branch 'dialyzer-fixes' into 'develop'
More dialyzer fixes See merge request pleroma/pleroma!4042
This commit is contained in:
commit
626c22961f
|
@ -0,0 +1 @@
|
||||||
|
Federated timeline removal of hashtags via MRF HashtagPolicy
|
|
@ -911,6 +911,8 @@
|
||||||
max_restarts: 3,
|
max_restarts: 3,
|
||||||
streamer_registry: true
|
streamer_registry: true
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Uploaders.Uploader, timeout: 30_000
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
|
@ -170,6 +170,10 @@
|
||||||
streamer_registry: false,
|
streamer_registry: false,
|
||||||
test_http_pools: true
|
test_http_pools: true
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Uploaders.Uploader, timeout: 1_000
|
||||||
|
|
||||||
|
config :pleroma, Pleroma.Emoji.Loader, test_emoji: true
|
||||||
|
|
||||||
if File.exists?("./config/test.secret.exs") do
|
if File.exists?("./config/test.secret.exs") do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
else
|
else
|
||||||
|
|
|
@ -23,19 +23,21 @@ defmodule Pleroma.Announcement do
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
end
|
end
|
||||||
|
|
||||||
def change(struct, params \\ %{}) do
|
@doc "Generates changeset for %Pleroma.Announcement{}"
|
||||||
struct
|
@spec changeset(%__MODULE__{}, map()) :: %Ecto.Changeset{}
|
||||||
|> cast(validate_params(struct, params), [:data, :starts_at, :ends_at, :rendered])
|
def changeset(announcement \\ %__MODULE__{}, params \\ %{data: %{}}) do
|
||||||
|
announcement
|
||||||
|
|> cast(validate_params(announcement, params), [:data, :starts_at, :ends_at, :rendered])
|
||||||
|> validate_required([:data])
|
|> validate_required([:data])
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_params(struct, params) do
|
defp validate_params(announcement, params) do
|
||||||
base_data =
|
base_data =
|
||||||
%{
|
%{
|
||||||
"content" => "",
|
"content" => "",
|
||||||
"all_day" => false
|
"all_day" => false
|
||||||
}
|
}
|
||||||
|> Map.merge((struct && struct.data) || %{})
|
|> Map.merge((announcement && announcement.data) || %{})
|
||||||
|
|
||||||
merged_data =
|
merged_data =
|
||||||
Map.merge(base_data, params.data)
|
Map.merge(base_data, params.data)
|
||||||
|
@ -61,13 +63,13 @@ def add_rendered_properties(params) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(params) do
|
def add(params) do
|
||||||
changeset = change(%__MODULE__{}, params)
|
changeset = changeset(%__MODULE__{}, params)
|
||||||
|
|
||||||
Repo.insert(changeset)
|
Repo.insert(changeset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(announcement, params) do
|
def update(announcement, params) do
|
||||||
changeset = change(announcement, params)
|
changeset = changeset(announcement, params)
|
||||||
|
|
||||||
Repo.update(changeset)
|
Repo.update(changeset)
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,6 +12,8 @@ defmodule Pleroma.DataMigration do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "data_migrations" do
|
schema "data_migrations" do
|
||||||
field(:name, :string)
|
field(:name, :string)
|
||||||
field(:state, State, default: :pending)
|
field(:state, State, default: :pending)
|
||||||
|
|
|
@ -15,8 +15,6 @@ defmodule Pleroma.Emoji.Loader do
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@mix_env Mix.env()
|
|
||||||
|
|
||||||
@type pattern :: Regex.t() | module() | String.t()
|
@type pattern :: Regex.t() | module() | String.t()
|
||||||
@type patterns :: pattern() | [pattern()]
|
@type patterns :: pattern() | [pattern()]
|
||||||
@type group_patterns :: keyword(patterns())
|
@type group_patterns :: keyword(patterns())
|
||||||
|
@ -79,7 +77,7 @@ def load do
|
||||||
|
|
||||||
# for testing emoji.txt entries we do not want exposed in normal operation
|
# for testing emoji.txt entries we do not want exposed in normal operation
|
||||||
test_emoji =
|
test_emoji =
|
||||||
if @mix_env == :test do
|
if Application.get_env(:pleroma, __MODULE__)[:test_emoji] do
|
||||||
load_from_file("test/config/emoji.txt", emoji_groups)
|
load_from_file("test/config/emoji.txt", emoji_groups)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -21,7 +21,7 @@ def init(_opts) do
|
||||||
def start_worker(opts, retry \\ false) do
|
def start_worker(opts, retry \\ false) do
|
||||||
case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do
|
case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do
|
||||||
{:error, :max_children} ->
|
{:error, :max_children} ->
|
||||||
if retry or free_pool() == :error do
|
if Enum.any?([retry, free_pool()], &match?(&1, :error)) do
|
||||||
:telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
|
:telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
|
||||||
{:error, :pool_full}
|
{:error, :pool_full}
|
||||||
else
|
else
|
||||||
|
|
|
@ -15,8 +15,8 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@type proxy ::
|
@type proxy ::
|
||||||
{Connection.host(), pos_integer()}
|
{host(), pos_integer()}
|
||||||
| {Connection.proxy_type(), Connection.host(), pos_integer()}
|
| {proxy_type(), host(), pos_integer()}
|
||||||
|
|
||||||
@callback options(keyword(), URI.t()) :: keyword()
|
@callback options(keyword(), URI.t()) :: keyword()
|
||||||
|
|
||||||
|
|
|
@ -188,10 +188,11 @@ defp update_status(status, message \\ nil) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp fault_rate do
|
defp fault_rate do
|
||||||
with failures_count when is_integer(failures_count) <- failures_count() do
|
with failures_count when is_integer(failures_count) <- failures_count(),
|
||||||
|
true <- failures_count > 0 do
|
||||||
failures_count / Enum.max([get_stat(:affected_count, 0), 1])
|
failures_count / Enum.max([get_stat(:affected_count, 0), 1])
|
||||||
else
|
else
|
||||||
_ -> :error
|
_ -> 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
defmodule Pleroma.Uploaders.Uploader do
|
defmodule Pleroma.Uploaders.Uploader do
|
||||||
import Pleroma.Web.Gettext
|
import Pleroma.Web.Gettext
|
||||||
|
|
||||||
@mix_env Mix.env()
|
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Defines the contract to put and get an uploaded file to any backend.
|
Defines the contract to put and get an uploaded file to any backend.
|
||||||
"""
|
"""
|
||||||
|
@ -75,10 +73,5 @@ defp handle_callback(uploader, upload) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp callback_timeout do
|
defp callback_timeout, do: Application.get_env(:pleroma, __MODULE__)[:timeout]
|
||||||
case @mix_env do
|
|
||||||
:test -> 1_000
|
|
||||||
_ -> 30_000
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,8 @@ defmodule Pleroma.User.Backup do
|
||||||
alias Pleroma.Web.ActivityPub.UserView
|
alias Pleroma.Web.ActivityPub.UserView
|
||||||
alias Pleroma.Workers.BackupWorker
|
alias Pleroma.Workers.BackupWorker
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "backups" do
|
schema "backups" do
|
||||||
field(:content_type, :string)
|
field(:content_type, :string)
|
||||||
field(:file_name, :string)
|
field(:file_name, :string)
|
||||||
|
@ -195,6 +197,7 @@ defp wait_backup(backup, current_processed, task) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@files ['actor.json', 'outbox.json', 'likes.json', 'bookmarks.json']
|
@files ['actor.json', 'outbox.json', 'likes.json', 'bookmarks.json']
|
||||||
|
@spec export(Pleroma.User.Backup.t(), pid()) :: {:ok, String.t()} | :error
|
||||||
def export(%__MODULE__{} = backup, caller_pid) do
|
def export(%__MODULE__{} = backup, caller_pid) do
|
||||||
backup = Repo.preload(backup, :user)
|
backup = Repo.preload(backup, :user)
|
||||||
dir = backup_tempdir(backup)
|
dir = backup_tempdir(backup)
|
||||||
|
@ -204,9 +207,11 @@ def export(%__MODULE__{} = backup, caller_pid) do
|
||||||
:ok <- statuses(dir, backup.user, caller_pid),
|
:ok <- statuses(dir, backup.user, caller_pid),
|
||||||
:ok <- likes(dir, backup.user, caller_pid),
|
:ok <- likes(dir, backup.user, caller_pid),
|
||||||
:ok <- bookmarks(dir, backup.user, caller_pid),
|
:ok <- bookmarks(dir, backup.user, caller_pid),
|
||||||
{:ok, zip_path} <- :zip.create(String.to_charlist(dir <> ".zip"), @files, cwd: dir),
|
{:ok, zip_path} <- :zip.create(backup.file_name, @files, cwd: dir),
|
||||||
{:ok, _} <- File.rm_rf(dir) do
|
{:ok, _} <- File.rm_rf(dir) do
|
||||||
{:ok, to_string(zip_path)}
|
{:ok, zip_path}
|
||||||
|
else
|
||||||
|
_ -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -382,6 +387,8 @@ def do_process(backup, current_pid) do
|
||||||
[:file_size, :processed, :state]
|
[:file_size, :processed, :state]
|
||||||
)
|
)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
else
|
||||||
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,7 +71,7 @@ defmodule Pleroma.User.Query do
|
||||||
@equal_criteria [:email]
|
@equal_criteria [:email]
|
||||||
@contains_criteria [:ap_id, :nickname]
|
@contains_criteria [:ap_id, :nickname]
|
||||||
|
|
||||||
@spec build(Query.t(), criteria()) :: Query.t()
|
@spec build(Ecto.Query.t(), criteria()) :: Ecto.Query.t()
|
||||||
def build(query \\ base_query(), criteria) do
|
def build(query \\ base_query(), criteria) do
|
||||||
prepare_query(query, criteria)
|
prepare_query(query, criteria)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,8 @@ defmodule Pleroma.UserRelationship do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.UserRelationship
|
alias Pleroma.UserRelationship
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
schema "user_relationships" do
|
schema "user_relationships" do
|
||||||
belongs_to(:source, User, type: FlakeId.Ecto.CompatType)
|
belongs_to(:source, User, type: FlakeId.Ecto.CompatType)
|
||||||
belongs_to(:target, User, type: FlakeId.Ecto.CompatType)
|
belongs_to(:target, User, type: FlakeId.Ecto.CompatType)
|
||||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
This module encodes our addressing policies and general shape of our objects.
|
This module encodes our addressing policies and general shape of our objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Emoji
|
alias Pleroma.Emoji
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
|
@ -84,7 +84,7 @@ def filter(%{"type" => type, "object" => object} = message) when type in ["Creat
|
||||||
if hashtags != [] do
|
if hashtags != [] do
|
||||||
with {:ok, message} <- check_reject(message, hashtags),
|
with {:ok, message} <- check_reject(message, hashtags),
|
||||||
{:ok, message} <-
|
{:ok, message} <-
|
||||||
(if "type" == "Create" do
|
(if type == "Create" do
|
||||||
check_ftl_removal(message, hashtags)
|
check_ftl_removal(message, hashtags)
|
||||||
else
|
else
|
||||||
{:ok, message}
|
{:ok, message}
|
||||||
|
|
|
@ -62,7 +62,6 @@ def config_description do
|
||||||
key: :mrf_inline_quote,
|
key: :mrf_inline_quote,
|
||||||
related_policy: "Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy",
|
related_policy: "Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy",
|
||||||
label: "MRF Inline Quote Policy",
|
label: "MRF Inline Quote Policy",
|
||||||
type: :group,
|
|
||||||
description: "Force quote url to appear in post content.",
|
description: "Force quote url to appear in post content.",
|
||||||
children: [
|
children: [
|
||||||
%{
|
%{
|
||||||
|
|
|
@ -10,15 +10,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
|
||||||
@moduledoc "Reject or Word-Replace messages with a keyword or regex"
|
@moduledoc "Reject or Word-Replace messages with a keyword or regex"
|
||||||
|
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
defp string_matches?(string, _) when not is_binary(string) do
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
defp string_matches?(string, pattern) when is_binary(pattern) do
|
defp string_matches?(string, pattern) when is_binary(pattern) do
|
||||||
String.contains?(string, pattern)
|
String.contains?(string, pattern)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp string_matches?(string, pattern) do
|
defp string_matches?(string, %Regex{} = pattern) do
|
||||||
String.match?(string, pattern)
|
String.match?(string, pattern)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -505,7 +505,7 @@ defp activity_is_public(activity) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec unpin(String.t(), User.t()) :: {:ok, User.t()} | {:error, term()}
|
@spec unpin(String.t(), User.t()) :: {:ok, Activity.t()} | {:error, term()}
|
||||||
def unpin(id, user) do
|
def unpin(id, user) do
|
||||||
with %Activity{} = activity <- create_activity_by_id(id),
|
with %Activity{} = activity <- create_activity_by_id(id),
|
||||||
{:ok, unpin_data, _} <- Builder.unpin(user, activity.object),
|
{:ok, unpin_data, _} <- Builder.unpin(user, activity.object),
|
||||||
|
|
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
|
||||||
import Pleroma.Web.Gettext
|
import Pleroma.Web.Gettext
|
||||||
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
|
import Pleroma.Web.Utils.Guards, only: [not_empty_string: 1]
|
||||||
|
|
||||||
|
@type t :: %__MODULE__{}
|
||||||
|
|
||||||
defstruct valid?: true,
|
defstruct valid?: true,
|
||||||
errors: [],
|
errors: [],
|
||||||
user: nil,
|
user: nil,
|
||||||
|
|
|
@ -20,7 +20,6 @@ defmodule Pleroma.Web.Streamer do
|
||||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||||
alias Pleroma.Web.StreamerView
|
alias Pleroma.Web.StreamerView
|
||||||
|
|
||||||
@mix_env Mix.env()
|
|
||||||
@registry Pleroma.Web.StreamerRegistry
|
@registry Pleroma.Web.StreamerRegistry
|
||||||
|
|
||||||
def registry, do: @registry
|
def registry, do: @registry
|
||||||
|
@ -396,25 +395,20 @@ def close_streams_by_oauth_token(oauth_token) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# In test environment, only return true if the registry is started.
|
# In dev/prod the streamer registry is expected to be started, so return true
|
||||||
# In benchmark environment, returns false.
|
# In test it is possible to have the registry started for a test so it will check
|
||||||
# In any other environment, always returns true.
|
# In benchmark it will never find the process alive and return false
|
||||||
cond do
|
def should_env_send? do
|
||||||
@mix_env == :test ->
|
if Application.get_env(:pleroma, Pleroma.Application)[:streamer_registry] do
|
||||||
def should_env_send? do
|
true
|
||||||
case Process.whereis(@registry) do
|
else
|
||||||
nil ->
|
case Process.whereis(@registry) do
|
||||||
false
|
nil ->
|
||||||
|
false
|
||||||
|
|
||||||
pid ->
|
pid ->
|
||||||
Process.alive?(pid)
|
Process.alive?(pid)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
@mix_env == :benchmark ->
|
|
||||||
def should_env_send?, do: false
|
|
||||||
|
|
||||||
true ->
|
|
||||||
def should_env_send?, do: true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
1
mix.exs
1
mix.exs
|
@ -10,6 +10,7 @@ def project do
|
||||||
compilers: Mix.compilers(),
|
compilers: Mix.compilers(),
|
||||||
elixirc_options: [warnings_as_errors: warnings_as_errors()],
|
elixirc_options: [warnings_as_errors: warnings_as_errors()],
|
||||||
xref: [exclude: [:eldap]],
|
xref: [exclude: [:eldap]],
|
||||||
|
dialyzer: [plt_add_apps: [:mix, :eldap]],
|
||||||
start_permanent: Mix.env() == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
aliases: aliases(),
|
aliases: aliases(),
|
||||||
deps: deps(),
|
deps: deps(),
|
||||||
|
|
Loading…
Reference in New Issue