From 8b28dce82ac244c6c5e67d8379e68e5742bfe875 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:31:35 -0600 Subject: [PATCH 01/40] Deprecate Pleroma.Uploaders.S3, :public_endpoint --- config/config.exs | 15 +++++++++--- config/description.exs | 8 +------ config/test.exs | 3 +-- docs/configuration/cheatsheet.md | 5 +--- lib/pleroma/config/deprecation_warnings.ex | 24 ++++++++++++++++++- priv/templates/sample_config.eex | 10 ++++++-- .../config/deprecation_warnings_test.exs | 9 +++++++ 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/config/config.exs b/config/config.exs index 7b14fbfe5..2a0c6302c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -64,14 +64,23 @@ config :pleroma, Pleroma.Upload, link_name: false, proxy_remote: false, filename_display_max_length: 30, - default_description: nil + default_description: nil, + base_url: nil config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads" config :pleroma, Pleroma.Uploaders.S3, bucket: nil, - streaming_enabled: true, - public_endpoint: "https://s3.amazonaws.com" + bucket_namespace: nil, + truncated_namespace: false, + streaming_enabled: true + +config :ex_aws, :s3, + # host: "s3.wasabisys.com", # required if not Amazon AWS + access_key_id: nil, + secret_access_key: nil, + # region: nil, # example: "us-east-1" + scheme: "https://" config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"], diff --git a/config/description.exs b/config/description.exs index f438a88ab..493d362d3 100644 --- a/config/description.exs +++ b/config/description.exs @@ -149,18 +149,12 @@ config :pleroma, :config_description, [ description: "S3 bucket namespace", suggestions: ["pleroma"] }, - %{ - key: :public_endpoint, - type: :string, - description: "S3 endpoint", - suggestions: ["https://s3.amazonaws.com"] - }, %{ key: :truncated_namespace, type: :string, description: "If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or \"\" etc." <> - " For example, when using CDN to S3 virtual host format, set \"\". At this time, write CNAME to CDN in public_endpoint." + " For example, when using CDN to S3 virtual host format, set \"\". At this time, write CNAME to CDN in Upload base_url." }, %{ key: :streaming_enabled, diff --git a/config/test.exs b/config/test.exs index 7fc457463..e482f38c8 100644 --- a/config/test.exs +++ b/config/test.exs @@ -117,8 +117,7 @@ config :pleroma, Pleroma.Web.ApiSpec.CastAndValidate, strict: true config :pleroma, Pleroma.Uploaders.S3, bucket: nil, - streaming_enabled: true, - public_endpoint: nil + streaming_enabled: true config :tzdata, :autoupdate, :disabled diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index 85551362c..c7d8a2dae 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -549,7 +549,7 @@ the source code is here: [kocaptcha](https://github.com/koto-bank/kocaptcha). Th * `uploader`: Which one of the [uploaders](#uploaders) to use. * `filters`: List of [upload filters](#upload-filters) to use. * `link_name`: When enabled Pleroma will add a `name` parameter to the url of the upload, for example `https://instance.tld/media/corndog.png?name=corndog.png`. This is needed to provide the correct filename in Content-Disposition headers when using filters like `Pleroma.Upload.Filter.Dedupe` -* `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host. +* `base_url`: The base URL to access a user-uploaded file. Useful when you want to host the media files via another domain or are using a 3rd party S3 provider. * `proxy_remote`: If you're using a remote uploader, Pleroma will proxy media requests instead of redirecting to it. * `proxy_opts`: Proxy options, see `Pleroma.ReverseProxy` documentation. * `filename_display_max_length`: Set max length of a filename to display. 0 = no limit. Default: 30. @@ -570,10 +570,7 @@ Don't forget to configure [Ex AWS S3](#ex-aws-s3-settings) * `bucket`: S3 bucket name. * `bucket_namespace`: S3 bucket namespace. -* `public_endpoint`: S3 endpoint that the user finally accesses(ex. "https://s3.dualstack.ap-northeast-1.amazonaws.com") * `truncated_namespace`: If you use S3 compatible service such as Digital Ocean Spaces or CDN, set folder name or "" etc. -For example, when using CDN to S3 virtual host format, set "". -At this time, write CNAME to CDN in public_endpoint. * `streaming_enabled`: Enable streaming uploads, when enabled the file will be sent to the server in chunks as it's being read. This may be unsupported by some providers, try disabling this if you have upload problems. #### Ex AWS S3 settings diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 59c6b0f58..703a5273f 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -40,7 +40,8 @@ defmodule Pleroma.Config.DeprecationWarnings do :ok <- check_welcome_message_config(), :ok <- check_gun_pool_options(), :ok <- check_activity_expiration_config(), - :ok <- check_remote_ip_plug_name() do + :ok <- check_remote_ip_plug_name(), + :ok <- check_uploders_s3_public_endpoint() do :ok else _ -> @@ -193,4 +194,25 @@ defmodule Pleroma.Config.DeprecationWarnings do warning_preface ) end + + @spec check_uploders_s3_public_endpoint() :: :ok | nil + def check_uploders_s3_public_endpoint do + s3_config = Pleroma.Config.get([Pleroma.Uploaders.S3]) + + use_old_config = Keyword.has_key?(s3_config, :public_endpoint) + + if use_old_config do + Logger.error(""" + !!!DEPRECATION WARNING!!! + Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket.\n + Please make the following change at your earliest convenience.\n + \n* `config :pleroma, Pleroma.Uploaders.S3, public_endpoint` is now equal to: + \n* `config :pleroma, Pleroma.Upload, base_url` + """) + + :error + else + :ok + end + end end diff --git a/priv/templates/sample_config.eex b/priv/templates/sample_config.eex index 2f5952ef1..0c2477e2c 100644 --- a/priv/templates/sample_config.eex +++ b/priv/templates/sample_config.eex @@ -49,12 +49,18 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "<%= uploads_dir %>" # sts: true # Configure S3 support if desired. -# The public S3 endpoint is different depending on region and provider, +# The public S3 endpoint (base_url) is different depending on region and provider, # consult your S3 provider's documentation for details on what to use. # +# config :pleroma, Pleroma.Upload, +# uploader: Pleroma.Uploaders.S3, +# base_url: "https://s3.amazonaws.com" +# # config :pleroma, Pleroma.Uploaders.S3, # bucket: "some-bucket", -# public_endpoint: "https://s3.amazonaws.com" +# bucket_namespace: "my-namespace", +# truncated_namespace: false, +# streaming_enabled: true # # Configure S3 credentials: # config :ex_aws, :s3, diff --git a/test/pleroma/config/deprecation_warnings_test.exs b/test/pleroma/config/deprecation_warnings_test.exs index f52629f8a..161bf6e90 100644 --- a/test/pleroma/config/deprecation_warnings_test.exs +++ b/test/pleroma/config/deprecation_warnings_test.exs @@ -94,6 +94,15 @@ defmodule Pleroma.Config.DeprecationWarningsTest do end) =~ "Your config is using old namespace for activity expiration configuration." end + test "check_uploders_s3_public_endpoint/0" do + clear_config(Pleroma.Uploaders.S3, public_endpoint: "https://fake.amazonaws.com/bucket/") + + assert capture_log(fn -> + DeprecationWarnings.check_uploders_s3_public_endpoint() + end) =~ + "Your config is using the old setting for controlling the URL of media uploaded to your S3 bucket." + end + describe "check_gun_pool_options/0" do test "await_up_timeout" do config = Config.get(:connections_pool) From 12528edc349a6ec10b1a1d9a7daf461823fdf928 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:32:52 -0600 Subject: [PATCH 02/40] Fix another ad-hoc construction of the upload base_url --- lib/pleroma/upload.ex | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 51ca97f41..619a85e93 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -131,12 +131,7 @@ defmodule Pleroma.Upload do uploader: Keyword.get(opts, :uploader, Pleroma.Config.get([__MODULE__, :uploader])), filters: Keyword.get(opts, :filters, Pleroma.Config.get([__MODULE__, :filters])), description: Keyword.get(opts, :description), - base_url: - Keyword.get( - opts, - :base_url, - Pleroma.Config.get([__MODULE__, :base_url], Pleroma.Web.base_url()) - ) + base_url: base_url() } end @@ -217,14 +212,7 @@ defmodule Pleroma.Upload do "" end - prefix = - if is_nil(Pleroma.Config.get([__MODULE__, :base_url])) do - "media" - else - "" - end - - [base_url, prefix, path] + [base_url, path] |> Path.join() end From c35e6fb51615fa3d22cfedeac2158ee62ea9b663 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:34:24 -0600 Subject: [PATCH 03/40] Provide a non-nil fallback for Upload.base_url/0 for tests using TestUploaderSuccess as the uploader --- lib/pleroma/upload.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 619a85e93..e714dc57b 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -249,7 +249,7 @@ defmodule Pleroma.Upload do end _ -> - public_endpoint || upload_base_url + public_endpoint || upload_base_url || Pleroma.Web.base_url() <> "/media/" end end end From e87cca97e62d8464c87c7335741f54c2299cc0d6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:35:10 -0600 Subject: [PATCH 04/40] Fix tests relying on old behavior. Use the Upload.base_url, Luke. --- test/pleroma/upload_test.exs | 4 ++-- test/pleroma/uploaders/s3_test.exs | 13 +++++++++---- test/pleroma/user/backup_test.exs | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/pleroma/upload_test.exs b/test/pleroma/upload_test.exs index f52d4dff6..cea161d8c 100644 --- a/test/pleroma/upload_test.exs +++ b/test/pleroma/upload_test.exs @@ -148,8 +148,8 @@ defmodule Pleroma.UploadTest do {:ok, data} = Upload.store(file, filters: [Pleroma.Upload.Filter.Dedupe]) assert List.first(data["url"])["href"] == - Pleroma.Web.base_url() <> - "/media/e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg" + Pleroma.Upload.base_url() <> + "e30397b58d226d6583ab5b8b3c5defb0c682bda5c31ef07a9f57c1c4986e3781.jpg" end test "copies the file to the configured folder without deduping" do diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs index 344cf7abe..f399f8ae5 100644 --- a/test/pleroma/uploaders/s3_test.exs +++ b/test/pleroma/uploaders/s3_test.exs @@ -16,9 +16,12 @@ defmodule Pleroma.Uploaders.S3Test do uploader: Pleroma.Uploaders.S3 ) + clear_config(Pleroma.Upload, + base_url: "https://s3.amazonaws.com" + ) + clear_config(Pleroma.Uploaders.S3, - bucket: "test_bucket", - public_endpoint: "https://s3.amazonaws.com" + bucket: "test_bucket" ) end @@ -33,10 +36,11 @@ defmodule Pleroma.Uploaders.S3Test do test "it returns path without bucket when truncated_namespace set to ''" do Config.put([Pleroma.Uploaders.S3], bucket: "test_bucket", - public_endpoint: "https://s3.amazonaws.com", truncated_namespace: "" ) + Config.put([Pleroma.Upload], base_url: "https://s3.amazonaws.com") + assert S3.get_file("test_image.jpg") == { :ok, {:url, "https://s3.amazonaws.com/test_image.jpg"} @@ -46,10 +50,11 @@ defmodule Pleroma.Uploaders.S3Test do test "it returns path with bucket namespace when namespace is set" do Config.put([Pleroma.Uploaders.S3], bucket: "test_bucket", - public_endpoint: "https://s3.amazonaws.com", bucket_namespace: "family" ) + Config.put([Pleroma.Upload], base_url: "https://s3.amazonaws.com") + assert S3.get_file("test_image.jpg") == { :ok, {:url, "https://s3.amazonaws.com/family:test_bucket/test_image.jpg"} diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index f68e4a029..01a1ed962 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -196,11 +196,11 @@ defmodule Pleroma.User.BackupTest do describe "it uploads and deletes a backup archive" do setup do clear_config(Pleroma.Uploaders.S3, - bucket: "test_bucket", - public_endpoint: "https://s3.amazonaws.com" + bucket: "test_bucket" ) clear_config([Pleroma.Upload, :uploader]) + clear_config([Pleroma.Upload, base_url: "https://s3.amazonaws.com"]) user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"}) From 2b93351bd7b1377793256a14c0356e1dccf36d2e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:40:29 -0600 Subject: [PATCH 05/40] Document deprecation --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25b24bf07..31d6a7561 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Search: When using Postgres 11+, Pleroma will use the `websearch_to_tsvector` function to parse search queries. - Emoji: Support the full Unicode 13.1 set of Emoji for reactions, plus regional indicators. - Admin API: Reports now ordered by newest +- Deprecated `Pleroma.Uploaders.S3, :public_endpoint`. Now `Pleroma.Upload, :base_url` is the standard configuration key for all uploaders. ### Added From 67e888498c16c8bba434afe91cb3e0a83b9da8bb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 12 Jan 2021 16:42:43 -0600 Subject: [PATCH 06/40] Switch another test to Upload.base_url/0 --- test/pleroma/upload_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pleroma/upload_test.exs b/test/pleroma/upload_test.exs index cea161d8c..8f84a0be1 100644 --- a/test/pleroma/upload_test.exs +++ b/test/pleroma/upload_test.exs @@ -133,7 +133,7 @@ defmodule Pleroma.UploadTest do assert %{"url" => [%{"href" => url}]} = data - assert String.starts_with?(url, Pleroma.Web.base_url() <> "/media/") + assert String.starts_with?(url, Pleroma.Upload.base_url()) end test "copies the file to the configured folder with deduping" do From f0ab60189e0749ca207b483b291c90f892dce6a3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 13 Jan 2021 11:54:00 -0600 Subject: [PATCH 07/40] truncated_namespace should default to nil --- config/config.exs | 2 +- lib/pleroma/upload.ex | 6 ++++-- priv/templates/sample_config.eex | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index 2a0c6302c..ef3baed93 100644 --- a/config/config.exs +++ b/config/config.exs @@ -72,7 +72,7 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "uploads" config :pleroma, Pleroma.Uploaders.S3, bucket: nil, bucket_namespace: nil, - truncated_namespace: false, + truncated_namespace: nil, streaming_enabled: true config :ex_aws, :s3, diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index e714dc57b..e13d40c5a 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -229,13 +229,15 @@ defmodule Pleroma.Upload do Pleroma.Uploaders.S3 -> bucket = Config.get([Pleroma.Uploaders.S3, :bucket]) + truncated_namespace = Config.get([Pleroma.Uploaders.S3, :truncated_namespace]) + namespace = Config.get([Pleroma.Uploaders.S3, :bucket_namespace]) bucket_with_namespace = cond do - truncated_namespace = Config.get([Pleroma.Uploaders.S3, :truncated_namespace]) -> + !is_nil(truncated_namespace) -> truncated_namespace - namespace = Config.get([Pleroma.Uploaders.S3, :bucket_namespace]) -> + !is_nil(namespace) -> namespace <> ":" <> bucket true -> diff --git a/priv/templates/sample_config.eex b/priv/templates/sample_config.eex index 0c2477e2c..42f496ded 100644 --- a/priv/templates/sample_config.eex +++ b/priv/templates/sample_config.eex @@ -59,7 +59,7 @@ config :pleroma, Pleroma.Uploaders.Local, uploads: "<%= uploads_dir %>" # config :pleroma, Pleroma.Uploaders.S3, # bucket: "some-bucket", # bucket_namespace: "my-namespace", -# truncated_namespace: false, +# truncated_namespace: nil, # streaming_enabled: true # # Configure S3 credentials: From 5627f3642fd96b678bdd5c3b9f3da0dbb038d75c Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 13 Jan 2021 11:54:45 -0600 Subject: [PATCH 08/40] Not needed in test.exs --- config/test.exs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/test.exs b/config/test.exs index e482f38c8..76c7a2c67 100644 --- a/config/test.exs +++ b/config/test.exs @@ -115,10 +115,6 @@ config :pleroma, Pleroma.Web.Plugs.RemoteIp, enabled: false config :pleroma, Pleroma.Web.ApiSpec.CastAndValidate, strict: true -config :pleroma, Pleroma.Uploaders.S3, - bucket: nil, - streaming_enabled: true - config :tzdata, :autoupdate, :disabled config :pleroma, :mrf, policies: [] From 94e51808461cd5a6148c6782159fa3f0ecc14638 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 13 Jan 2021 12:00:48 -0600 Subject: [PATCH 09/40] Consistent style --- test/pleroma/uploaders/s3_test.exs | 9 ++------- test/pleroma/user/backup_test.exs | 9 +++------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs index f399f8ae5..da3a57163 100644 --- a/test/pleroma/uploaders/s3_test.exs +++ b/test/pleroma/uploaders/s3_test.exs @@ -12,13 +12,8 @@ defmodule Pleroma.Uploaders.S3Test do import ExUnit.CaptureLog setup do - clear_config(Pleroma.Upload, - uploader: Pleroma.Uploaders.S3 - ) - - clear_config(Pleroma.Upload, - base_url: "https://s3.amazonaws.com" - ) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) + clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") clear_config(Pleroma.Uploaders.S3, bucket: "test_bucket" diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 01a1ed962..64a92cb7d 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -195,12 +195,9 @@ defmodule Pleroma.User.BackupTest do describe "it uploads and deletes a backup archive" do setup do - clear_config(Pleroma.Uploaders.S3, - bucket: "test_bucket" - ) - - clear_config([Pleroma.Upload, :uploader]) - clear_config([Pleroma.Upload, base_url: "https://s3.amazonaws.com"]) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) + clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") + clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket") user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"}) From ba234d3c73ee6d6e96150928d0853c51783abd1d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 13 Jan 2021 12:01:01 -0600 Subject: [PATCH 10/40] Unnecessary duplication here --- test/pleroma/uploaders/s3_test.exs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs index da3a57163..30653aad2 100644 --- a/test/pleroma/uploaders/s3_test.exs +++ b/test/pleroma/uploaders/s3_test.exs @@ -48,8 +48,6 @@ defmodule Pleroma.Uploaders.S3Test do bucket_namespace: "family" ) - Config.put([Pleroma.Upload], base_url: "https://s3.amazonaws.com") - assert S3.get_file("test_image.jpg") == { :ok, {:url, "https://s3.amazonaws.com/family:test_bucket/test_image.jpg"} From fd9a0ac32943f7869e950524d4ed7a052f609e5c Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Thu, 14 Jan 2021 20:18:45 +0100 Subject: [PATCH 11/40] BackupTest: Fix s3 test. --- test/pleroma/user/backup_test.exs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 64a92cb7d..108928c09 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -195,7 +195,6 @@ defmodule Pleroma.User.BackupTest do describe "it uploads and deletes a backup archive" do setup do - clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket") @@ -216,7 +215,8 @@ defmodule Pleroma.User.BackupTest do end test "S3", %{path: path, backup: backup} do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) + clear_config([Pleroma.Uploaders.S3, :streaming_enabled], false) with_mock ExAws, request: fn @@ -226,13 +226,10 @@ defmodule Pleroma.User.BackupTest do assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path) assert {:ok, _backup} = Backup.delete(backup) end - - with_mock ExAws, request: fn %{http_method: :delete} -> {:ok, %{status_code: 204}} end do - end end test "Local", %{path: path, backup: backup} do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) assert {:ok, %Pleroma.Upload{}} = Backup.upload(backup, path) assert {:ok, _backup} = Backup.delete(backup) From fb47e83adc074f994714c83618b6de17915d0556 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 14 Jan 2021 13:53:35 -0600 Subject: [PATCH 12/40] Add ConfigDB migration --- ...210113225652_deprecate_public_endpoint.exs | 57 ++++++++++++++++++ .../public_endpoint_deprecation_test.exs | 60 +++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs create mode 100644 test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs diff --git a/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs b/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs new file mode 100644 index 000000000..d2e6e3c56 --- /dev/null +++ b/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs @@ -0,0 +1,57 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpoint do + use Ecto.Migration + + def up do + with %Pleroma.ConfigDB{} = s3_config <- + Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}), + %Pleroma.ConfigDB{} = upload_config <- + Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) do + public_endpoint = s3_config.value[:public_endpoint] + + if !is_nil(public_endpoint) do + upload_value = upload_config.value |> Keyword.merge(base_url: public_endpoint) + + upload_config + |> Ecto.Changeset.change(value: upload_value) + |> Pleroma.Repo.update() + + s3_value = s3_config.value |> Keyword.delete(:public_endpoint) + + s3_config + |> Ecto.Changeset.change(value: s3_value) + |> Pleroma.Repo.update() + end + else + _ -> :ok + end + end + + def down do + with %Pleroma.ConfigDB{} = upload_config <- + Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}), + %Pleroma.ConfigDB{} = s3_config <- + Pleroma.ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}) do + base_url = upload_config.value[:base_url] + + if !is_nil(base_url) do + s3_value = s3_config.value |> Keyword.merge(public_endpoint: base_url) + + s3_config + |> Ecto.Changeset.change(value: s3_value) + |> Pleroma.Repo.update() + + upload_value = upload_config.value |> Keyword.delete(:base_url) + + upload_config + |> Ecto.Changeset.change(value: upload_value) + |> Pleroma.Repo.update() + end + else + _ -> :ok + end + end +end diff --git a/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs b/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs new file mode 100644 index 000000000..b68d24bfc --- /dev/null +++ b/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs @@ -0,0 +1,60 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do + use Pleroma.DataCase + import Pleroma.Factory + import Pleroma.Tests.Helpers + alias Pleroma.ConfigDB + + setup do: clear_config(Pleroma.Upload) + setup do: clear_config(Pleroma.Uploaders.S3) + setup_all do: require_migration("20210113225652_deprecate_public_endpoint") + + test "up/0 migrates public_endpoint to base_url", %{migration: migration} do + s3_values = [ + public_endpoint: "https://coolhost.com/", + bucket: "secret_bucket" + ] + + insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values) + + upload_values = [ + uploader: Pleroma.Uploaders.S3 + ] + + insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values) + + migration.up() + + assert [bucket: "secret_bucket"] == + ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value + + assert [uploader: Pleroma.Uploaders.S3, base_url: "https://coolhost.com/"] == + ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value + end + + test "down/0 reverts base_url to public_endpoint", %{migration: migration} do + s3_values = [ + bucket: "secret_bucket" + ] + + insert(:config, group: :pleroma, key: Pleroma.Uploaders.S3, value: s3_values) + + upload_values = [ + uploader: Pleroma.Uploaders.S3, + base_url: "https://coolhost.com/" + ] + + insert(:config, group: :pleroma, key: Pleroma.Upload, value: upload_values) + + migration.down() + + assert [bucket: "secret_bucket", public_endpoint: "https://coolhost.com/"] == + ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Uploaders.S3}).value + + assert [uploader: Pleroma.Uploaders.S3] == + ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value + end +end From 12c8ce481c1afec69a9f401bcfffae63744dfb09 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 14 Jan 2021 13:58:52 -0600 Subject: [PATCH 13/40] Bump Copyright year --- .../migrations/20210113225652_deprecate_public_endpoint.exs | 2 +- .../repo/migrations/public_endpoint_deprecation_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs b/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs index d2e6e3c56..6f470a459 100644 --- a/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs +++ b/priv/repo/migrations/20210113225652_deprecate_public_endpoint.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpoint do diff --git a/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs b/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs index b68d24bfc..2ffc1b145 100644 --- a/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs +++ b/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Repo.Migrations.DeprecatePublicEndpointTest do From 0b725f5d216cfd2b11f81cddd792338c23161a60 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 14 Jan 2021 16:00:32 -0600 Subject: [PATCH 14/40] Lint --- ...nt_deprecation_test.exs => deprecate_public_endpoint_test.exs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/pleroma/repo/migrations/{public_endpoint_deprecation_test.exs => deprecate_public_endpoint_test.exs} (100%) diff --git a/test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs b/test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs similarity index 100% rename from test/pleroma/repo/migrations/public_endpoint_deprecation_test.exs rename to test/pleroma/repo/migrations/deprecate_public_endpoint_test.exs From d0e0396528c55f1b61c1d48452e855ea69ec3e89 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 14 Jan 2021 17:49:37 -0600 Subject: [PATCH 15/40] Hack to fix tests not passing. Unclear why the filters are being set to nil. Both of these changes are needed or it doesn't work. --- lib/pleroma/upload/filter.ex | 2 ++ test/support/data_case.ex | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/upload/filter.ex b/lib/pleroma/upload/filter.ex index 661135634..367acd214 100644 --- a/lib/pleroma/upload/filter.ex +++ b/lib/pleroma/upload/filter.ex @@ -43,4 +43,6 @@ defmodule Pleroma.Upload.Filter do error end end + + def filter(nil, upload), do: filter([], upload) end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 0b41f0f63..23c858d2a 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -107,7 +107,7 @@ defmodule Pleroma.DataCase do def ensure_local_uploader(context) do test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local) uploader = Pleroma.Config.get([Pleroma.Upload, :uploader]) - filters = Pleroma.Config.get([Pleroma.Upload, :filters]) + filters = Pleroma.Config.get([Pleroma.Upload, :filters]) || [] Pleroma.Config.put([Pleroma.Upload, :uploader], test_uploader) Pleroma.Config.put([Pleroma.Upload, :filters], []) From d2382ab5f4b507b01ae7fbe6d7522e33d073419d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 14:58:33 -0600 Subject: [PATCH 16/40] Update Oban to 2.3.4 --- mix.exs | 2 +- mix.lock | 8 ++++---- .../20210115205649_upgrade_oban_jobs_to_v9.exs | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs diff --git a/mix.exs b/mix.exs index 14448f12f..caa86d395 100644 --- a/mix.exs +++ b/mix.exs @@ -123,7 +123,7 @@ defmodule Pleroma.Mixfile do {:ecto_enum, "~> 1.4"}, {:ecto_sql, "~> 3.4.4"}, {:postgrex, ">= 0.15.5"}, - {:oban, "~> 2.1.0"}, + {:oban, "~> 2.3.4"}, {:gettext, "~> 0.18"}, {:bcrypt_elixir, "~> 2.2"}, {:trailing_format_plug, "~> 0.0.7"}, diff --git a/mix.lock b/mix.lock index 01caf319e..840a82555 100644 --- a/mix.lock +++ b/mix.lock @@ -15,7 +15,7 @@ "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "comeonin": {:hex, :comeonin, "5.3.1", "7fe612b739c78c9c1a75186ef2d322ce4d25032d119823269d0aa1e2f1e20025", [:mix], [], "hexpm", "d6222483060c17f0977fad1b7401ef0c5863c985a64352755f366aee3799c245"}, "concurrent_limiter": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/concurrent_limiter.git", "d81be41024569330f296fc472e24198d7499ba78", [ref: "d81be41024569330f296fc472e24198d7499ba78"]}, - "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, + "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cors_plug": {:hex, :cors_plug, "2.0.2", "2b46083af45e4bc79632bd951550509395935d3e7973275b2b743bd63cc942ce", [:mix], [{:plug, "~> 1.8", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "f0d0e13f71c51fd4ef8b2c7e051388e4dfb267522a83a22392c856de7e46465f"}, "cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.0", "69fdb5cf92df6373e15675eb4018cf629f5d8e35e74841bb637d6596cb797bbc", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "42868c229d9a2900a1501c5d0355bfd46e24c862c322b0b4f5a6f14fe0216753"}, @@ -24,7 +24,7 @@ "crontab": {:hex, :crontab, "1.1.8", "2ce0e74777dfcadb28a1debbea707e58b879e6aa0ffbf9c9bb540887bce43617", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"}, "crypt": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/crypt.git", "cf2aa3f11632e8b0634810a15b3e612c7526f6a3", [ref: "cf2aa3f11632e8b0634810a15b3e612c7526f6a3"]}, "custom_base": {:hex, :custom_base, "0.2.1", "4a832a42ea0552299d81652aa0b1f775d462175293e99dfbe4d7dbaab785a706", [:mix], [], "hexpm", "8df019facc5ec9603e94f7270f1ac73ddf339f56ade76a721eaa57c1493ba463"}, - "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, + "db_connection": {:hex, :db_connection, "2.3.1", "4c9f3ed1ef37471cbdd2762d6655be11e38193904d9c5c1c9389f1b891a3088e", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "abaab61780dde30301d840417890bd9f74131041afd02174cf4e10635b3a63f5"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, @@ -81,7 +81,7 @@ "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, "nimble_pool": {:hex, :nimble_pool, "0.1.0", "ffa9d5be27eee2b00b0c634eb649aa27f97b39186fec3c493716c2a33e784ec6", [:mix], [], "hexpm", "343a1eaa620ddcf3430a83f39f2af499fe2370390d4f785cd475b4df5acaf3f9"}, "nodex": {:git, "https://git.pleroma.social/pleroma/nodex", "cb6730f943cfc6aad674c92161be23a8411f15d1", [ref: "cb6730f943cfc6aad674c92161be23a8411f15d1"]}, - "oban": {:hex, :oban, "2.1.0", "034144686f7e76a102b5d67731f098d98a9e4a52b07c25ad580a01f83a7f1cf5", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c6f067fa3b308ed9e0e6beb2b34277c9c4e48bf95338edabd8f4a757a26e04c2"}, + "oban": {:hex, :oban, "2.3.4", "ec7509b9af2524d55f529cb7aee93d36131ae0bf0f37706f65d2fe707f4d9fd8", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c70ca0434758fd1805422ea4446af5e910ddc697c0c861549c8f0eb0cfbd2fdf"}, "open_api_spex": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/open_api_spex.git", "f296ac0924ba3cf79c7a588c4c252889df4c2edd", [ref: "f296ac0924ba3cf79c7a588c4c252889df4c2edd"]}, "p1_utils": {:hex, :p1_utils, "1.0.18", "3fe224de5b2e190d730a3c5da9d6e8540c96484cf4b4692921d1e28f0c32b01c", [:rebar3], [], "hexpm", "1fc8773a71a15553b179c986b22fbeead19b28fe486c332d4929700ffeb71f88"}, "parse_trans": {:git, "https://github.com/uwiger/parse_trans.git", "76abb347c3c1d00fb0ccf9e4b43e22b3d2288484", [tag: "3.3.0"]}, @@ -97,7 +97,7 @@ "plug_static_index_html": {:hex, :plug_static_index_html, "1.0.0", "840123d4d3975585133485ea86af73cb2600afd7f2a976f9f5fd8b3808e636a0", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "79fd4fcf34d110605c26560cbae8f23c603ec4158c08298bd4360fdea90bb5cf"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"}, "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, - "postgrex": {:hex, :postgrex, "0.15.6", "a464c72010a56e3214fe2b99c1a76faab4c2bb0255cabdef30dea763a3569aa2", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "f99268325ac8f66ffd6c4964faab9e70fbf721234ab2ad238c00f9530b8cdd55"}, + "postgrex": {:hex, :postgrex, "0.15.7", "724410acd48abac529d0faa6c2a379fb8ae2088e31247687b16cacc0e0883372", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "88310c010ff047cecd73d5ceca1d99205e4b1ab1b9abfdab7e00f5c9d20ef8f9"}, "pot": {:hex, :pot, "0.11.0", "61bad869a94534739dd4614a25a619bc5c47b9970e9a0ea5bef4628036fc7a16", [:rebar3], [], "hexpm", "57ee6ee6bdeb639661ffafb9acefe3c8f966e45394de6a766813bb9e1be4e54b"}, "prometheus": {:hex, :prometheus, "4.6.0", "20510f381db1ccab818b4cf2fac5fa6ab5cc91bc364a154399901c001465f46f", [:mix, :rebar3], [], "hexpm", "4905fd2992f8038eccd7aa0cd22f40637ed618c0bed1f75c05aacec15b7545de"}, "prometheus_ecto": {:hex, :prometheus_ecto, "1.4.3", "3dd4da1812b8e0dbee81ea58bb3b62ed7588f2eae0c9e97e434c46807ff82311", [:mix], [{:ecto, "~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:prometheus_ex, "~> 1.1 or ~> 2.0 or ~> 3.0", [hex: :prometheus_ex, repo: "hexpm", optional: false]}], "hexpm", "8d66289f77f913b37eda81fd287340c17e61a447549deb28efc254532b2bed82"}, diff --git a/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs b/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs new file mode 100644 index 000000000..067e62e8c --- /dev/null +++ b/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs @@ -0,0 +1,10 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.UpgradeObanJobsToV9 do + use Ecto.Migration + + defdelegate up, to: Oban.Migrations + defdelegate down, to: Oban.Migrations +end From 3607dfefcae4a941c05f9e350354226d1c5fa920 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 16:53:55 -0600 Subject: [PATCH 17/40] Add mix alias to easily add copyright headers to files --- mix.exs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 14448f12f..166cbdca5 100644 --- a/mix.exs +++ b/mix.exs @@ -229,7 +229,8 @@ defmodule Pleroma.Mixfile do "ecto.reset": ["ecto.drop", "ecto.setup"], test: ["ecto.create --quiet", "ecto.migrate", "test"], docs: ["pleroma.docs", "docs"], - analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"] + analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"], + copyright: &add_copyright/1 ] end @@ -332,4 +333,20 @@ defmodule Pleroma.Mixfile do |> Enum.filter(fn string -> string && string != "" end) |> Enum.join() end + + defp add_copyright(_) do + line1 = "# Pleroma: A lightweight social networking server\\n" + + line2 = + "# Copyright © 2017-#{NaiveDateTime.utc_now().year} Pleroma Authors \\n" + + line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" + template = line1 <> line2 <> line3 + + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " + grep = "grep -L '# Copyright' {} \\; |" + xargs = "xargs -n1 sed -i '' '1s;^;#{template};'" + + :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) + end end From 41a637c3a66cc68efddb84d3e888c6c21787c1c9 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 17:25:43 -0600 Subject: [PATCH 18/40] Split out year --- mix.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 166cbdca5..1bfca0b47 100644 --- a/mix.exs +++ b/mix.exs @@ -335,10 +335,10 @@ defmodule Pleroma.Mixfile do end defp add_copyright(_) do + year = NaiveDateTime.utc_now().year line1 = "# Pleroma: A lightweight social networking server\\n" - line2 = - "# Copyright © 2017-#{NaiveDateTime.utc_now().year} Pleroma Authors \\n" + line2 = "# Copyright © 2017-#{year} Pleroma Authors \\n" line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" template = line1 <> line2 <> line3 From 23c6cea889658b5a03b113854f0489ee2da147c7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 17:26:02 -0600 Subject: [PATCH 19/40] Add a mix alias to bump copyright --- mix.exs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 1bfca0b47..281cca643 100644 --- a/mix.exs +++ b/mix.exs @@ -230,7 +230,8 @@ defmodule Pleroma.Mixfile do test: ["ecto.create --quiet", "ecto.migrate", "test"], docs: ["pleroma.docs", "docs"], analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"], - copyright: &add_copyright/1 + copyright: &add_copyright/1, + "copyright.bump": &bump_copyright/1 ] end @@ -349,4 +350,13 @@ defmodule Pleroma.Mixfile do :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) end + + defp bump_copyright(_) do + year = NaiveDateTime.utc_now().year + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" + + xargs = "xargs sed -i '' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + + :os.cmd(String.to_charlist("#{find}#{xargs}")) + end end From 99c2e8ed5c797078188911d05b693388a88ade3d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:12:41 +0100 Subject: [PATCH 20/40] mix.exs: GNU sed doesn't into proper getopt() --- mix.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 281cca643..5404a5c11 100644 --- a/mix.exs +++ b/mix.exs @@ -346,7 +346,7 @@ defmodule Pleroma.Mixfile do find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " grep = "grep -L '# Copyright' {} \\; |" - xargs = "xargs -n1 sed -i '' '1s;^;#{template};'" + xargs = "xargs -n1 sed -i'' '1s;^;#{template};'" :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) end @@ -355,7 +355,7 @@ defmodule Pleroma.Mixfile do year = NaiveDateTime.utc_now().year find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" - xargs = "xargs sed -i '' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + xargs = "xargs sed -i'' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" :os.cmd(String.to_charlist("#{find}#{xargs}")) end From a17a9dcc4d5f3d8f27769d334462c54d6b457230 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:17:24 +0100 Subject: [PATCH 21/40] mix.exs: Put template into one variable with ~s[] --- mix.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mix.exs b/mix.exs index 5404a5c11..79d9783c4 100644 --- a/mix.exs +++ b/mix.exs @@ -337,12 +337,12 @@ defmodule Pleroma.Mixfile do defp add_copyright(_) do year = NaiveDateTime.utc_now().year - line1 = "# Pleroma: A lightweight social networking server\\n" + template = ~s[\ +# Pleroma: A lightweight social networking server +# Copyright © 2017-#{year} Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only - line2 = "# Copyright © 2017-#{year} Pleroma Authors \\n" - - line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" - template = line1 <> line2 <> line3 +] |> String.replace("\n", "\\n") find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " grep = "grep -L '# Copyright' {} \\; |" From 3e0d1588a45d1e0d6b23ad2d39050098bc445269 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:38:37 +0100 Subject: [PATCH 22/40] mix.exs: Make copyright regexes more precise - Add copyright checks for Pleroma's not any copyright - Copyright bump fixes the whole line instead of just the year --- mix.exs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mix.exs b/mix.exs index 79d9783c4..26b52b0cb 100644 --- a/mix.exs +++ b/mix.exs @@ -345,18 +345,19 @@ defmodule Pleroma.Mixfile do ] |> String.replace("\n", "\\n") find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " - grep = "grep -L '# Copyright' {} \\; |" + grep = "grep -L '# Copyright © [0-9\-]* Pleroma' {} \\;" xargs = "xargs -n1 sed -i'' '1s;^;#{template};'" - :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) + :os.cmd(String.to_charlist("#{find}#{grep} | #{xargs}")) end defp bump_copyright(_) do year = NaiveDateTime.utc_now().year - find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\)" - xargs = "xargs sed -i'' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + xargs = + "xargs sed -i'' 's;# Copyright © [0-9\-]* Pleroma.*$;# Copyright © 2017-#{year} Pleroma Authors ;'" - :os.cmd(String.to_charlist("#{find}#{xargs}")) + :os.cmd(String.to_charlist("#{find} | #{xargs}")) end end From 3f88e33a71ce02cdea722c322f1e86672aa5ff69 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 16 Jan 2021 23:05:31 +0300 Subject: [PATCH 23/40] [#3251] Fixed wrong test-env config setting for [Pleroma.Upload]. Refactoring. Added warning to `clear_config/_` to minimize such issues in future. --- lib/pleroma/upload/filter.ex | 2 -- test/pleroma/object_test.exs | 24 ++++++++++++------------ test/pleroma/scheduled_activity_test.exs | 7 +++---- test/pleroma/uploaders/s3_test.exs | 8 +++----- test/support/data_case.ex | 15 +++++---------- test/support/helpers.ex | 12 ++++++++++++ 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/lib/pleroma/upload/filter.ex b/lib/pleroma/upload/filter.ex index 367acd214..661135634 100644 --- a/lib/pleroma/upload/filter.ex +++ b/lib/pleroma/upload/filter.ex @@ -43,6 +43,4 @@ defmodule Pleroma.Upload.Filter do error end end - - def filter(nil, upload), do: filter([], upload) end diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs index fe7f37e7c..3150c8e01 100644 --- a/test/pleroma/object_test.exs +++ b/test/pleroma/object_test.exs @@ -78,8 +78,8 @@ defmodule Pleroma.ObjectTest do setup do: clear_config([:instance, :cleanup_attachments]) test "Disabled via config" do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([:instance, :cleanup_attachments], false) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([:instance, :cleanup_attachments], false) file = %Plug.Upload{ content_type: "image/jpeg", @@ -112,8 +112,8 @@ defmodule Pleroma.ObjectTest do end test "in subdirectories" do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([:instance, :cleanup_attachments], true) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpeg", @@ -146,9 +146,9 @@ defmodule Pleroma.ObjectTest do end test "with dedupe enabled" do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe]) - Pleroma.Config.put([:instance, :cleanup_attachments], true) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([Pleroma.Upload, :filters], [Pleroma.Upload.Filter.Dedupe]) + clear_config([:instance, :cleanup_attachments], true) uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads]) @@ -184,8 +184,8 @@ defmodule Pleroma.ObjectTest do end test "with objects that have legacy data.url attribute" do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([:instance, :cleanup_attachments], true) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpeg", @@ -220,9 +220,9 @@ defmodule Pleroma.ObjectTest do end test "With custom base_url" do - Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) - Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/") - Pleroma.Config.put([:instance, :cleanup_attachments], true) + clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) + clear_config([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/") + clear_config([:instance, :cleanup_attachments], true) file = %Plug.Upload{ content_type: "image/jpeg", diff --git a/test/pleroma/scheduled_activity_test.exs b/test/pleroma/scheduled_activity_test.exs index 7faa5660d..902d1d99c 100644 --- a/test/pleroma/scheduled_activity_test.exs +++ b/test/pleroma/scheduled_activity_test.exs @@ -4,15 +4,14 @@ defmodule Pleroma.ScheduledActivityTest do use Pleroma.DataCase - alias Pleroma.DataCase + alias Pleroma.ScheduledActivity + import Pleroma.Factory setup do: clear_config([ScheduledActivity, :enabled]) - setup context do - DataCase.ensure_local_uploader(context) - end + setup [:ensure_local_uploader] describe "creation" do test "scheduled activities with jobs when ScheduledActivity enabled" do diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs index 30653aad2..242dc0d50 100644 --- a/test/pleroma/uploaders/s3_test.exs +++ b/test/pleroma/uploaders/s3_test.exs @@ -14,10 +14,8 @@ defmodule Pleroma.Uploaders.S3Test do setup do clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3) clear_config([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") - - clear_config(Pleroma.Uploaders.S3, - bucket: "test_bucket" - ) + clear_config([Pleroma.Uploaders.S3]) + clear_config([Pleroma.Uploaders.S3, :bucket], "test_bucket") end describe "get_file/1" do @@ -34,7 +32,7 @@ defmodule Pleroma.Uploaders.S3Test do truncated_namespace: "" ) - Config.put([Pleroma.Upload], base_url: "https://s3.amazonaws.com") + Config.put([Pleroma.Upload, :base_url], "https://s3.amazonaws.com") assert S3.get_file("test_image.jpg") == { :ok, diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 23c858d2a..0427682a2 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -18,6 +18,8 @@ defmodule Pleroma.DataCase do use ExUnit.CaseTemplate + import Pleroma.Tests.Helpers, only: [clear_config: 2] + using do quote do alias Pleroma.Repo @@ -105,17 +107,10 @@ defmodule Pleroma.DataCase do end def ensure_local_uploader(context) do - test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local) - uploader = Pleroma.Config.get([Pleroma.Upload, :uploader]) - filters = Pleroma.Config.get([Pleroma.Upload, :filters]) || [] + test_uploader = Map.get(context, :uploader) || Pleroma.Uploaders.Local - Pleroma.Config.put([Pleroma.Upload, :uploader], test_uploader) - Pleroma.Config.put([Pleroma.Upload, :filters], []) - - on_exit(fn -> - Pleroma.Config.put([Pleroma.Upload, :uploader], uploader) - Pleroma.Config.put([Pleroma.Upload, :filters], filters) - end) + clear_config([Pleroma.Upload, :uploader], test_uploader) + clear_config([Pleroma.Upload, :filters], []) :ok end diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 15e8cbd9d..db38a1e81 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -8,6 +8,8 @@ defmodule Pleroma.Tests.Helpers do """ alias Pleroma.Config + require Logger + defmacro clear_config(config_path) do quote do clear_config(unquote(config_path)) do @@ -18,6 +20,7 @@ defmodule Pleroma.Tests.Helpers do defmacro clear_config(config_path, do: yield) do quote do initial_setting = Config.fetch(unquote(config_path)) + unquote(yield) on_exit(fn -> @@ -35,6 +38,15 @@ defmodule Pleroma.Tests.Helpers do end defmacro clear_config(config_path, temp_setting) do + # NOTE: `clear_config([section, key], value)` != `clear_config([section], key: value)` (!) + # Displaying a warning to prevent unintentional clearing of all but one keys in section + if Keyword.keyword?(temp_setting) and length(temp_setting) == 1 do + Logger.warn( + "Please change to `clear_config([section]); clear_config([section, key], value)`: " <> + "#{inspect(config_path)}, #{inspect(temp_setting)}" + ) + end + quote do clear_config(unquote(config_path)) do Config.put(unquote(config_path), unquote(temp_setting)) From 02dbf1c51d7d12e30e279afb3b84c2141c6c6e4a Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sun, 17 Jan 2021 09:58:07 +0300 Subject: [PATCH 24/40] use explicitly oban migration version --- .../20210115205649_upgrade_oban_jobs_to_v9.exs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs b/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs index 067e62e8c..bfb405579 100644 --- a/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs +++ b/priv/repo/migrations/20210115205649_upgrade_oban_jobs_to_v9.exs @@ -5,6 +5,11 @@ defmodule Pleroma.Repo.Migrations.UpgradeObanJobsToV9 do use Ecto.Migration - defdelegate up, to: Oban.Migrations - defdelegate down, to: Oban.Migrations + def up do + Oban.Migrations.up(version: 9) + end + + def down do + Oban.Migrations.down(version: 9) + end end From 0e48c80d7fd65cedaccd2ecbfbd49bb0f56d6f4d Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sun, 17 Jan 2021 09:58:41 +0300 Subject: [PATCH 25/40] start oban app in migrations and mix tasks --- lib/mix/pleroma.ex | 3 ++- .../20200825061316_move_activity_expirations_to_oban.exs | 2 ++ .../20200907092050_move_tokens_expiration_into_oban.exs | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 45d0ad624..2b6c7d6bb 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -13,7 +13,8 @@ defmodule Mix.Pleroma do :flake_id, :swoosh, :timex, - :fast_html + :fast_html, + :oban ] @cachex_children ["object", "user", "scrubber", "web_resp"] @doc "Common functions to be reused in mix tasks" diff --git a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs index a703af83f..096ab4ce5 100644 --- a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs +++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs @@ -6,6 +6,8 @@ defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do def change do Pleroma.Config.Oban.warn() + Application.ensure_all_started(:oban) + Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}], strategy: :one_for_one, name: Pleroma.Supervisor diff --git a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs index 9e49ddacb..725c5ab0b 100644 --- a/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs +++ b/priv/repo/migrations/20200907092050_move_tokens_expiration_into_oban.exs @@ -6,6 +6,8 @@ defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do def change do Pleroma.Config.Oban.warn() + Application.ensure_all_started(:oban) + Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}], strategy: :one_for_one, name: Pleroma.Supervisor From 318d6dde1c6cb0c3d6c9e31b976d71de8c721d8d Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Tue, 19 Jan 2021 00:23:39 +0300 Subject: [PATCH 26/40] Mox mode setup tweak; refactoring. --- test/pleroma/gun/connection_pool_test.exs | 1 - test/support/channel_case.ex | 16 +------------- test/support/conn_case.ex | 26 +++++------------------ test/support/data_case.ex | 15 +++++++++++-- 4 files changed, 19 insertions(+), 39 deletions(-) diff --git a/test/pleroma/gun/connection_pool_test.exs b/test/pleroma/gun/connection_pool_test.exs index 459d19b11..9cbaf0978 100644 --- a/test/pleroma/gun/connection_pool_test.exs +++ b/test/pleroma/gun/connection_pool_test.exs @@ -19,7 +19,6 @@ defmodule Pleroma.Gun.ConnectionPoolTest do :ok end - setup :set_mox_from_context setup :gun_mock test "gives the same connection to 2 concurrent requests" do diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 6888984a2..1fbf6f100 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -30,19 +30,5 @@ defmodule Pleroma.Web.ChannelCase do end end - setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) - - if tags[:async] do - Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache) - Mox.set_mox_private() - else - Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) - Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) - Mox.set_mox_global() - Pleroma.DataCase.clear_cachex() - end - - :ok - end + setup tags, do: Pleroma.DataCase.setup_multi_process_mode(tags) end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 5b7111fd3..953aa010a 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -19,6 +19,8 @@ defmodule Pleroma.Web.ConnCase do use ExUnit.CaseTemplate + alias Pleroma.DataCase + using do quote do # Import conveniences for testing with connections @@ -116,27 +118,9 @@ defmodule Pleroma.Web.ConnCase do end setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) - - if tags[:async] do - Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache) - Mox.set_mox_private() - else - Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) - Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) - Mox.set_mox_global() - Pleroma.DataCase.clear_cachex() - end - - if tags[:needs_streamer] do - start_supervised(%{ - id: Pleroma.Web.Streamer.registry(), - start: - {Registry, :start_link, [[keys: :duplicate, name: Pleroma.Web.Streamer.registry()]]} - }) - end - - Pleroma.DataCase.stub_pipeline() + DataCase.setup_multi_process_mode(tags) + DataCase.setup_streamer(tags) + DataCase.stub_pipeline() Mox.verify_on_exit!() diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 9db3478bc..c309d2f41 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -62,7 +62,7 @@ defmodule Pleroma.DataCase do end) end - setup tags do + def setup_multi_process_mode(tags) do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) if tags[:async] do @@ -70,11 +70,16 @@ defmodule Pleroma.DataCase do Mox.set_mox_private() else Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) - Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) + Mox.set_mox_global() + Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) clear_cachex() end + :ok + end + + def setup_streamer(tags) do if tags[:needs_streamer] do start_supervised(%{ id: Pleroma.Web.Streamer.registry(), @@ -83,6 +88,12 @@ defmodule Pleroma.DataCase do }) end + :ok + end + + setup tags do + setup_multi_process_mode(tags) + setup_streamer(tags) stub_pipeline() Mox.verify_on_exit!() From e759579f9749ac4198054ddab2d3bb77cc5f04ae Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 19 Jan 2021 16:39:55 -0600 Subject: [PATCH 27/40] Active users must be confirmed --- lib/pleroma/user/query.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pleroma/user/query.ex b/lib/pleroma/user/query.ex index 74ef1158a..4076925aa 100644 --- a/lib/pleroma/user/query.ex +++ b/lib/pleroma/user/query.ex @@ -139,6 +139,7 @@ defmodule Pleroma.User.Query do defp compose_query({:active, _}, query) do User.restrict_deactivated(query) |> where([u], u.is_approved == true) + |> where([u], u.is_confirmed == true) end defp compose_query({:legacy_active, _}, query) do From 87c468f009e048634b705452abbdf2ef489cd055 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 20 Jan 2021 20:07:24 +0300 Subject: [PATCH 28/40] use correct versions for oban migrations --- priv/repo/migrations/20190730055101_add_oban_jobs_table.exs | 5 ++++- priv/repo/migrations/20190917100019_update_oban.exs | 2 +- .../migrations/20200402063221_update_oban_jobs_table.exs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs b/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs index 2f201bd05..5214d59cb 100644 --- a/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs +++ b/priv/repo/migrations/20190730055101_add_oban_jobs_table.exs @@ -1,6 +1,9 @@ defmodule Pleroma.Repo.Migrations.AddObanJobsTable do use Ecto.Migration - defdelegate up, to: Oban.Migrations + def up do + Oban.Migrations.up(version: 2) + end + defdelegate down, to: Oban.Migrations end diff --git a/priv/repo/migrations/20190917100019_update_oban.exs b/priv/repo/migrations/20190917100019_update_oban.exs index 157dc54f9..f673675de 100644 --- a/priv/repo/migrations/20190917100019_update_oban.exs +++ b/priv/repo/migrations/20190917100019_update_oban.exs @@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.UpdateOban do end def down do - Oban.Migrations.down(version: 2) + Oban.Migrations.down(version: 3) end end diff --git a/priv/repo/migrations/20200402063221_update_oban_jobs_table.exs b/priv/repo/migrations/20200402063221_update_oban_jobs_table.exs index e7ff04008..ca6856798 100644 --- a/priv/repo/migrations/20200402063221_update_oban_jobs_table.exs +++ b/priv/repo/migrations/20200402063221_update_oban_jobs_table.exs @@ -6,6 +6,6 @@ defmodule Pleroma.Repo.Migrations.UpdateObanJobsTable do end def down do - Oban.Migrations.down(version: 7) + Oban.Migrations.down(version: 8) end end From 704eef3c2d29c92316f4860c50982512824dd514 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 11:14:15 -0600 Subject: [PATCH 29/40] Special handling for unconfirmed users based on instance config no longer needed. --- lib/pleroma/user.ex | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index d81abbd2b..2aeacf816 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -289,15 +289,7 @@ defmodule Pleroma.User do def account_status(%User{deactivated: true}), do: :deactivated def account_status(%User{password_reset_pending: true}), do: :password_reset_pending def account_status(%User{local: true, is_approved: false}), do: :approval_pending - - def account_status(%User{local: true, is_confirmed: false}) do - if Config.get([:instance, :account_activation_required]) do - :confirmation_pending - else - :active - end - end - + def account_status(%User{local: true, is_confirmed: false}), do: :confirmation_pending def account_status(%User{}), do: :active @spec visible_for(User.t(), User.t() | nil) :: From 3cb4d40ebf9fbf58fac6f9657f799571dc7f318e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 11:17:13 -0600 Subject: [PATCH 30/40] This scenario no longer exists. Users are auto-confirmed if confirmation not required at time of registration. --- test/pleroma/user_test.exs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 617d9b755..a85e89a50 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1830,13 +1830,6 @@ defmodule Pleroma.UserTest do assert User.visible_for(user, other_user) == :visible end - test "returns true when the account is unconfirmed and confirmation is not required" do - user = insert(:user, local: true, is_confirmed: false) - other_user = insert(:user, local: true) - - assert User.visible_for(user, other_user) == :visible - end - test "returns true when the account is unconfirmed and being viewed by a privileged account (confirmation required)" do Pleroma.Config.put([:instance, :account_activation_required], true) From 5d344e5c7965651232c4a20a3a3cc187eb79f18d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 11:26:14 -0600 Subject: [PATCH 31/40] Only need to test if unconfirmed users are successfully deleted It's no longer possible to have an active user account with User.is_confirmed == false --- test/pleroma/user_test.exs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index a85e89a50..7e1e75404 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1563,31 +1563,15 @@ defmodule Pleroma.UserTest do end end - describe "delete/1 when confirmation is pending" do - setup do - user = insert(:user, is_confirmed: false) - {:ok, user: user} - end + test "delete/1 when confirmation is pending deletes the user" do + clear_config([:instance, :account_activation_required], true) + user = insert(:user, is_confirmed: false) - test "deletes user from database when activation required", %{user: user} do - clear_config([:instance, :account_activation_required], true) + {:ok, job} = User.delete(user) + {:ok, _} = ObanHelpers.perform(job) - {:ok, job} = User.delete(user) - {:ok, _} = ObanHelpers.perform(job) - - refute User.get_cached_by_id(user.id) - refute User.get_by_id(user.id) - end - - test "deactivates user when activation is not required", %{user: user} do - clear_config([:instance, :account_activation_required], false) - - {:ok, job} = User.delete(user) - {:ok, _} = ObanHelpers.perform(job) - - assert %{deactivated: true} = User.get_cached_by_id(user.id) - assert %{deactivated: true} = User.get_by_id(user.id) - end + refute User.get_cached_by_id(user.id) + refute User.get_by_id(user.id) end test "delete/1 when approval is pending deletes the user" do From dfc4cb6ebd61754ee5865c33092c5e1b782c12cd Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 11:30:29 -0600 Subject: [PATCH 32/40] Special handling for unconfirmed users based on instance config no longer needed. --- test/pleroma/web/activity_pub/side_effects_test.exs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index e3f45ecdb..13167f50a 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -165,14 +165,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do {:ok, delete: delete_user, user: user} end - test "when activation is not required", %{delete: delete, user: user} do - clear_config([:instance, :account_activation_required], false) - {:ok, _, _} = SideEffects.handle(delete) - ObanHelpers.perform_all() - - assert User.get_cached_by_id(user.id).deactivated - end - test "when activation is required", %{delete: delete, user: user} do clear_config([:instance, :account_activation_required], true) {:ok, _, _} = SideEffects.handle(delete) From 9988d9261c2c933ecb595d0b98790b40f3b44f52 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 16:33:00 -0600 Subject: [PATCH 33/40] Add bucket_namespace to be extra certain truncated_namespace works --- test/pleroma/uploaders/s3_test.exs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/pleroma/uploaders/s3_test.exs b/test/pleroma/uploaders/s3_test.exs index 242dc0d50..991052596 100644 --- a/test/pleroma/uploaders/s3_test.exs +++ b/test/pleroma/uploaders/s3_test.exs @@ -29,6 +29,7 @@ defmodule Pleroma.Uploaders.S3Test do test "it returns path without bucket when truncated_namespace set to ''" do Config.put([Pleroma.Uploaders.S3], bucket: "test_bucket", + bucket_namespace: "myaccount", truncated_namespace: "" ) From 086100e3b7cad827c0f377fdcc4ae9d3b66327c7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 16:39:39 -0600 Subject: [PATCH 34/40] Consistent comment style for :ex_aws --- config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index ef3baed93..dc5964fc9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -79,7 +79,7 @@ config :ex_aws, :s3, # host: "s3.wasabisys.com", # required if not Amazon AWS access_key_id: nil, secret_access_key: nil, - # region: nil, # example: "us-east-1" + # region: "us-east-1", # may be required for Amazon AWS scheme: "https://" config :pleroma, :emoji, From b4ff63d020293bd633bc9c01af1078cacf7f90ed Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Sat, 9 Jan 2021 18:52:40 +0300 Subject: [PATCH 35/40] configurable limits for ConcurrentLimiter Pleroma.Web.RichMedia.Helpers & Pleroma.Web.MediaProxy --- config/config.exs | 5 ++++ config/description.exs | 48 ++++++++++++++++++++++++++++++++ docs/configuration/cheatsheet.md | 12 ++++++++ lib/pleroma/application.ex | 11 +++++++- 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/config/config.exs b/config/config.exs index 70d0c2c2b..e07e67de9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -832,6 +832,11 @@ config :pleroma, Pleroma.User.Backup, limit_days: 7, dir: nil +config :pleroma, ConcurrentLimiter, [ + {Pleroma.Web.RichMedia.Helpers, [max_running: 5, max_waiting: 5]}, + {Pleroma.Web.MediaProxy, [max_running: 5, max_waiting: 5]} +] + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/config/description.exs b/config/description.exs index 493d362d3..49fea4234 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3330,5 +3330,53 @@ config :pleroma, :config_description, [ suggestions: [:text, :protobuf] } ] + }, + %{ + group: :pleroma, + key: ConcurrentLimiter, + type: :group, + description: "Limits configuration for background tasks.", + children: [ + %{ + key: Pleroma.Web.RichMedia.Helpers, + type: :keyword, + description: "Concurrent limits configuration for getting RichMedia for activities.", + suggestions: [max_running: 5, max_waiting: 5], + children: [ + %{ + key: :max_running, + type: :integer, + description: "Max running concurrently jobs.", + suggestion: [5] + }, + %{ + key: :max_waiting, + type: :integer, + description: "Max waiting jobs.", + suggestion: [5] + } + ] + }, + %{ + key: Pleroma.Web.MediaProxy, + type: :keyword, + description: "Concurrent limits configuration for MediaProxyWarmingPolicy.", + suggestions: [max_running: 5, max_waiting: 5], + children: [ + %{ + key: :max_running, + type: :integer, + description: "Max running concurrently jobs.", + suggestion: [5] + }, + %{ + key: :max_waiting, + type: :integer, + description: "Max waiting jobs.", + suggestion: [5] + } + ] + } + ] } ] diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index c7d8a2dae..c7ff8687e 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -1110,3 +1110,15 @@ Settings to enable and configure expiration for ephemeral activities * `:enabled` - enables ephemeral activities creation * `:min_lifetime` - minimum lifetime for ephemeral activities (in seconds). Default: 10 minutes. + +## ConcurrentLimiter + +Settings allow configuring restrictions for concurrently running jobs. Jobs, which can be configured: + +* `Pleroma.Web.RichMedia.Helpers` - configuration for getting RichMedia for activities. +* `Pleroma.Web.MediaProxy` - configuration for MediaProxyWarmingPolicy. + +Each job has these settings: + +* `:max_running` - max concurrently runnings jobs +* `:max_waiting` - max waiting jobs diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 203a95004..4742a3ecb 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -297,7 +297,16 @@ defmodule Pleroma.Application do @spec limiters_setup() :: :ok def limiters_setup do + config = Config.get(ConcurrentLimiter, []) + [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy] - |> Enum.each(&ConcurrentLimiter.new(&1, 1, 0)) + |> Enum.each(fn module -> + mod_config = Keyword.get(config, module, []) + + max_running = Keyword.get(mod_config, :max_running, 5) + max_waiting = Keyword.get(mod_config, :max_waiting, 5) + + ConcurrentLimiter.new(module, max_running, max_waiting) + end) end end From 1537a4f0adfdc079d7d77dbe249c83df5c3b2eef Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 17:01:26 -0600 Subject: [PATCH 36/40] Document ConcurrentLimiter for RichMedia and MediaProxy --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76eab51d4..2ab432d3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - OAuth form improvements: users are remembered by their cookie, the CSS is overridable by the admin, and the style has been improved. - OAuth improvements and fixes: more secure session-based authentication (by token that could be revoked anytime), ability to revoke belonging OAuth token from any client etc. - Ability to set ActivityPub aliases for follower migration. +- Configurable background job limits for RichMedia (link previews) and MediaProxy +
API Changes From dece31a031b8fce5b47c61ad014aa38ae72ee685 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 20 Jan 2021 17:07:00 -0600 Subject: [PATCH 37/40] Update docs --- docs/configuration/cheatsheet.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index c7ff8687e..e7a1b40b1 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -1113,10 +1113,10 @@ Settings to enable and configure expiration for ephemeral activities ## ConcurrentLimiter -Settings allow configuring restrictions for concurrently running jobs. Jobs, which can be configured: +Settings to restrict concurrently running jobs. Jobs which can be configured: -* `Pleroma.Web.RichMedia.Helpers` - configuration for getting RichMedia for activities. -* `Pleroma.Web.MediaProxy` - configuration for MediaProxyWarmingPolicy. +* `Pleroma.Web.RichMedia.Helpers` - generating link previews of URLs in activities +* `Pleroma.Web.MediaProxy` - fetching remote media via MediaProxy Each job has these settings: From 6d48144a9d7273e1b6c253164af5550580a6ea9f Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 21 Jan 2021 09:50:18 +0300 Subject: [PATCH 38/40] use proper naming for MediaProxyWarmingPolicy in ConcurrentLimiter --- config/description.exs | 2 +- docs/configuration/cheatsheet.md | 2 +- lib/pleroma/application.ex | 2 +- lib/pleroma/web/activity_pub/mrf/media_proxy_warming_policy.ex | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/description.exs b/config/description.exs index 49fea4234..715a0d0c3 100644 --- a/config/description.exs +++ b/config/description.exs @@ -3358,7 +3358,7 @@ config :pleroma, :config_description, [ ] }, %{ - key: Pleroma.Web.MediaProxy, + key: Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy, type: :keyword, description: "Concurrent limits configuration for MediaProxyWarmingPolicy.", suggestions: [max_running: 5, max_waiting: 5], diff --git a/docs/configuration/cheatsheet.md b/docs/configuration/cheatsheet.md index e7a1b40b1..5c0fd6487 100644 --- a/docs/configuration/cheatsheet.md +++ b/docs/configuration/cheatsheet.md @@ -1116,7 +1116,7 @@ Settings to enable and configure expiration for ephemeral activities Settings to restrict concurrently running jobs. Jobs which can be configured: * `Pleroma.Web.RichMedia.Helpers` - generating link previews of URLs in activities -* `Pleroma.Web.MediaProxy` - fetching remote media via MediaProxy +* `Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy` - warming remote media cache via MediaProxyWarmingPolicy Each job has these settings: diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 4742a3ecb..9e262235e 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -299,7 +299,7 @@ defmodule Pleroma.Application do def limiters_setup do config = Config.get(ConcurrentLimiter, []) - [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy] + [Pleroma.Web.RichMedia.Helpers, Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy] |> Enum.each(fn module -> mod_config = Keyword.get(config, module, []) diff --git a/lib/pleroma/web/activity_pub/mrf/media_proxy_warming_policy.ex b/lib/pleroma/web/activity_pub/mrf/media_proxy_warming_policy.ex index 50d48edc8..8dbf44071 100644 --- a/lib/pleroma/web/activity_pub/mrf/media_proxy_warming_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/media_proxy_warming_policy.ex @@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do if Pleroma.Config.get(:env) == :test do fetch(prefetch_url) else - ConcurrentLimiter.limit(MediaProxy, fn -> + ConcurrentLimiter.limit(__MODULE__, fn -> Task.start(fn -> fetch(prefetch_url) end) end) end From 5ade430e46e76543b317dc07fdbc0a3fe7367621 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 21 Jan 2021 10:12:01 +0300 Subject: [PATCH 39/40] changed naming in changelog --- CHANGELOG.md | 2 +- config/config.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ab432d3f..e1dfeae01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - OAuth form improvements: users are remembered by their cookie, the CSS is overridable by the admin, and the style has been improved. - OAuth improvements and fixes: more secure session-based authentication (by token that could be revoked anytime), ability to revoke belonging OAuth token from any client etc. - Ability to set ActivityPub aliases for follower migration. -- Configurable background job limits for RichMedia (link previews) and MediaProxy +- Configurable background job limits for RichMedia (link previews) and MediaProxyWarmingPolicy
diff --git a/config/config.exs b/config/config.exs index e07e67de9..c4a690799 100644 --- a/config/config.exs +++ b/config/config.exs @@ -834,7 +834,7 @@ config :pleroma, Pleroma.User.Backup, config :pleroma, ConcurrentLimiter, [ {Pleroma.Web.RichMedia.Helpers, [max_running: 5, max_waiting: 5]}, - {Pleroma.Web.MediaProxy, [max_running: 5, max_waiting: 5]} + {Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy, [max_running: 5, max_waiting: 5]} ] # Import environment specific config. This must remain at the bottom From 80ccdb56f623be21b3ec5b78fc55cee57bee1d2b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 21 Jan 2021 16:49:19 -0600 Subject: [PATCH 40/40] Make tag urls absolute --- CHANGELOG.md | 1 + lib/pleroma/web/mastodon_api/views/status_view.ex | 2 +- test/pleroma/web/mastodon_api/views/status_view_test.exs | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1dfeae01..2727d1f2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Streaming API: Posts and notifications are not dropped, when CLI task is executing. - Creating incorrect IPv4 address-style HTTP links when encountering certain numbers. - Reblog API Endpoint: Do not set visibility parameter to public by default and let CommonAPI to infer it from status, so a user can reblog their private status without explicitly setting reblog visibility to private. +- Tag URLs in statuses are now absolute
API Changes diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index cd1a85088..2cd6732fe 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -491,7 +491,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def build_tags(object_tags) when is_list(object_tags) do object_tags |> Enum.filter(&is_binary/1) - |> Enum.map(&%{name: &1, url: "/tag/#{URI.encode(&1)}"}) + |> Enum.map(&%{name: &1, url: "#{Pleroma.Web.base_url()}/tag/#{URI.encode(&1)}"}) end def build_tags(_), do: [] diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index 21a01658e..ed59cf285 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -263,7 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do tags: [ %{ name: "#{object_data["tag"]}", - url: "/tag/#{object_data["tag"]}" + url: "http://localhost:4001/tag/#{object_data["tag"]}" } ], application: %{ @@ -585,9 +585,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do ] assert StatusView.build_tags(object_tags) == [ - %{name: "fediverse", url: "/tag/fediverse"}, - %{name: "mastodon", url: "/tag/mastodon"}, - %{name: "nextcloud", url: "/tag/nextcloud"} + %{name: "fediverse", url: "http://localhost:4001/tag/fediverse"}, + %{name: "mastodon", url: "http://localhost:4001/tag/mastodon"}, + %{name: "nextcloud", url: "http://localhost:4001/tag/nextcloud"} ] end end