From 490d9cf7b149bbb93f6065fc807eafd339bcc0ea Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 16:04:44 +0300 Subject: [PATCH 1/5] Add "local" to users admin API --- .../mastodon_api/views/admin/account_view.ex | 1 + .../admin_api/admin_api_controller_test.exs | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 5ce017124..1bed11089 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -21,6 +21,7 @@ def render("show.json", %{user: user}) do "id" => user.id, "nickname" => user.nickname, "deactivated" => user.info.deactivated, + "local" => user.local, "roles" => Info.roles(user.info) } end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 0470a439b..c72e6b975 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -394,7 +394,8 @@ test "regular search" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -418,7 +419,8 @@ test "regular search with page size" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -436,7 +438,8 @@ test "regular search with page size" do "deactivated" => user2.info.deactivated, "id" => user2.id, "nickname" => user2.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -461,7 +464,8 @@ test "only local users" do "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -486,13 +490,15 @@ test "only local users with no query" do "deactivated" => admin.info.deactivated, "id" => admin.id, "nickname" => admin.nickname, - "roles" => %{"admin" => true, "moderator" => false} + "roles" => %{"admin" => true, "moderator" => false}, + "local" => true }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } @@ -513,7 +519,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do "deactivated" => !user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } end end From d5edff6ce6e62d003984760df6110bf47806d468 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 16:14:31 +0300 Subject: [PATCH 2/5] Fix test --- test/web/admin_api/admin_api_controller_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index c72e6b975..96cb95da6 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -349,13 +349,15 @@ test "renders users array for the first page" do "deactivated" => admin.info.deactivated, "id" => admin.id, "nickname" => admin.nickname, - "roles" => %{"admin" => true, "moderator" => false} + "roles" => %{"admin" => true, "moderator" => false}, + "local" => true }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, - "roles" => %{"admin" => false, "moderator" => false} + "roles" => %{"admin" => false, "moderator" => false}, + "local" => true } ] } From 4872914d3253d673071220cb2149f32fe3ca9e26 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Wed, 13 Mar 2019 17:56:15 +0300 Subject: [PATCH 3/5] Add test when local is false --- test/web/admin_api/admin_api_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 96cb95da6..555272d05 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -334,7 +334,7 @@ test "/api/pleroma/admin/password_reset" do describe "GET /api/pleroma/admin/users" do test "renders users array for the first page" do admin = insert(:user, info: %{is_admin: true}) - user = insert(:user) + user = insert(:user, local: false) conn = build_conn() @@ -357,7 +357,7 @@ test "renders users array for the first page" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => false } ] } From 257d8e78e54a7b2d27bcb129bface01a543fc68f Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 14 Mar 2019 01:52:24 +0300 Subject: [PATCH 4/5] Add tags --- .../mastodon_api/views/admin/account_view.ex | 3 +- .../admin_api/admin_api_controller_test.exs | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index 1bed11089..efb26be64 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -22,7 +22,8 @@ def render("show.json", %{user: user}) do "nickname" => user.nickname, "deactivated" => user.info.deactivated, "local" => user.local, - "roles" => Info.roles(user.info) + "roles" => Info.roles(user.info), + "tags" => user.tags } end end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 555272d05..e50f0edde 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -334,7 +334,7 @@ test "/api/pleroma/admin/password_reset" do describe "GET /api/pleroma/admin/users" do test "renders users array for the first page" do admin = insert(:user, info: %{is_admin: true}) - user = insert(:user, local: false) + user = insert(:user, local: false, tags: ["foo", "bar"]) conn = build_conn() @@ -350,14 +350,16 @@ test "renders users array for the first page" do "id" => admin.id, "nickname" => admin.nickname, "roles" => %{"admin" => true, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => false + "local" => false, + "tags" => ["foo", "bar"] } ] } @@ -397,7 +399,8 @@ test "regular search" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -422,7 +425,8 @@ test "regular search with page size" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -441,7 +445,8 @@ test "regular search with page size" do "id" => user2.id, "nickname" => user2.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -467,7 +472,8 @@ test "only local users" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -493,14 +499,16 @@ test "only local users with no query" do "id" => admin.id, "nickname" => admin.nickname, "roles" => %{"admin" => true, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] }, %{ "deactivated" => user.info.deactivated, "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } ] } @@ -522,7 +530,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do "id" => user.id, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, - "local" => true + "local" => true, + "tags" => [] } end end From f3964f4024d5f5c0738e1ca8ce44742330bc0a80 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Thu, 14 Mar 2019 03:17:09 +0300 Subject: [PATCH 5/5] Ensure empty array is returned for tags --- lib/pleroma/web/mastodon_api/views/admin/account_view.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex index efb26be64..787b049a3 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -23,7 +23,7 @@ def render("show.json", %{user: user}) do "deactivated" => user.info.deactivated, "local" => user.local, "roles" => Info.roles(user.info), - "tags" => user.tags + "tags" => user.tags || [] } end end