Merge branch 'fixes' into 'master'

Remove unused deps and fix some config defined at compile-time instead of runtime

See merge request framasoft/mobilizon!932
This commit is contained in:
Thomas Citharel 2021-06-07 09:37:17 +00:00
commit 46ec43193e
12 changed files with 63 additions and 51 deletions

View file

@ -8,8 +8,6 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
@shortdoc "Clean orphan media"
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
@impl Mix.Task
def run(options) do
{options, [], []} =
@ -26,9 +24,12 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
]
)
default_grace_period =
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
dry_run = Keyword.get(options, :dry_run, false)
grace_period = Keyword.get(options, :days)
grace_period = if is_nil(grace_period), do: @grace_period, else: grace_period * 24
grace_period = if is_nil(grace_period), do: default_grace_period, else: grace_period * 24
verbose = Keyword.get(options, :verbose, false)
start_mobilizon()

View file

@ -8,7 +8,6 @@ defmodule Mix.Tasks.Mobilizon.Users.Clean do
alias Mobilizon.Service.CleanUnconfirmedUsers
@shortdoc "Clean unconfirmed users from Mobilizon"
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
@impl Mix.Task
def run(options) do
@ -26,9 +25,12 @@ defmodule Mix.Tasks.Mobilizon.Users.Clean do
]
)
default_grace_period =
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
dry_run = Keyword.get(options, :dry_run, false)
grace_period = Keyword.get(options, :days)
grace_period = if is_nil(grace_period), do: @grace_period, else: grace_period * 24
grace_period = if is_nil(grace_period), do: default_grace_period, else: grace_period * 24
verbose = Keyword.get(options, :verbose, false)
start_mobilizon()

View file

@ -1740,17 +1740,14 @@ defmodule Mobilizon.Actors do
from(a in query, where: a.preferred_username == ^name and is_nil(a.domain))
end
@own_domain Mobilizon.Config.instance_hostname()
defp filter_by_name(query, [name, @own_domain]) do
filter_by_name(query, [name])
end
defp filter_by_name(query, [name, domain]) do
from(a in query, where: a.preferred_username == ^name and a.domain == ^domain)
if domain == Mobilizon.Config.instance_hostname() do
filter_by_name(query, [name])
else
where(query, [a], a.preferred_username == ^name and a.domain == ^domain)
end
end
@spec filter_by_name(Ecto.Query.t(), boolean | nil) :: Ecto.Query.t()
defp filter_followed_by_approved_status(query, nil), do: query
defp filter_followed_by_approved_status(query, approved) do

View file

@ -9,8 +9,6 @@ defmodule Mobilizon.Service.CleanOrphanMedia do
alias Mobilizon.Storage.Repo
import Ecto.Query
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
@doc """
Clean orphan media
@ -37,7 +35,10 @@ defmodule Mobilizon.Service.CleanOrphanMedia do
@spec find_media(Keyword.t()) :: list(Media.t())
defp find_media(opts) do
grace_period = Keyword.get(opts, :grace_period, @grace_period)
default_grace_period =
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
grace_period = Keyword.get(opts, :grace_period, default_grace_period)
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
Media

View file

@ -9,8 +9,6 @@ defmodule Mobilizon.Service.CleanUnconfirmedUsers do
alias Mobilizon.Users.User
import Ecto.Query
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
@doc """
Clean unattached media
@ -49,7 +47,10 @@ defmodule Mobilizon.Service.CleanUnconfirmedUsers do
@spec find_unconfirmed_users_to_clean(Keyword.t()) :: list(User.t())
defp find_unconfirmed_users_to_clean(opts) do
grace_period = Keyword.get(opts, :grace_period, @grace_period)
default_grace_period =
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
grace_period = Keyword.get(opts, :grace_period, default_grace_period)
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
User

View file

