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(
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]
|> 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, "")
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)
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)
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)
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,