From cf5d1302aa97c3a042421333f93d91b474266e51 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 3 Sep 2018 11:55:12 +0000 Subject: [PATCH 1/4] migrations: add is_moderator index for users table --- .../20180903114437_users_add_is_moderator_index.exs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs diff --git a/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs b/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs new file mode 100644 index 000000000..ba6b90ea9 --- /dev/null +++ b/priv/repo/migrations/20180903114437_users_add_is_moderator_index.exs @@ -0,0 +1,7 @@ +defmodule Pleroma.Repo.Migrations.UsersAddIsModeratorIndex do + use Ecto.Migration + + def change do + create index(:users, ["(info->'is_moderator')"], name: :users_is_moderator_index, using: :gin) + end +end From b61430163ba983f1d8a1d762f4eec743ed7ffab1 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 3 Sep 2018 12:03:23 +0000 Subject: [PATCH 2/4] user: add moderator_user_query() --- lib/pleroma/user.ex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 64c69b209..1dad30e87 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -609,6 +609,14 @@ def local_user_query() do ) end + def moderator_user_query() do + from( + u in User, + where: u.local == true, + where: fragment("?->'is_moderator' @> 'true'", u.info) + ) + end + def deactivate(%User{} = user) do new_info = Map.put(user.info, "deactivated", true) cs = User.info_changeset(user, %{info: new_info}) From 9a21ff5f619b61dd1942b9d3044bdbe1f61666af Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 3 Sep 2018 14:35:51 +0000 Subject: [PATCH 3/4] nodeinfo: add staffAccounts field to metadata --- lib/pleroma/web/nodeinfo/nodeinfo_controller.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex index 2fab60274..d95addb0b 100644 --- a/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex +++ b/lib/pleroma/web/nodeinfo/nodeinfo_controller.ex @@ -3,6 +3,7 @@ defmodule Pleroma.Web.Nodeinfo.NodeinfoController do alias Pleroma.Stats alias Pleroma.Web + alias Pleroma.{User, Repo} def schemas(conn, _params) do response = %{ @@ -24,6 +25,11 @@ def nodeinfo(conn, %{"version" => "2.0"}) do suggestions = Application.get_env(:pleroma, :suggestions) stats = Stats.get_stats() + staff_accounts = + User.moderator_user_query() + |> Repo.all() + |> Enum.map(fn u -> u.ap_id end) + response = %{ version: "2.0", software: %{ @@ -52,7 +58,8 @@ def nodeinfo(conn, %{"version" => "2.0"}) do thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""), timeout: Keyword.get(suggestions, :timeout, 5000), web: Keyword.get(suggestions, :web, "") - } + }, + staffAccounts: staff_accounts } } From d3f6814febb95f03af58543f4896599810f9b069 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 3 Sep 2018 14:40:14 +0000 Subject: [PATCH 4/4] tests: add test for staffAccounts presence in nodeinfo --- test/web/node_info_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/web/node_info_test.exs diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs new file mode 100644 index 000000000..d48f40e47 --- /dev/null +++ b/test/web/node_info_test.exs @@ -0,0 +1,17 @@ +defmodule Pleroma.Web.NodeInfoTest do + use Pleroma.Web.ConnCase + + import Pleroma.Factory + + test "nodeinfo shows staff accounts", %{conn: conn} do + user = insert(:user, %{local: true, info: %{"is_moderator" => true}}) + + conn = + conn + |> get("/nodeinfo/2.0.json") + + assert result = json_response(conn, 200) + + assert user.ap_id in result["metadata"]["staffAccounts"] + end +end