Remove user recommendation by third party engine
authorHakaba Hitoyo <hakabahitoyo@yahoo.co.jp>
Mon, 27 Jan 2020 13:21:50 +0000 (13:21 +0000)
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>
Mon, 27 Jan 2020 13:21:50 +0000 (13:21 +0000)
CHANGELOG.md
config/config.exs
config/description.exs
docs/configuration/howto_user_recomendation.md [deleted file]
lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex
lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
test/web/mastodon_api/controllers/suggestion_controller_test.exs

index 4d626a6836e4660592b266e194a7f0aec979ccf5..8d9f7d1b5e844b23e085f3acf05b2aacfb05356b 100644 (file)
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - **Breaking**: Removed 1.0+ deprecated configurations `Pleroma.Upload, :strip_exif` and `:instance, :dedupe_media`
 - **Breaking**: OStatus protocol support
 - **Breaking**: MDII uploader
+- **Breaking**: Using third party engines for user recommendation
 
 ### Changed
 - **Breaking:** Pleroma won't start if it detects unapplied migrations
index 2c154eb456e30475a1a5995759648519324b269f..f4e307e183ad680b822b919dff9a5dd5748376eb 100644 (file)
@@ -425,14 +425,6 @@ config :pleroma, Pleroma.Web.Metadata,
   ],
   unfurl_nsfw: false
 
-config :pleroma, :suggestions,
-  enabled: false,
-  third_party_engine:
-    "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
-  timeout: 300_000,
-  limit: 40,
-  web: "https://vinayaka.distsn.org"
-
 config :pleroma, :http_security,
   enabled: true,
   sts: false,
index b9b696e42d9b66086cdc5f622795a55e60753589..5f3c58b08dbc4bbc62f99cf351e69a0091c7f137 100644 (file)
@@ -2748,43 +2748,6 @@ config :pleroma, :config_description, [
       }
     ]
   },