@ -10,8 +10,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
alias Mobilizon.Service.Export.Common
alias Mobilizon.Service.Formatter.HTML
@vendor "Mobilizon #{Config.instance_version()}"
@doc """
Create cache for an actor, an event or an user token
"""
@ -119,7 +117,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
@spec events_to_ics(list(Events.t())) :: String.t()
defp events_to_ics(events) do
%ICalendar{events: events |> Enum.map(&do_export_event/1)}
|> ICalendar.to_ics(vendor: @vendor)
|> ICalendar.to_ics(vendor: vendor())
end
@spec do_export_event(Event.t()) :: ICalendar.Event.t()
@ -137,4 +135,8 @@ defmodule Mobilizon.Service.Export.ICalendar do
categories: event.tags |> Enum.map(& &1.title)
}
end
defp vendor do
"Mobilizon #{Config.instance_version()}"
end
end

View file

@ -6,8 +6,6 @@ defmodule Mobilizon.Service.Workers.CleanOrphanMediaWorker do
use Oban.Worker, queue: "background"
alias Mobilizon.Service.CleanOrphanMedia
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
@impl Oban.Worker
def perform(%Job{}) do
if Mobilizon.Config.get!([:instance, :remove_orphan_uploads]) and should_perform?() do
@ -19,9 +17,12 @@ defmodule Mobilizon.Service.Workers.CleanOrphanMediaWorker do
defp should_perform? do
case Cachex.get(:key_value, "last_media_cleanup") do
{:ok, %DateTime{} = last_media_cleanup} ->
default_grace_period =
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
DateTime.compare(
last_media_cleanup,
DateTime.add(DateTime.utc_now(), @grace_period * -3600)
DateTime.add(DateTime.utc_now(), default_grace_period * -3600)
) == :lt
_ ->

View file

@ -6,8 +6,6 @@ defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
use Oban.Worker, queue: "background"
alias Mobilizon.Service.CleanUnconfirmedUsers
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
@impl Oban.Worker
def perform(%Job{}) do
if Mobilizon.Config.get!([:instance, :remove_unconfirmed_users]) and should_perform?() do
@ -19,9 +17,12 @@ defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
defp should_perform? do
case Cachex.get(:key_value, "last_media_cleanup") do
{:ok, %DateTime{} = last_media_cleanup} ->
default_grace_period =
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
DateTime.compare(
last_media_cleanup,
DateTime.add(DateTime.utc_now(), @grace_period * -3600)
DateTime.add(DateTime.utc_now(), default_grace_period * -3600)
) == :lt
_ ->

View file

@ -107,7 +107,6 @@ defmodule Mobilizon.Mixfile do
{:argon2_elixir, "~> 2.0"},
{:cors_plug, "~> 2.0"},
{:ecto_autoslug_field, "~> 2.0"},
{:rsa_ex, "~> 0.1"},
{:geo, "~> 3.0"},
{:geo_postgis, "~> 3.1"},
{:timex, "~> 3.0"},
@ -115,8 +114,6 @@ defmodule Mobilizon.Mixfile do
{:exgravatar, "~> 2.0.1"},
# {:json_ld, "~> 0.3"},
{:jason, "~> 1.2"},
{:ex_crypto, "~> 0.10.0"},
{:http_sign, "~> 0.1.1"},
{:ecto_enum, "~> 1.4"},
{:ex_ical, "~> 0.2"},
{:bamboo, "~> 2.1"},

View file

