forked from YokaiRick/akkoma
Add more admin actions
This commit is contained in:
parent
b985c91431
commit
90d0d055fc
4 changed files with 39 additions and 0 deletions
|
@ -772,6 +772,12 @@ def search(query, resolve \\ false, for_user \\ nil) do
|
|||
Enum.uniq_by(fts_results ++ trigram_results, & &1.id)
|
||||
end
|
||||
|
||||
def all_except_one(user) do
|
||||
query = from(u in User, where: u.id != ^user.id)
|
||||
|
||||
Repo.all(query)
|
||||
end
|
||||
|
||||
defp do_search(subquery, for_user, options \\ []) do
|
||||
q =
|
||||
from(
|
||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||
use Pleroma.Web, :controller
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
|
||||
|
||||
|
@ -41,6 +42,15 @@ def user_create(
|
|||
|> 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(UserView.render("show_for_admin.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, "")
|
||||
|
@ -51,6 +61,13 @@ def untag_users(conn, %{"nicknames" => nicknames, "tags" => tags}) do
|
|||
do: json_response(conn, :no_content, "")
|
||||
end
|
||||
|
||||
def list_users(%{assigns: %{user: admin}} = conn, _data) do
|
||||
users = User.all_except_one(admin)
|
||||
|
||||
conn
|
||||
|> json(UserView.render("index_for_admin.json", %{users: users}))
|
||||
end
|
||||
|
||||
def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname})
|
||||
when permission_group in ["moderator", "admin"] do
|
||||
user = User.get_by_nickname(nickname)
|
||||
|
|
|
@ -139,7 +139,9 @@ defmodule Pleroma.Web.Router do
|
|||
scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||
pipe_through([:admin_api, :oauth_write])
|
||||
|
||||
get("/users", AdminAPIController, :list_users)
|
||||
delete("/user", AdminAPIController, :user_delete)
|
||||
patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
|
||||
post("/user", AdminAPIController, :user_create)
|
||||
put("/users/tag", AdminAPIController, :tag_users)
|
||||
delete("/users/tag", AdminAPIController, :untag_users)
|
||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
|
||||
def render("show.json", %{user: user = %User{}} = assigns) do
|
||||
render_one(user, Pleroma.Web.TwitterAPI.UserView, "user.json", assigns)
|
||||
|
@ -26,6 +27,19 @@ def render("user.json", %{user: user = %User{}} = assigns) do
|
|||
else: %{}
|
||||
end
|
||||
|
||||
def render("index_for_admin.json", %{users: users} = opts) do
|
||||
users
|
||||
|> render_many(UserView, "show_for_admin.json", opts)
|
||||
end
|
||||
|
||||
def render("show_for_admin.json", %{user: user}) do
|
||||
%{
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"deactivated" => user.info.deactivated
|
||||
}
|
||||
end
|
||||
|
||||
def render("short.json", %{
|
||||
user: %User{
|
||||
nickname: nickname,
|
||||
|
|
Loading…
Reference in a new issue