-  %{
-    group: :pleroma,
-    key: :suggestions,
-    type: :group,
-    children: [
-      %{
-        key: :enabled,
-        type: :boolean,
-        description: "Enables suggestions"
-      },
-      %{
-        key: :third_party_engine,
-        type: :string,
-        description: "URL for third party engine",
-        suggestions: [
-          "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}"
-        ]
-      },
-      %{
-        key: :timeout,
-        type: :integer,
-        description: "Request timeout to third party engine",
-        suggestions: [300_000]
-      },
-      %{
-        key: :limit,
-        type: :integer,
-        description: "Limit for suggestions",
-        suggestions: [40]
-      },
-      %{
-        key: :web,
-        type: :string,
-        suggestions: ["https://vinayaka.distsn.org"]
-      }
-    ]
-  },
   %{
     group: :prometheus,
     key: Pleroma.Web.Endpoint.MetricsExporter,
diff --git a/docs/configuration/howto_user_recomendation.md b/docs/configuration/howto_user_recomendation.md
deleted file mode 100644 (file)
index c4d749d..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-# How to activate user recommendation (Who to follow panel)
-![who-to-follow-panel-small](/uploads/9de1b1300436c32461d272945f1bc23e/who-to-follow-panel-small.png)
-
-To show the *who to follow* panel, edit `config/prod.secret.exs` in the Pleroma backend. Following code activates the *who to follow* panel:
-
-```elixir
-config :pleroma, :suggestions,
-  enabled: true,
-  third_party_engine:
-    "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-suggestions-api.cgi?{{host}}+{{user}}",
-  timeout: 300_000,
-  limit: 40,
-  web: "https://vinayaka.distsn.org"
-
-```
-
-`config/config.exs` already includes this code, but `enabled:` is `false`.
-
-`/api/v1/suggestions` is also provided when *who to follow* panel is enabled.
-
-For advanced customization, following code shows the newcomers of the fediverse at the *who to follow* panel:
-
-```elixir
-config :pleroma, :suggestions,
-  enabled: true,
-  third_party_engine:
-    "http://vinayaka.distsn.org/cgi-bin/vinayaka-user-new-suggestions-api.cgi?{{host}}+{{user}}",
-  timeout: 60_000,
-  limit: 40,
-  web: "https://vinayaka.distsn.org/user-new.html"
-```
index fe71c36affc8de297e13a89169d34e59ec87b7e0..b9cc8f10492cae8f23bfed216dfdd6a595cdc8f9 100644 (file)
@@ -7,62 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionController do
 
   require Logger
 
-  alias Pleroma.Config
-  alias Pleroma.Plugs.OAuthScopesPlug
-  alias Pleroma.User
-  alias Pleroma.Web.MediaProxy
-
-  action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
-
-  plug(OAuthScopesPlug, %{scopes: ["read"]} when action == :index)
-
-  plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
-
   @doc "GET /api/v1/suggestions"
-  def index(%{assigns: %{user: user}} = conn, _) do
-    if Config.get([:suggestions, :enabled], false) do
-      with {:ok, data} <- fetch_suggestions(user) do
-        limit = Config.get([:suggestions, :limit], 23)
-
-        data =
-          data
-          |> Enum.slice(0, limit)
-          |> Enum.map(fn x ->
-            x
-            |> Map.put("id", fetch_suggestion_id(x))
-            |> Map.put("avatar", MediaProxy.url(x["avatar"]))
-            |> Map.put("avatar_static", MediaProxy.url(x["avatar_static"]))
-          end)
-
-        json(conn, data)
-      end
-    else
-      json(conn, [])
-    end
-  end
-
-  defp fetch_suggestions(user) do
-    api = Config.get([:suggestions, :third_party_engine], "")
-    timeout = Config.get([:suggestions, :timeout], 5000)
-    host = Config.get([Pleroma.Web.Endpoint, :url, :host])
-
-    url =
-      api
-      |> String.replace("{{host}}", host)
-      |> String.replace("{{user}}", user.nickname)
-
-    with {:ok, %{status: 200, body: body}} <-
-           Pleroma.HTTP.get(url, [], adapter: [recv_timeout: timeout, pool: :default]) do
-      Jason.decode(body)
-    else
-      e -> Logger.error("Could not retrieve suggestions at fetch #{url}, #{inspect(e)}")
-    end
-  end
-
-  defp fetch_suggestion_id(attrs) do
-    case User.get_or_fetch(attrs["acct"]) do
-      {:ok, %User{id: id}} -> id
-      _ -> 0
-    end
+  def index(conn, _) do
+    json(conn, [])
   end
 end
index abcf46034d10c0cc6073eeb6364e8eb02257ab31..03c35cc2a25fa89a62f7cf74171583940e9c13e2 100644 (file)
@@ -69,9 +69,6 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
         if Config.get([:chat, :enabled]) do
           "chat"
         end,
-        if Config.get([:suggestions, :enabled]) do
-          "suggestions"
-        end,
         if Config.get([:instance, :allow_relay]) do
           "relay"
         end,
@@ -104,11 +101,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
         nodeDescription: Config.get([:instance, :description]),
         private: !Config.get([:instance, :public], true),
         suggestions: %{
-          enabled: Config.get([:suggestions, :enabled], false),
-          thirdPartyEngine: Config.get([:suggestions, :third_party_engine], ""),
-          timeout: Config.get([:suggestions, :timeout], 5000),
-          limit: Config.get([:suggestions, :limit], 23),
-          web: Config.get([:suggestions, :web], "")
+          enabled: false
         },
         staffAccounts: staff_accounts,
         federation: federation_response,
index c4118a57674d6d8f4c24c15cfa116e9d2f8e5c0a..c288c2fffb9e6788156d557eba61b11ea19343f3 100644 (file)
@@ -36,11 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
     [other_user: other_user]
   end
 
-  clear_config(:suggestions)
-
-  test "returns empty result when suggestions disabled", %{conn: conn} do
-    Config.put([:suggestions, :enabled], false)
-
+  test "returns empty result", %{conn: conn} do
     res =
       conn
       |> get("/api/v1/suggestions")
@@ -48,43 +44,4 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
 
     assert res == []
   end
-
-  test "returns error", %{conn: conn} do
-    Config.put([:suggestions, :enabled], true)
-    Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
-
-    assert capture_log(fn ->
-             res =
-               conn
-               |> get("/api/v1/suggestions")
-               |> json_response(500)
-
-             assert res == "Something went wrong"
-           end) =~ "Could not retrieve suggestions"
-  end
-
-  test "returns suggestions", %{conn: conn, other_user: other_user} do
-    Config.put([:suggestions, :enabled], true)
-    Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
-
-    res =
-      conn
-      |> get("/api/v1/suggestions")
-      |> json_response(200)
-
-    assert res == [
-             %{
-               "acct" => "yj455",
-               "avatar" => "https://social.heldscal.la/avatar/201.jpeg",
-               "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
-               "id" => 0
-             },
-             %{
-               "acct" => other_user.ap_id,
-               "avatar" => "https://social.heldscal.la/avatar/202.jpeg",
-               "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
-               "id" => other_user.id
-             }
-           ]
-  end
 end