From 25eb6cf1cbbfe78618f13a7218238a69807a051c Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 12 Mar 2019 22:15:28 +0300 Subject: [PATCH] Add "roles" to users admin API --- lib/pleroma/user/info.ex | 9 +++++++ .../mastodon_api/views/admin/account_view.ex | 4 ++- .../admin_api/admin_api_controller_test.exs | 27 ++++++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 818b64645..e3fd65a6e 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -6,6 +6,8 @@ defmodule Pleroma.User.Info do use Ecto.Schema import Ecto.Changeset + alias Pleroma.User.Info + embedded_schema do field(:banner, :map, default: %{}) field(:background, :map, default: %{}) @@ -250,4 +252,11 @@ def remove_pinnned_activity(info, %Pleroma.Activity{id: id}) do cast(info, params, [:pinned_activities]) end + + def roles(%Info{is_moderator: is_moderator, is_admin: is_admin}) do + %{ + admin: is_admin, + moderator: is_moderator + } + end end 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 74ca13564..66ad20ec4 100644 --- a/lib/pleroma/web/mastodon_api/views/admin/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/admin/account_view.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountView do use Pleroma.Web, :view alias Pleroma.Web.MastodonAPI.Admin.AccountView + alias Pleroma.User.Info def render("index.json", %{users: users, count: count, page_size: page_size}) do %{ @@ -19,7 +20,8 @@ def render("show.json", %{user: user}) do %{ "id" => user.id, "nickname" => user.nickname, - "deactivated" => user.info.deactivated + "deactivated" => user.info.deactivated, + "roles" => Info.roles(user.info) } 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 1b8b4d4b7..0470a439b 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -348,12 +348,14 @@ test "renders users array for the first page" do %{ "deactivated" => admin.info.deactivated, "id" => admin.id, - "nickname" => admin.nickname + "nickname" => admin.nickname, + "roles" => %{"admin" => true, "moderator" => false} }, %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -391,7 +393,8 @@ test "regular search" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -414,7 +417,8 @@ test "regular search with page size" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -431,7 +435,8 @@ test "regular search with page size" do %{ "deactivated" => user2.info.deactivated, "id" => user2.id, - "nickname" => user2.nickname + "nickname" => user2.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -455,7 +460,8 @@ test "only local users" do %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -479,12 +485,14 @@ test "only local users with no query" do %{ "deactivated" => admin.info.deactivated, "id" => admin.id, - "nickname" => admin.nickname + "nickname" => admin.nickname, + "roles" => %{"admin" => true, "moderator" => false} }, %{ "deactivated" => user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } ] } @@ -504,7 +512,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do %{ "deactivated" => !user.info.deactivated, "id" => user.id, - "nickname" => user.nickname + "nickname" => user.nickname, + "roles" => %{"admin" => false, "moderator" => false} } end end