summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaelwenn <contact+git.pleroma.social@hacktivis.me>2020-01-27 13:21:50 +0000
committerHaelwenn <contact+git.pleroma.social@hacktivis.me>2020-01-27 13:21:50 +0000
commitb12f3064730648de992f934cf5a23cadb5206b9d (patch)
treeedaa519452d9008660e5aa4dd8464506ba806828
parent0b582d415ba5215495047ddae1cb4e4fc1e016e6 (diff)
parentdabd535e436789e64f6630460bfadd2f49dcf069 (diff)
Merge branch 'remove/suggestions-third-party-engine' into 'develop'
Remove user recommendation by third party engine See merge request pleroma/pleroma!2141
-rw-r--r--CHANGELOG.md1
-rw-r--r--config/config.exs8
-rw-r--r--config/description.exs37
-rw-r--r--docs/configuration/howto_user_recomendation.md31
-rw-r--r--lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex58
-rw-r--r--lib/pleroma/web/nodeinfo/nodeinfo_controller.ex9
-rw-r--r--test/web/mastodon_api/controllers/suggestion_controller_test.exs45
7 files changed, 5 insertions, 184 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4d626a683..8d9f7d1b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/config/config.exs b/config/config.exs
index 2c154eb45..f4e307e18 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -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,
diff --git a/config/description.exs b/config/description.exs
index b9b696e42..5f3c58b08 100644
--- a/config/description.exs
+++ b/config/description.exs
@@ -2749,43 +2749,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,
type: :group,
diff --git a/docs/configuration/howto_user_recomendation.md b/docs/configuration/howto_user_recomendation.md
deleted file mode 100644
index c4d749d0c..000000000
--- a/docs/configuration/howto_user_recomendation.md
+++ /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"
-```
diff --git a/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex b/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex
index fe71c36af..b9cc8f104 100644
--- a/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex
+++ b/lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex
@@ -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
diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
index abcf46034..03c35cc2a 100644
--- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
+++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex
@@ -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,
diff --git a/test/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/web/mastodon_api/controllers/suggestion_controller_test.exs
index c4118a576..c288c2fff 100644
--- a/test/web/mastodon_api/controllers/suggestion_controller_test.exs
+++ b/test/web/mastodon_api/controllers/suggestion_controller_test.exs
@@ -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