From 34606d609d5761f4d0b7e46965a87344c84065d6 Mon Sep 17 00:00:00 2001 From: kPherox Date: Mon, 9 Aug 2021 09:03:58 +0000 Subject: [PATCH 01/15] fix: stream out Create Activity Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3499 --- CHANGELOG.md | 7 ++++++- lib/pleroma/web/activity_pub/side_effects.ex | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e3e40864..d6bf12d41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Removed -## 2.4.0 - 2021-08-xx +## 2.4.1 + +### Fixed +- MastodonAPI: Stream out Create activities + +## 2.4.0 - 2021-08-08 ### Changed diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index b0ec84ade..b82a89896 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -10,7 +10,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do collection, and so on. """ alias Pleroma.Activity - alias Pleroma.Activity.Ir.Topics alias Pleroma.Chat alias Pleroma.Chat.MessageReference alias Pleroma.FollowingRelationship @@ -225,6 +224,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do meta |> add_notifications(notifications) + ap_streamer().stream_out(activity) + {:ok, activity, meta} else e -> Repo.rollback(e) @@ -245,9 +246,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do if !User.is_internal_user?(user) do Notification.create_notifications(object) - object - |> Topics.get_activity_topics() - |> Streamer.stream(object) + ap_streamer().stream_out(object) end {:ok, object, meta} From 1cf89de89a87f7bdc9e1436a010e9bdb50d16c6f Mon Sep 17 00:00:00 2001 From: Ilja Date: Tue, 10 Aug 2021 06:09:31 +0000 Subject: [PATCH 02/15] Make the OPT recomendation clearer AFAIK OTP releases are the recomended way of installing, but * People seem unaware of that and use from source installations because they use the guide with the name of their distro * People don't know what OTP releases are or what it means I added a warning on all installation-from-source guides and added the same explanation on the two OTP pages (the miigration to OTP and installing OTP) Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3485 --- docs/installation/alpine_linux_en.md | 3 +++ docs/installation/arch_linux_en.md | 3 +++ docs/installation/debian_based_en.md | 3 +++ docs/installation/gentoo_en.md | 3 +++ docs/installation/migrating_from_source_otp_en.md | 5 +++-- docs/installation/otp_en.md | 4 ++++ docs/installation/otp_vs_from_source.include | 3 +++ docs/installation/otp_vs_from_source_source.include | 3 +++ 8 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 docs/installation/otp_vs_from_source.include create mode 100644 docs/installation/otp_vs_from_source_source.include diff --git a/docs/installation/alpine_linux_en.md b/docs/installation/alpine_linux_en.md index 13395ff25..c37ff0c63 100644 --- a/docs/installation/alpine_linux_en.md +++ b/docs/installation/alpine_linux_en.md @@ -1,4 +1,7 @@ # Installing on Alpine Linux + +{! backend/installation/otp_vs_from_source_source.include !} + ## Installation This guide is a step-by-step installation guide for Alpine Linux. The instructions were verified against Alpine v3.10 standard image. You might miss additional dependencies if you use `netboot` instead. diff --git a/docs/installation/arch_linux_en.md b/docs/installation/arch_linux_en.md index d11deb621..285743d56 100644 --- a/docs/installation/arch_linux_en.md +++ b/docs/installation/arch_linux_en.md @@ -1,4 +1,7 @@ # Installing on Arch Linux + +{! backend/installation/otp_vs_from_source_source.include !} + ## Installation This guide will assume that you have administrative rights, either as root or a user with [sudo permissions](https://wiki.archlinux.org/index.php/Sudo). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su -s $SHELL -c 'command'` instead. diff --git a/docs/installation/debian_based_en.md b/docs/installation/debian_based_en.md index 02682e5b0..4e52b2155 100644 --- a/docs/installation/debian_based_en.md +++ b/docs/installation/debian_based_en.md @@ -1,4 +1,7 @@ # Installing on Debian Based Distributions + +{! backend/installation/otp_vs_from_source_source.include !} + ## Installation This guide will assume you are on Debian 11 (“bullseye”) or later. This guide should also work with Ubuntu 18.04 (“Bionic Beaver”) and later. It also assumes that you have administrative rights, either as root or a user with [sudo permissions](https://www.digitalocean.com/community/tutorials/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su -s $SHELL -c 'command'` instead. diff --git a/docs/installation/gentoo_en.md b/docs/installation/gentoo_en.md index 982ab52d2..36882c8c8 100644 --- a/docs/installation/gentoo_en.md +++ b/docs/installation/gentoo_en.md @@ -1,4 +1,7 @@ # Installing on Gentoo GNU/Linux + +{! backend/installation/otp_vs_from_source_source.include !} + ## Installation This guide will assume that you have administrative rights, either as root or a user with [sudo permissions](https://wiki.gentoo.org/wiki/Sudo). Lines that begin with `#` indicate that they should be run as the superuser. Lines using `$` should be run as the indicated user, e.g. `pleroma$` should be run as the `pleroma` user. diff --git a/docs/installation/migrating_from_source_otp_en.md b/docs/installation/migrating_from_source_otp_en.md index d303a6daf..e4a01d8db 100644 --- a/docs/installation/migrating_from_source_otp_en.md +++ b/docs/installation/migrating_from_source_otp_en.md @@ -1,7 +1,8 @@ # Switching a from-source install to OTP releases -## What are OTP releases? -OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it, it is easily administered via the provided shell script to open up a remote console, start/stop/restart the release, start in the background, send remote commands, and more. +{! backend/installation/otp_vs_from_source.include !} + +In this guide we cover how you can migrate from a from source installation to one using OTP releases. ## Pre-requisites You will be running commands as root. If you aren't root already, please elevate your priviledges by executing `sudo su`/`su`. diff --git a/docs/installation/otp_en.md b/docs/installation/otp_en.md index 3f67534ac..0861a8157 100644 --- a/docs/installation/otp_en.md +++ b/docs/installation/otp_en.md @@ -1,5 +1,9 @@ # Installing on Linux using OTP releases +{! backend/installation/otp_vs_from_source.include !} + +This guide covers a installation using an OTP release. To install Pleroma from source, please check out the corresponding guide for your distro. + ## Pre-requisites * A machine running Linux with GNU (e.g. Debian, Ubuntu) or musl (e.g. Alpine) libc and `x86_64`, `aarch64` or `armv7l` CPU, you have root access to. If you are not sure if it's compatible see [Detecting flavour section](#detecting-flavour) below * A (sub)domain pointed to the machine diff --git a/docs/installation/otp_vs_from_source.include b/docs/installation/otp_vs_from_source.include new file mode 100644 index 000000000..63e837a53 --- /dev/null +++ b/docs/installation/otp_vs_from_source.include @@ -0,0 +1,3 @@ +## OTP releases vs from-source installations + +There are two ways to install Pleroma. You can use OTP releases or do a from-source installation. OTP releases are as close as you can get to binary releases with Erlang/Elixir. The release is self-contained, and provides everything needed to boot it, it is easily administered via the provided shell script to open up a remote console, start/stop/restart the release, start in the background, send remote commands, and more. With from source installations you install Pleroma from source, meaning you have to install certain dependencies like Erlang+Elixir and compile Pleroma yourself. diff --git a/docs/installation/otp_vs_from_source_source.include b/docs/installation/otp_vs_from_source_source.include new file mode 100644 index 000000000..63482b69d --- /dev/null +++ b/docs/installation/otp_vs_from_source_source.include @@ -0,0 +1,3 @@ +{! backend/installation/otp_vs_from_source.include !} + +This guide covers a from-source installation. To install using OTP releases, please check out [the OTP guide](./otp_en.md). From 8baaa36a16d9fd720e5ca455b80e0ffeba245030 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 10 Aug 2021 07:41:06 +0200 Subject: [PATCH 03/15] ObjectAgePolicy: Fix pattern matching on published Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3500 --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/mrf/object_age_policy.ex | 6 +++++- test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6bf12d41..0756d5223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - MastodonAPI: Stream out Create activities +- MRF ObjectAgePolicy: Fix pattern matching on "published" ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/activity_pub/mrf/object_age_policy.ex b/lib/pleroma/web/activity_pub/mrf/object_age_policy.ex index 9a211fd44..02c9b18ed 100644 --- a/lib/pleroma/web/activity_pub/mrf/object_age_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/object_age_policy.ex @@ -49,6 +49,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do message |> Map.put("to", to) |> Map.put("cc", cc) + |> Kernel.put_in(["object", "to"], to) + |> Kernel.put_in(["object", "cc"], cc) {:ok, message} else @@ -70,6 +72,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do message |> Map.put("to", to) |> Map.put("cc", cc) + |> Kernel.put_in(["object", "to"], to) + |> Kernel.put_in(["object", "cc"], cc) {:ok, message} else @@ -82,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do end @impl true - def filter(%{"type" => "Create", "published" => _} = message) do + def filter(%{"type" => "Create", "object" => %{"published" => _}} = message) do with actions <- Config.get([:mrf_object_age, :actions]), {:reject, _} <- check_date(message), {:ok, message} <- check_reject(message, actions), diff --git a/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs b/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs index 137aafd39..2f649a0a4 100644 --- a/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs @@ -22,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do defp get_old_message do File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() + |> Map.drop(["published"]) end defp get_new_message do From 3961422f853934a598a36d3ec10659158affb6ed Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 10 Aug 2021 19:42:03 +0200 Subject: [PATCH 04/15] TwitterAPI: Make change_password require body params instead of query Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3503 --- CHANGELOG.md | 1 + .../api_spec/operations/twitter_util_operation.ex | 31 ++++++--- .../web/twitter_api/controllers/util_controller.ex | 12 ++-- .../web/twitter_api/util_controller_test.exs | 80 ++++++++++------------ 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0756d5223..14e04c053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - MastodonAPI: Stream out Create activities - MRF ObjectAgePolicy: Fix pattern matching on "published" +- TwitterAPI: Make `change_password` require params on body instead of query ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex index 0cafbc719..bc54f1915 100644 --- a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex +++ b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex @@ -8,6 +8,8 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do alias Pleroma.Web.ApiSpec.Schemas.ApiError alias Pleroma.Web.ApiSpec.Schemas.BooleanLike + import Pleroma.Web.ApiSpec.Helpers + def open_api_operation(action) do operation = String.to_existing_atom("#{action}_operation") apply(__MODULE__, operation, []) @@ -63,17 +65,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do summary: "Change account password", security: [%{"oAuth" => ["write:accounts"]}], operationId: "UtilController.change_password", - parameters: [ - Operation.parameter(:password, :query, :string, "Current password", required: true), - Operation.parameter(:new_password, :query, :string, "New password", required: true), - Operation.parameter( - :new_password_confirmation, - :query, - :string, - "New password, confirmation", - required: true - ) - ], + requestBody: request_body("Parameters", change_password_request(), required: true), responses: %{ 200 => Operation.response("Success", "application/json", %Schema{ @@ -86,6 +78,23 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do } end + defp change_password_request do + %Schema{ + title: "ChangePasswordRequest", + description: "POST body for changing the account's passowrd", + type: :object, + required: [:password, :new_password, :new_password_confirmation], + properties: %{ + password: %Schema{type: :string, description: "Current password"}, + new_password: %Schema{type: :string, description: "New password"}, + new_password_confirmation: %Schema{ + type: :string, + description: "New password, confirmation" + } + } + } + end + def change_email_operation do %Operation{ tags: ["Account credentials"], diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index a2e69666e..58a733258 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -81,17 +81,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end end - def change_password(%{assigns: %{user: user}} = conn, %{ - password: password, - new_password: new_password, - new_password_confirmation: new_password_confirmation - }) do - case CommonAPI.Utils.confirm_current_password(user, password) do + def change_password(%{assigns: %{user: user}, body_params: body_params} = conn, %{}) do + case CommonAPI.Utils.confirm_current_password(user, body_params.password) do {:ok, user} -> with {:ok, _user} <- User.reset_password(user, %{ - password: new_password, - password_confirmation: new_password_confirmation + password: body_params.new_password, + password_confirmation: body_params.new_password_confirmation }) do json(conn, %{status: "success"}) else diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs index cc17940b5..fe3d99272 100644 --- a/test/pleroma/web/twitter_api/util_controller_test.exs +++ b/test/pleroma/web/twitter_api/util_controller_test.exs @@ -356,15 +356,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn = conn |> assign(:token, nil) - |> post( - "/api/pleroma/change_password?#{ - URI.encode_query(%{ - password: "hi", - new_password: "newpass", - new_password_confirmation: "newpass" - }) - }" - ) + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_password", %{ + "password" => "hi", + "new_password" => "newpass", + "new_password_confirmation" => "newpass" + }) assert json_response_and_validate_schema(conn, 403) == %{ "error" => "Insufficient permissions: write:accounts." @@ -373,16 +370,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do test "with proper permissions and invalid password", %{conn: conn} do conn = - post( - conn, - "/api/pleroma/change_password?#{ - URI.encode_query(%{ - password: "hi", - new_password: "newpass", - new_password_confirmation: "newpass" - }) - }" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_password", %{ + "password" => "hi", + "new_password" => "newpass", + "new_password_confirmation" => "newpass" + }) assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."} end @@ -392,16 +386,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn: conn } do conn = - post( - conn, - "/api/pleroma/change_password?#{ - URI.encode_query(%{ - password: "test", - new_password: "newpass", - new_password_confirmation: "notnewpass" - }) - }" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_password", %{ + "password" => "test", + "new_password" => "newpass", + "new_password_confirmation" => "notnewpass" + }) assert json_response_and_validate_schema(conn, 200) == %{ "error" => "New password does not match confirmation." @@ -412,12 +403,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn: conn } do conn = - post( - conn, - "/api/pleroma/change_password?#{ - URI.encode_query(%{password: "test", new_password: "", new_password_confirmation: ""}) - }" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_password", %{ + password: "test", + new_password: "", + new_password_confirmation: "" + }) assert json_response_and_validate_schema(conn, 200) == %{ "error" => "New password can't be blank." @@ -429,15 +421,15 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user: user } do conn = - post( - conn, - "/api/pleroma/change_password?#{ - URI.encode_query(%{ - password: "test", - new_password: "newpass", - new_password_confirmation: "newpass" - }) - }" + conn + |> put_req_header("content-type", "multipart/form-data") + |> post( + "/api/pleroma/change_password", + %{ + password: "test", + new_password: "newpass", + new_password_confirmation: "newpass" + } ) assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"} From 0e2aebd036fd49386f373327d933dd380b14b649 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 10 Aug 2021 20:33:00 +0200 Subject: [PATCH 05/15] TwitterAPI: Make change_email require body params instead of query Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3503 --- CHANGELOG.md | 2 +- .../api_spec/operations/twitter_util_operation.ex | 19 +++++--- .../web/twitter_api/controllers/util_controller.ex | 6 +-- .../web/twitter_api/util_controller_test.exs | 51 +++++++++------------- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e04c053..13469d8d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - MastodonAPI: Stream out Create activities - MRF ObjectAgePolicy: Fix pattern matching on "published" -- TwitterAPI: Make `change_password` require params on body instead of query +- TwitterAPI: Make `change_password` and `change_email` require params on body instead of query ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex index bc54f1915..879b2227e 100644 --- a/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex +++ b/lib/pleroma/web/api_spec/operations/twitter_util_operation.ex @@ -101,11 +101,7 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do summary: "Change account email", security: [%{"oAuth" => ["write:accounts"]}], operationId: "UtilController.change_email", - parameters: [ - Operation.parameter(:password, :query, :string, "Current password", required: true), - Operation.parameter(:email, :query, :string, "New email", required: true) - ], - requestBody: nil, + requestBody: request_body("Parameters", change_email_request(), required: true), responses: %{ 200 => Operation.response("Success", "application/json", %Schema{ @@ -118,6 +114,19 @@ defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do } end + defp change_email_request do + %Schema{ + title: "ChangeEmailRequest", + description: "POST body for changing the account's email", + type: :object, + required: [:email, :password], + properties: %{ + email: %Schema{type: :string, description: "New email"}, + password: %Schema{type: :string, description: "Current password"} + } + } + end + def update_notificaton_settings_operation do %Operation{ tags: ["Accounts"], diff --git a/lib/pleroma/web/twitter_api/controllers/util_controller.ex b/lib/pleroma/web/twitter_api/controllers/util_controller.ex index 58a733258..ef43f7682 100644 --- a/lib/pleroma/web/twitter_api/controllers/util_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/util_controller.ex @@ -104,10 +104,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do end end - def change_email(%{assigns: %{user: user}} = conn, %{password: password, email: email}) do - case CommonAPI.Utils.confirm_current_password(user, password) do + def change_email(%{assigns: %{user: user}, body_params: body_params} = conn, %{}) do + case CommonAPI.Utils.confirm_current_password(user, body_params.password) do {:ok, user} -> - with {:ok, _user} <- User.change_email(user, email) do + with {:ok, _user} <- User.change_email(user, body_params.email) do json(conn, %{status: "success"}) else {:error, changeset} -> diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs index fe3d99272..f030483d8 100644 --- a/test/pleroma/web/twitter_api/util_controller_test.exs +++ b/test/pleroma/web/twitter_api/util_controller_test.exs @@ -261,11 +261,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn = conn |> assign(:token, nil) - |> post( - "/api/pleroma/change_email?#{ - URI.encode_query(%{password: "hi", email: "test@test.com"}) - }" - ) + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"}) assert json_response_and_validate_schema(conn, 403) == %{ "error" => "Insufficient permissions: write:accounts." @@ -274,12 +271,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do test "with proper permissions and invalid password", %{conn: conn} do conn = - post( - conn, - "/api/pleroma/change_email?#{ - URI.encode_query(%{password: "hi", email: "test@test.com"}) - }" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "hi", email: "test@test.com"}) assert json_response_and_validate_schema(conn, 200) == %{"error" => "Invalid password."} end @@ -288,10 +282,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn: conn } do conn = - post( - conn, - "/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: "foobar"})}" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "test", email: "foobar"}) assert json_response_and_validate_schema(conn, 200) == %{ "error" => "Email has invalid format." @@ -301,7 +294,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do test "with proper permissions, valid password and no email", %{ conn: conn } do - conn = post(conn, "/api/pleroma/change_email?#{URI.encode_query(%{password: "test"})}") + conn = + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "test"}) assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400) end @@ -310,10 +306,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn: conn } do conn = - post( - conn, - "/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: ""})}" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "test", email: ""}) assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."} end @@ -324,10 +319,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user = insert(:user) conn = - post( - conn, - "/api/pleroma/change_email?#{URI.encode_query(%{password: "test", email: user.email})}" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "test", email: user.email}) assert json_response_and_validate_schema(conn, 200) == %{ "error" => "Email has already been taken." @@ -338,12 +332,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do conn: conn } do conn = - post( - conn, - "/api/pleroma/change_email?#{ - URI.encode_query(%{password: "test", email: "cofe@foobar.com"}) - }" - ) + conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/change_email", %{password: "test", email: "cofe@foobar.com"}) assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"} end From bb2d5879cc1275ebc552e704589cf608bb91a43d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Wed, 11 Aug 2021 19:45:49 +0200 Subject: [PATCH 06/15] maybe_notify_subscribers: Don't create notifications from ingested replies Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3505 --- CHANGELOG.md | 1 + lib/pleroma/web/common_api/utils.ex | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13469d8d8..05c05b814 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - MastodonAPI: Stream out Create activities - MRF ObjectAgePolicy: Fix pattern matching on "published" - TwitterAPI: Make `change_password` and `change_email` require params on body instead of query +- Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 33639e695..10eb48250 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -412,19 +412,14 @@ defmodule Pleroma.Web.CommonAPI.Utils do def maybe_notify_mentioned_recipients(recipients, _), do: recipients - # Do not notify subscribers if author is making a reply - def maybe_notify_subscribers(recipients, %Activity{ - object: %Object{data: %{"inReplyTo" => _ap_id}} - }) do - recipients - end - def maybe_notify_subscribers( recipients, - %Activity{data: %{"actor" => actor, "type" => type}} = activity - ) - when type == "Create" do - with %User{} = user <- User.get_cached_by_ap_id(actor) do + %Activity{data: %{"actor" => actor, "type" => "Create"}} = activity + ) do + # Do not notify subscribers if author is making a reply + with %Object{data: object} <- Object.normalize(activity, fetch: false), + nil <- object["inReplyTo"], + %User{} = user <- User.get_cached_by_ap_id(actor) do subscriber_ids = user |> User.subscriber_users() From e1175511693973ef0c5b21ea70e517893f61f4e1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 11 Aug 2021 09:38:16 -0500 Subject: [PATCH 07/15] AdminAPI: hotfix for nil report objects Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3504 --- CHANGELOG.md | 1 + lib/pleroma/web/admin_api/report.ex | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c05b814..6cdb665d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - MRF ObjectAgePolicy: Fix pattern matching on "published" - TwitterAPI: Make `change_password` and `change_email` require params on body instead of query - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies +- AdminAPI: Fix rendering reports containing a `nil` object ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/admin_api/report.ex b/lib/pleroma/web/admin_api/report.ex index 259068f04..345bc1e87 100644 --- a/lib/pleroma/web/admin_api/report.ex +++ b/lib/pleroma/web/admin_api/report.ex @@ -13,7 +13,9 @@ defmodule Pleroma.Web.AdminAPI.Report do account = User.get_cached_by_ap_id(account_ap_id) statuses = - Enum.map(status_ap_ids, fn + status_ap_ids + |> Enum.reject(&is_nil(&1)) + |> Enum.map(fn act when is_map(act) -> Activity.get_by_ap_id_with_object(act["id"]) act when is_binary(act) -> Activity.get_by_ap_id_with_object(act) end) From 27e1e4c742bb37a89e0ca91fda03b5ca8be3984a Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Thu, 12 Aug 2021 10:29:53 +0200 Subject: [PATCH 08/15] Activity.Search: fallback on status resolution on DB Timeout Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3507 --- CHANGELOG.md | 1 + lib/pleroma/activity/search.ex | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cdb665d1..369a8bbdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - TwitterAPI: Make `change_password` and `change_email` require params on body instead of query - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies - AdminAPI: Fix rendering reports containing a `nil` object +- Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex index ed898ba4f..a5923519c 100644 --- a/lib/pleroma/activity/search.ex +++ b/lib/pleroma/activity/search.ex @@ -26,19 +26,23 @@ defmodule Pleroma.Activity.Search do :plain end - Activity - |> Activity.with_preloaded_object() - |> Activity.restrict_deactivated_users() - |> restrict_public() - |> query_with(index_type, search_query, search_function) - |> maybe_restrict_local(user) - |> maybe_restrict_author(author) - |> maybe_restrict_blocked(user) - |> Pagination.fetch_paginated( - %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum}, - :offset - ) - |> maybe_fetch(user, search_query) + try do + Activity + |> Activity.with_preloaded_object() + |> Activity.restrict_deactivated_users() + |> restrict_public() + |> query_with(index_type, search_query, search_function) + |> maybe_restrict_local(user) + |> maybe_restrict_author(author) + |> maybe_restrict_blocked(user) + |> Pagination.fetch_paginated( + %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum}, + :offset + ) + |> maybe_fetch(user, search_query) + rescue + _ -> maybe_fetch([], user, search_query) + end end def maybe_restrict_author(query, %User{} = author) do From 01175ef4988e98aa38851e77703ffc60a3756fdd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 13 Aug 2021 10:25:42 -0500 Subject: [PATCH 09/15] Streamer: fix crash in MastodonAPI.StatusView Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3508 --- CHANGELOG.md | 1 + lib/pleroma/web/mastodon_api/views/status_view.ex | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 369a8bbdd..f06bbfdf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies - AdminAPI: Fix rendering reports containing a `nil` object - Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error +- Mastodon API: Fix crash in Streamer related to reblogging ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index da44e0a74..463f34198 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -65,11 +65,19 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do defp get_context_id(_), do: nil - defp reblogged?(activity, user) do - object = Object.normalize(activity, fetch: false) || %{} - present?(user && user.ap_id in (object.data["announcements"] || [])) + # Check if the user reblogged this status + defp reblogged?(activity, %User{ap_id: ap_id}) do + with %Object{data: %{"announcements" => announcements}} when is_list(announcements) <- + Object.normalize(activity, fetch: false) do + ap_id in announcements + else + _ -> false + end end + # False if the user is logged out + defp reblogged?(_activity, _user), do: false + def render("index.json", opts) do reading_user = opts[:for] From 09c42ce13e68b78075822a78026300d754e05d22 Mon Sep 17 00:00:00 2001 From: Sam Therapy Date: Sat, 14 Aug 2021 11:08:39 -0500 Subject: [PATCH 10/15] Add Admin-FE menu for StealEmojiPolicy Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3512 --- CHANGELOG.md | 3 ++ .../web/activity_pub/mrf/steal_emoji_policy.ex | 45 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f06bbfdf0..02d9d59cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## 2.4.1 +### Added +- AdminAPI: Missing configuration description for StealEmojiPolicy + ### Fixed - MastodonAPI: Stream out Create activities - MRF ObjectAgePolicy: Fix pattern matching on "published" diff --git a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex index c28f14a41..fbe9795ac 100644 --- a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex @@ -93,6 +93,51 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do def filter(message), do: {:ok, message} @impl true + @spec config_description :: %{ + children: [ + %{ + description: <<_::272, _::_*256>>, + key: :hosts | :rejected_shortcodes | :size_limit, + suggestions: [any(), ...], + type: {:list, :string} | {:list, :string} | :integer + }, + ... + ], + description: <<_::448>>, + key: :mrf_steal_emoji, + label: <<_::80>>, + related_policy: <<_::352>> + } + def config_description do + %{ + key: :mrf_steal_emoji, + related_policy: "Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy", + label: "MRF Emojis", + description: "Steals emojis from selected instances when it sees them.", + children: [ + %{ + key: :hosts, + type: {:list, :string}, + description: "List of hosts to steal emojis from", + suggestions: [""] + }, + %{ + key: :rejected_shortcodes, + type: {:list, :string}, + description: "Regex-list of shortcodes to reject", + suggestions: [""] + }, + %{ + key: :size_limit, + type: :integer, + description: "File size limit (in bytes), checked before an emoji is saved to the disk", + suggestions: ["100000"] + } + ] + } + end + + @impl true def describe do {:ok, %{}} end From 53b0dd4ecc9f7f23983082cf610156f0840443a9 Mon Sep 17 00:00:00 2001 From: Ilja Date: Sat, 14 Aug 2021 18:42:12 +0000 Subject: [PATCH 11/15] List available frontends also when no static/frontends folder is present yet * To see what front ends are installed, it ls static/frontends. When this folder doesn't exists yet, it will return an empty array. * Installing still works since the folder is created during installation already Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3510 --- CHANGELOG.md | 1 + .../web/admin_api/controllers/frontend_controller.ex | 8 +++++++- .../web/admin_api/controllers/frontend_controller_test.exs | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02d9d59cb..90e0ca82a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - AdminAPI: Fix rendering reports containing a `nil` object - Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error - Mastodon API: Fix crash in Streamer related to reblogging +- AdminAPI: List available frontends when `static/frontends` folder is missing ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/admin_api/controllers/frontend_controller.ex b/lib/pleroma/web/admin_api/controllers/frontend_controller.ex index 722f51bd2..442e6a5a0 100644 --- a/lib/pleroma/web/admin_api/controllers/frontend_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/frontend_controller.ex @@ -35,6 +35,12 @@ defmodule Pleroma.Web.AdminAPI.FrontendController do end defp installed do - File.ls!(Pleroma.Frontend.dir()) + frontend_directory = Pleroma.Frontend.dir() + + if File.exists?(frontend_directory) do + File.ls!(frontend_directory) + else + [] + end end end diff --git a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs index bc827cc12..200682ba9 100644 --- a/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/frontend_controller_test.exs @@ -42,6 +42,20 @@ defmodule Pleroma.Web.AdminAPI.FrontendControllerTest do refute Enum.any?(response, fn frontend -> frontend["installed"] == true end) end + + test "it lists available frontends when no frontend folder was created yet", %{conn: conn} do + File.rm_rf(@dir) + + response = + conn + |> get("/api/pleroma/admin/frontends") + |> json_response_and_validate_schema(:ok) + + assert Enum.map(response, & &1["name"]) == + Enum.map(Config.get([:frontends, :available]), fn {_, map} -> map["name"] end) + + refute Enum.any?(response, fn frontend -> frontend["installed"] == true end) + end end describe "POST /api/pleroma/admin/frontends/install" do From bd0eb1c675c5a70e7ae97c17f6fa88e534776ca5 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Fri, 27 Aug 2021 21:43:50 -0400 Subject: [PATCH 12/15] Make activity search properly use GIN indexes The original approach to search in GIN indexes is to use `to_tsvector(text)` in the WHERE clause of the query. According to postgres docs [pdoc], this method does not make use of the index, while `to_tsvector(config, text)` does. This commit changed the query to use the two-argument `to_tsvector()`. [pdoc]: https://www.postgresql.org/docs/12/textsearch-tables.html To obtain the search config in use, we make a query to the db first. The `::regconfig::oid` hack is needed because Postgrex does not support regconfig type directly [postgrexbug]. I use the conversion from and to `oid` instead of `text` because I tested in the actual DB and querying using the conversion via `text` is slow just as the one-argument `to_tsvector()` variant. [postgrexbug]: https://github.com/elixir-ecto/postgrex/issues/502 Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3519 Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/2758 --- CHANGELOG.md | 1 + lib/pleroma/activity/search.ex | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90e0ca82a..660920565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error - Mastodon API: Fix crash in Streamer related to reblogging - AdminAPI: List available frontends when `static/frontends` folder is missing +- Make activity search properly use language-aware GIN indexes ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex index a5923519c..09671f621 100644 --- a/lib/pleroma/activity/search.ex +++ b/lib/pleroma/activity/search.ex @@ -65,10 +65,17 @@ defmodule Pleroma.Activity.Search do end defp query_with(q, :gin, search_query, :plain) do + %{rows: [[tsc]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + "select current_setting('default_text_search_config')::regconfig::oid;" + ) + from([a, o] in q, where: fragment( - "to_tsvector(?->>'content') @@ plainto_tsquery(?)", + "to_tsvector(?::oid::regconfig, ?->>'content') @@ plainto_tsquery(?)", + ^tsc, o.data, ^search_query ) @@ -76,10 +83,17 @@ defmodule Pleroma.Activity.Search do end defp query_with(q, :gin, search_query, :websearch) do + %{rows: [[tsc]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + "select current_setting('default_text_search_config')::regconfig::oid;" + ) + from([a, o] in q, where: fragment( - "to_tsvector(?->>'content') @@ websearch_to_tsquery(?)", + "to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)", + ^tsc, o.data, ^search_query ) From 20084329ea4dc2f978c6451c46ed76995064b864 Mon Sep 17 00:00:00 2001 From: Ilja Date: Sat, 14 Aug 2021 13:42:32 +0200 Subject: [PATCH 13/15] Selecting MRF policies didn't work as intended any more * Policies were put under a new module (Pleroma.Web.ActivityPub.MRF.Policy instead of Pleroma.Web.ActivityPub.MRF), but this wasn't changed in the Pleroma.Web.ActivityPub.MRF @mrf_config_descriptions * I don't have a unit test to prevent similar problems in the future because I don't find a proper way to do it * The descriptions in the unit tests are defined in the unit tests, so if someone changes module names in the code, the tests wont see it * The list is generated in Pleroma.Docs.Generator.list_behaviour_implementations, but I can't do a check in the when clause of the function to see if the provided module is a behaviour or not. Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3509 --- CHANGELOG.md | 1 + lib/pleroma/web/activity_pub/mrf.ex | 2 +- test/pleroma/docs/generator_test.exs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 660920565..c54fa9498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Mastodon API: Fix crash in Streamer related to reblogging - AdminAPI: List available frontends when `static/frontends` folder is missing - Make activity search properly use language-aware GIN indexes +- AdminAPI: Fix suggestions for MRF Policies ## 2.4.0 - 2021-08-08 diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index ac00fa54b..41592e71e 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF do type: [:module, {:list, :module}], description: "A list of MRF policies enabled. Module names are shortened (removed leading `Pleroma.Web.ActivityPub.MRF.` part), but on adding custom module you need to use full name.", - suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF} + suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF.Policy} }, %{ key: :transparency, diff --git a/test/pleroma/docs/generator_test.exs b/test/pleroma/docs/generator_test.exs index a9b09e577..8574c1d5e 100644 --- a/test/pleroma/docs/generator_test.exs +++ b/test/pleroma/docs/generator_test.exs @@ -23,7 +23,7 @@ defmodule Pleroma.Docs.GeneratorTest do key: :filters, type: {:list, :module}, description: "", - suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF} + suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF.Policy} }, %{ key: Pleroma.Upload, From cc4f20b1307f5b308369ea20541df10e1e2a239c Mon Sep 17 00:00:00 2001 From: someone Date: Sun, 15 Aug 2021 13:49:12 -0400 Subject: [PATCH 14/15] mix pleroma.database set_text_search_config now runs concurrently and infinitely Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3514 --- CHANGELOG.md | 3 +++ docs/configuration/howto_search_cjk.md | 4 ++-- lib/mix/tasks/pleroma/database.ex | 8 ++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c54fa9498..dfb83abbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## 2.4.1 +### Changed +- Make `mix pleroma.database set_text_search_config` run concurrently and indefinitely + ### Added - AdminAPI: Missing configuration description for StealEmojiPolicy diff --git a/docs/configuration/howto_search_cjk.md b/docs/configuration/howto_search_cjk.md index d3ce28077..a73b10db3 100644 --- a/docs/configuration/howto_search_cjk.md +++ b/docs/configuration/howto_search_cjk.md @@ -5,7 +5,7 @@ Pleroma's full text search feature is powered by PostgreSQL's native [text searc ## Setup and test the new search config -In most cases, you would need an extension installed to support parsing CJK text. Here are a few extension you may choose from, or you are more than welcome to share additional ones you found working for you with the rest of Pleroma community. +In most cases, you would need an extension installed to support parsing CJK text. Here are a few extensions you may choose from, or you are more than welcome to share additional ones you found working for you with the rest of Pleroma community. * [a generic n-gram parser](https://github.com/huangjimmy/pg_cjk_parser) supports Simplifed/Traditional Chinese, Japanese, and Korean * [a Korean parser](https://github.com/i0seph/textsearch_ko) based on mecab @@ -34,7 +34,7 @@ Check output of the query, and see if it matches your expectation. mix pleroma.database set_text_search_config YOUR.CONFIG ``` -Note: index update may take a while. +Note: index update may take a while, and it can be done while the instance is up and running, so you may restart db connection as soon as you see `Recreate index` in task output. ## Restart database connection Since some changes above will only apply with a new database connection, you will have to restart either Pleroma or PostgreSQL process, or use `pg_terminate_backend` SQL command without restarting either. diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index 57f73d12b..a973beaa9 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -209,7 +209,9 @@ defmodule Mix.Tasks.Pleroma.Database do new.fts_content := to_tsvector(new.data->>'content'); RETURN new; END - $$ LANGUAGE plpgsql" + $$ LANGUAGE plpgsql", + [], + timeout: :infinity ) shell_info("Refresh RUM index") @@ -219,7 +221,9 @@ defmodule Mix.Tasks.Pleroma.Database do Ecto.Adapters.SQL.query!( Pleroma.Repo, - "CREATE INDEX objects_fts ON objects USING gin(to_tsvector('#{tsconfig}', data->>'content')); " + "CREATE INDEX CONCURRENTLY objects_fts ON objects USING gin(to_tsvector('#{tsconfig}', data->>'content')); ", + [], + timeout: :infinity ) end From 7372609c5b5063d177715d5067654888f7075403 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 28 Aug 2021 18:31:56 +0200 Subject: [PATCH 15/15] Release 2.4.1 --- CHANGELOG.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb83abbd..5f26d48ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Removed -## 2.4.1 +## 2.4.1 - 2021-08-29 ### Changed - Make `mix pleroma.database set_text_search_config` run concurrently and indefinitely diff --git a/mix.exs b/mix.exs index 763c58089..39c79c83b 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do def project do [ app: :pleroma, - version: version("2.4.0"), + version: version("2.4.1"), elixir: "~> 1.9", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(),