@ -41,7 +41,6 @@
"ex_cldr_dates_times": {:hex, :ex_cldr_dates_times, "2.7.2", "04aea75ccc017e006961f9c6413aa203630ec2a3bb03091b5943d0013ff21b61", [:mix], [{:calendar_interval, "~> 0.2", [hex: :calendar_interval, repo: "hexpm", optional: true]}, {:ex_cldr_calendars, "~> 1.13", [hex: :ex_cldr_calendars, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.17", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "ae6bcb69d5e6585b10265eb984d60894e82ff5b91c0ac61ea7d35278a11e9aa0"},
"ex_cldr_languages": {:hex, :ex_cldr_languages, "0.2.2", "d7dab93272443b70e18e6aef0f62974418baaca3a3b31a66d51921ec1547113c", [:mix], [{:ex_cldr, "~> 2.2 and >= 2.2.1", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "d9cbf4bf643365b0042e774520ddfcbc31618efd5a5383fac98f75149961622c"},
"ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.18.0", "58ff26aa7420e6bc3d0e0902c031b409b30cbc924e31efa1df0988f865c7756c", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.21", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.9", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "9663db9c6a3d2bae4d6cf9847aad7f00c48c87a3336629b34d72f70ad753f7cb"},
"ex_crypto": {:hex, :ex_crypto, "0.10.0", "af600a89b784b36613a989da6e998c1b200ff1214c3cfbaf8deca4aa2f0a1739", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm", "ccc7472cfe8a0f4565f97dce7e9280119bf15a5ea51c6535e5b65f00660cde1c"},
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
"ex_ical": {:hex, :ex_ical, "0.2.0", "4b928b554614704016cc0c9ee226eb854da9327a1cc460457621ceacb1ac29a6", [:mix], [{:timex, "~> 3.1", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm", "db76473b2ae0259e6633c6c479a5a4d8603f09497f55c88f9ef4d53d2b75befb"},
"ex_machina": {:hex, :ex_machina, "2.7.0", "b792cc3127fd0680fecdb6299235b4727a4944a09ff0fa904cc639272cd92dc7", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "419aa7a39bde11894c87a615c4ecaa52d8f107bbdd81d810465186f783245bf8"},
@ -69,7 +68,6 @@
"guardian_phoenix": {:hex, :guardian_phoenix, "2.0.1", "89a817265af09a6ddf7cb1e77f17ffca90cea2db10ff888375ef34502b2731b1", [:mix], [{:guardian, "~> 2.0", [hex: :guardian, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "21f439246715192b231f228680465d1ed5fbdf01555a4a3b17165532f5f9a08c"},
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
"http_sign": {:hex, :http_sign, "0.1.1", "b16edb83aa282892f3271f9a048c155e772bf36e15700ab93901484c55f8dd10", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "2d4b1c2579d85534035f12c9e1260abdf6d03a9ad4f515b2ee53b50e68c8b787"},
"http_signatures": {:hex, :http_signatures, "0.1.0", "4e4b501a936dbf4cb5222597038a89ea10781776770d2e185849fa829686b34c", [:mix], [], "hexpm", "f8a7b3731e3fd17d38fa6e343fcad7b03d6874a3b0a108c8568a71ed9c2cf824"},
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
"hut": {:hex, :hut, "1.3.0", "71f2f054e657c03f959cf1acc43f436ea87580696528ca2a55c8afb1b06c85e7", [:"erlang.mk", :rebar, :rebar3], [], "hexpm", "7e15d28555d8a1f2b5a3a931ec120af0753e4853a4c66053db354f35bf9ab563"},
@ -115,7 +113,6 @@
"progress_bar": {:hex, :progress_bar, "2.0.1", "7b40200112ae533d5adceb80ff75fbe66dc753bca5f6c55c073bfc122d71896d", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "2519eb58a2f149a3a094e729378256d8cb6d96a259ec94841bd69fdc71f18f87"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"remote_ip": {:hex, :remote_ip, "1.0.0", "3d7fb45204a5704443f480cee9515e464997f52c35e0a60b6ece1f81484067ae", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9e9fcad4e50c43b5234bb6a9629ed6ab223f3ed07147bd35470e4ee5c8caf907"},
"rsa_ex": {:hex, :rsa_ex, "0.4.0", "e28dd7dc5236e156df434af0e4aa822384c8866c928e17b785d4edb7c253b558", [:mix], [], "hexpm", "40e1f08e8401da4be59a6dd0f4da30c42d5bb01703161f0208d839d97db27f4e"},
"sentry": {:hex, :sentry, "8.0.5", "5ca922b9238a50c7258b52f47364b2d545beda5e436c7a43965b34577f1ef61f", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, "~> 2.3", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "4972839fdbf52e886d7b3e694c8adf421f764f2fa79036b88fb4742049bd4b7c"},
"shortuuid": {:hex, :shortuuid, "2.1.2", "14dbafdb2f6c7213fdfcc05c7572384b5051a7b1621170018ad4c05504bd96c1", [:mix], [], "hexpm", "d9b0c4f37500ea5199b6275ece872e213e9f45a015caf4aa777cec84f63ad353"},
"sitemapper": {:hex, :sitemapper, "0.5.0", "23b0bb7b3888f03d4e4e5bedb7034e6d2979e169366372d960d6f433112b9bdf", [:mix], [{:ex_aws_s3, "~> 2.0", [hex: :ex_aws_s3, repo: "hexpm", optional: true]}, {:xml_builder, "~> 2.1.1", [hex: :xml_builder, repo: "hexpm", optional: false]}], "hexpm", "be7acff8d0245aa7ca125b9c4d0751009bbbca26ef866d888fef4fdf98670e41"},

View file

@ -40,7 +40,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
File.read!("test/fixtures/mastodon-post-activity.json")
|> Jason.decode!()
reply_to_url = "https://soc.punktrash.club/objects/d811df79-6e54-4f51-841e-0c38bc356467"
reply_to_url = "https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
object =
data["object"]
@ -65,11 +65,11 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.CommentsTest do
%Comment{} =
origin_comment =
Discussions.get_comment_from_url(
"https://soc.punktrash.club/objects/d811df79-6e54-4f51-841e-0c38bc356467"
"https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
)
assert returned_activity.data["object"]["inReplyTo"] ==
"https://soc.punktrash.club/objects/d811df79-6e54-4f51-841e-0c38bc356467"
"https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9"
assert returned_activity.data["object"]["inReplyTo"] == origin_comment.url
end

View file

@ -1,25 +1,37 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://soc.punktrash.club/schemas/litepub-0.1.jsonld",
"https://fedi.absturztau.be/schemas/litepub-0.1.jsonld",
{
"@language": "und"
}
],
"actor": "https://soc.punktrash.club/users/jorin",
"attachment": [],
"attributedTo": "https://soc.punktrash.club/users/jorin",
"cc": ["https://soc.punktrash.club/users/jorin/followers"],
"content": "I live in Spain<br><br>The S is silent<br><br>And it&#39;s French<br><br>🥖😎",
"context": "https://soc.punktrash.club/contexts/62eb8f27-c8ea-4cc3-818d-385ff96e4397",
"conversation": "https://soc.punktrash.club/contexts/62eb8f27-c8ea-4cc3-818d-385ff96e4397",
"id": "https://soc.punktrash.club/objects/d811df79-6e54-4f51-841e-0c38bc356467",
"published": "2021-05-06T03:52:10.195835Z",
"repliesCount": 1,
"sensitive": false,
"source": "I live in Spain\n\nThe S is silent\n\nAnd it's French\n\n🥖😎",
"actor": "https://fedi.absturztau.be/users/dqn",
"attachment": [
{
"mediaType": "image/jpeg",
"name": "",
"type": "Document",
"url": "https://fedi.absturztau.be/media/f96e58881c72844e8e233b78f7e53ab93d8308dcf2118e493fcf53d5cc968ea6.jpg?name=p5d85wsralb61.jpg"
}
],
"attributedTo": "https://fedi.absturztau.be/users/dqn",
"cc": ["https://fedi.absturztau.be/users/dqn/followers"],
"content": "<a class=\"hashtag\" data-tag=\"animeirl\" href=\"https://fedi.absturztau.be/tag/animeirl\" rel=\"tag ugc\">#animeirl</a><br><a href=\"https://fedi.absturztau.be/media/f96e58881c72844e8e233b78f7e53ab93d8308dcf2118e493fcf53d5cc968ea6.jpg?name=p5d85wsralb61.jpg\" class='attachment'></a>",
"context": "https://fedi.absturztau.be/contexts/4adddb80-0236-4e03-8a83-94be817b5dbe",
"conversation": "https://fedi.absturztau.be/contexts/4adddb80-0236-4e03-8a83-94be817b5dbe",
"id": "https://fedi.absturztau.be/objects/1726cdc7-4f2a-4ddb-9c68-03d27c98c3d9",
"published": "2021-06-07T09:00:04.292206Z",
"sensitive": null,
"source": "#animeirl",
"summary": "",
"tag": [],
"tag": [
{
"href": "https://fedi.absturztau.be/tags/animeirl",
"name": "#animeirl",
"type": "Hashtag"
}
],
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"type": "Note"
}