X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fadmin_api%2Fadmin_api_controller.ex;h=6d9bf289502f617ea40adffc3a3278fa43e616cc;hb=e751f3ec56a1b05892cedefb88418ac3243bc99d;hp=49d237661f69ff9b1eb52ce320c056ed54f5a142;hpb=bee6acd51dc4e84e44caecf9d123dfff2f640a38;p=akkoma
diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex
index 49d237661..6d9bf2895 100644
--- a/lib/pleroma/web/admin_api/admin_api_controller.ex
+++ b/lib/pleroma/web/admin_api/admin_api_controller.ex
@@ -1,11 +1,14 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.AdminAPIController do
+ @users_page_size 50
+
use Pleroma.Web, :controller
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Relay
+ alias Pleroma.Web.AdminAPI.AccountView
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
@@ -14,13 +17,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
action_fallback(:errors)
def user_delete(conn, %{"nickname" => nickname}) do
- user = User.get_by_nickname(nickname)
-
- if user.local == true do
- User.delete(user)
- else
- User.delete(user)
- end
+ User.get_by_nickname(nickname)
+ |> User.delete()
conn
|> json(nickname)
@@ -46,6 +44,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> json(user.nickname)
end
+ def user_toggle_activation(conn, %{"nickname" => nickname}) do
+ user = User.get_by_nickname(nickname)
+
+ {:ok, updated_user} = User.deactivate(user, !user.info.deactivated)
+
+ conn
+ |> json(AccountView.render("show.json", %{user: updated_user}))
+ end
+
def tag_users(conn, %{"nicknames" => nicknames, "tags" => tags}) do
with {:ok, _} <- User.tag(nicknames, tags),
do: json_response(conn, :no_content, "")
@@ -56,6 +63,28 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
do: json_response(conn, :no_content, "")
end
+ def list_users(%{assigns: %{user: admin}} = conn, params) do
+ {page, page_size} = page_params(params)
+
+ with {:ok, users, count} <-
+ User.search_for_admin(%{
+ query: params["query"],
+ admin: admin,
+ local: params["local_only"] == "true",
+ page: page,
+ page_size: page_size
+ }),
+ do:
+ conn
+ |> json(
+ AccountView.render("index.json",
+ users: users,
+ count: count,
+ page_size: page_size
+ )
+ )
+ end
+
def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname})
when permission_group in ["moderator", "admin"] do
user = User.get_by_nickname(nickname)
@@ -129,6 +158,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> json(%{error: "No such permission_group"})
end
+ def set_activation_status(conn, %{"nickname" => nickname, "status" => status}) do
+ with {:ok, status} <- Ecto.Type.cast(:boolean, status),
+ %User{} = user <- User.get_by_nickname(nickname),
+ {:ok, _} <- User.deactivate(user, !status),
+ do: json_response(conn, :no_content, "")
+ end
+
def relay_follow(conn, %{"relay_url" => target}) do
with {:ok, _message} <- Relay.follow(target) do
json(conn, target)
@@ -192,4 +228,26 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|> put_status(500)
|> json("Something went wrong")
end
+
+ defp page_params(params) do
+ {get_page(params["page"]), get_page_size(params["page_size"])}
+ end
+
+ defp get_page(page_string) when is_nil(page_string), do: 1
+
+ defp get_page(page_string) do
+ case Integer.parse(page_string) do
+ {page, _} -> page
+ :error -> 1
+ end
+ end
+
+ defp get_page_size(page_size_string) when is_nil(page_size_string), do: @users_page_size
+
+ defp get_page_size(page_size_string) do
+ case Integer.parse(page_size_string) do
+ {page_size, _} -> page_size
+ :error -> @users_page_size
+ end
+ end
end