1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.AccountView do
10 alias Pleroma.Web.AdminAPI.AccountView
11 alias Pleroma.Web.MediaProxy
13 def render("index.json", %{users: users, count: count, page_size: page_size}) do
15 users: render_many(users, AccountView, "show.json", as: :user),
21 def render("index.json", %{users: users}) do
23 users: render_many(users, AccountView, "show.json", as: :user)
27 def render("show.json", %{user: user}) do
28 avatar = User.avatar_url(user) |> MediaProxy.url()
29 display_name = HTML.strip_tags(user.name || user.nickname)
34 "nickname" => user.nickname,
35 "display_name" => display_name,
36 "deactivated" => user.deactivated,
37 "local" => user.local,
38 "roles" => User.roles(user),
39 "tags" => user.tags || []
43 def render("invite.json", %{invite: invite}) do
46 "token" => invite.token,
47 "used" => invite.used,
48 "expires_at" => invite.expires_at,
49 "uses" => invite.uses,
50 "max_use" => invite.max_use,
51 "invite_type" => invite.invite_type
55 def render("invites.json", %{invites: invites}) do
57 invites: render_many(invites, AccountView, "invite.json", as: :invite)
61 def render("created.json", %{user: user}) do
66 nickname: user.nickname,
72 def render("create-error.json", %{changeset: %Ecto.Changeset{changes: changes, errors: errors}}) do
76 error: parse_error(errors),
78 nickname: Map.get(changes, :nickname),
79 email: Map.get(changes, :email)
84 defp parse_error([]), do: ""
86 defp parse_error(errors) do
87 ## when nickname is duplicate ap_id constraint error is raised
88 nickname_error = Keyword.get(errors, :nickname) || Keyword.get(errors, :ap_id)
89 email_error = Keyword.get(errors, :email)
90 password_error = Keyword.get(errors, :password)
94 "nickname #{elem(nickname_error, 0)}"
97 "email #{elem(email_error, 0)}"
100 "password #{elem(password_error, 0)}"