Add "roles" to users admin API
authorMaxim Filippov <colixer@gmail.com>
Tue, 12 Mar 2019 19:15:28 +0000 (22:15 +0300)
committerMaxim Filippov <colixer@gmail.com>
Tue, 12 Mar 2019 19:15:28 +0000 (22:15 +0300)
lib/pleroma/user/info.ex
lib/pleroma/web/mastodon_api/views/admin/account_view.ex
test/web/admin_api/admin_api_controller_test.exs

index 818b646454993b1e4fa472bfdbd3f2b692856a02..e3fd65a6ed8dcecd8989796cb6d226de68e06993 100644 (file)
@@ -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 @@ defmodule Pleroma.User.Info 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
index 74ca1356454b1ca4fd265139627ea144a0e9d552..66ad20ec42de7e470b3cef619c7ead8ef00551bb 100644 (file)
@@ -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 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountView do
     %{
       "id" => user.id,
       "nickname" => user.nickname,
-      "deactivated" => user.info.deactivated
+      "deactivated" => user.info.deactivated,
+      "roles" => Info.roles(user.info)
     }
   end
 end
index 1b8b4d4b78b1209d91206681d3b3223506a0169f..0470a439bef958b5a541ddc0e8d43a1ba46dcd10 100644 (file)
@@ -348,12 +348,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  %{
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
-                   "nickname" => user.nickname
+                   "nickname" => user.nickname,
+                   "roles" => %{"admin" => false, "moderator" => false}
                  }
                ]
              }
@@ -414,7 +417,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  %{
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
-                   "nickname" => user.nickname
+                   "nickname" => user.nickname,
+                   "roles" => %{"admin" => false, "moderator" => false}
                  }
                ]
              }
@@ -431,7 +435,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  %{
                    "deactivated" => user2.info.deactivated,
                    "id" => user2.id,
-                   "nickname" => user2.nickname
+                   "nickname" => user2.nickname,
+                   "roles" => %{"admin" => false, "moderator" => false}
                  }
                ]
              }
@@ -455,7 +460,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                  %{
                    "deactivated" => user.info.deactivated,
                    "id" => user.id,
-                   "nickname" => user.nickname
+                   "nickname" => user.nickname,
+                   "roles" => %{"admin" => false, "moderator" => false}
                  }
                ]
              }
@@ -479,12 +485,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
              %{
                "deactivated" => !user.info.deactivated,
                "id" => user.id,
-               "nickname" => user.nickname
+               "nickname" => user.nickname,
+               "roles" => %{"admin" => false, "moderator" => false}
              }
   end
 end