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.User.Info
11 alias Pleroma.Web.AdminAPI.AccountView
12 alias Pleroma.Web.MediaProxy
14 def render("index.json", %{users: users, count: count, page_size: page_size}) do
16 users: render_many(users, AccountView, "show.json", as: :user),
22 def render("index.json", %{users: users}) do
24 users: render_many(users, AccountView, "show.json", as: :user)
28 def render("show.json", %{user: user}) do
29 avatar = User.avatar_url(user) |> MediaProxy.url()
30 display_name = HTML.strip_tags(user.name || user.nickname)
35 "nickname" => user.nickname,
36 "display_name" => display_name,
37 "deactivated" => user.info.deactivated,
38 "local" => user.local,
39 "roles" => Info.roles(user.info),
40 "tags" => user.tags || []
44 def render("invite.json", %{invite: invite}) do
47 "token" => invite.token,
48 "used" => invite.used,
49 "expires_at" => invite.expires_at,
50 "uses" => invite.uses,
51 "max_use" => invite.max_use,
52 "invite_type" => invite.invite_type
56 def render("invites.json", %{invites: invites}) do
58 invites: render_many(invites, AccountView, "invite.json", as: :invite)
62 def render("created.json", %{user: user}) do
67 nickname: user.nickname,
73 def render("create-error.json", %{changeset: %Ecto.Changeset{changes: changes, errors: errors}}) do
77 error: parse_error(errors),
79 nickname: Map.get(changes, :nickname),
80 email: Map.get(changes, :email)
85 defp parse_error([]), do: ""
87 defp parse_error(errors) do
88 ## when nickname is duplicate ap_id constraint error is raised
89 nickname_error = Keyword.get(errors, :nickname) || Keyword.get(errors, :ap_id)
90 email_error = Keyword.get(errors, :email)
91 password_error = Keyword.get(errors, :password)
95 "nickname #{elem(nickname_error, 0)}"
98 "email #{elem(email_error, 0)}"
101 "password #{elem(password_error, 0)}"