AdminAPI: Return registration_reason with users

This commit is contained in:
Alex Gleason 2020-07-14 13:04:57 -05:00
parent 5ddf0415c4
commit a1570ba6ad
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 51 additions and 25 deletions

View file

@ -46,7 +46,8 @@ Configuration options:
"local": bool, "local": bool,
"tags": array, "tags": array,
"avatar": string, "avatar": string,
"display_name": string "display_name": string,
"registration_reason": string,
}, },
... ...
] ]

View file

@ -77,7 +77,8 @@ def render("show.json", %{user: user}) do
"roles" => User.roles(user), "roles" => User.roles(user),
"tags" => user.tags || [], "tags" => user.tags || [],
"confirmation_pending" => user.confirmation_pending, "confirmation_pending" => user.confirmation_pending,
"url" => user.uri || user.ap_id "url" => user.uri || user.ap_id,
"registration_reason" => user.registration_reason
} }
end end

View file

@ -338,7 +338,8 @@ test "Show", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
assert expected == json_response(conn, 200) assert expected == json_response(conn, 200)
@ -601,7 +602,9 @@ test "/api/pleroma/admin/users/:nickname/password_reset", %{conn: conn} do
describe "GET /api/pleroma/admin/users" do describe "GET /api/pleroma/admin/users" do
test "renders users array for the first page", %{conn: conn, admin: admin} do test "renders users array for the first page", %{conn: conn, admin: admin} do
user = insert(:user, local: false, tags: ["foo", "bar"]) user =
insert(:user, local: false, tags: ["foo", "bar"], registration_reason: "I'm a chill dude")
conn = get(conn, "/api/pleroma/admin/users?page=1") conn = get(conn, "/api/pleroma/admin/users?page=1")
users = users =
@ -616,7 +619,8 @@ test "renders users array for the first page", %{conn: conn, admin: admin} do
"avatar" => User.avatar_url(admin) |> MediaProxy.url(), "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(admin.name || admin.nickname), "display_name" => HTML.strip_tags(admin.name || admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => admin.ap_id "url" => admin.ap_id,
"registration_reason" => nil
}, },
%{ %{
"deactivated" => user.deactivated, "deactivated" => user.deactivated,
@ -628,7 +632,8 @@ test "renders users array for the first page", %{conn: conn, admin: admin} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => "I'm a chill dude"
} }
] ]
|> Enum.sort_by(& &1["nickname"]) |> Enum.sort_by(& &1["nickname"])
@ -701,7 +706,8 @@ test "regular search", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -727,7 +733,8 @@ test "search by domain", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -753,7 +760,8 @@ test "search by full nickname", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -779,7 +787,8 @@ test "search by display name", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -805,7 +814,8 @@ test "search by email", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -831,7 +841,8 @@ test "regular search with page size", %{conn: conn} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -852,7 +863,8 @@ test "regular search with page size", %{conn: conn} do
"avatar" => User.avatar_url(user2) |> MediaProxy.url(), "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user2.name || user2.nickname), "display_name" => HTML.strip_tags(user2.name || user2.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user2.ap_id "url" => user2.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -885,7 +897,8 @@ test "only local users" do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -911,7 +924,8 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
}, },
%{ %{
"deactivated" => admin.deactivated, "deactivated" => admin.deactivated,
@ -923,7 +937,8 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
"avatar" => User.avatar_url(admin) |> MediaProxy.url(), "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(admin.name || admin.nickname), "display_name" => HTML.strip_tags(admin.name || admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => admin.ap_id "url" => admin.ap_id,
"registration_reason" => nil
}, },
%{ %{
"deactivated" => false, "deactivated" => false,
@ -935,7 +950,8 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
"avatar" => User.avatar_url(old_admin) |> MediaProxy.url(), "avatar" => User.avatar_url(old_admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname), "display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => old_admin.ap_id "url" => old_admin.ap_id,
"registration_reason" => nil
} }
] ]
|> Enum.sort_by(& &1["nickname"]) |> Enum.sort_by(& &1["nickname"])
@ -966,7 +982,8 @@ test "load only admins", %{conn: conn, admin: admin} do
"avatar" => User.avatar_url(admin) |> MediaProxy.url(), "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(admin.name || admin.nickname), "display_name" => HTML.strip_tags(admin.name || admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => admin.ap_id "url" => admin.ap_id,
"registration_reason" => nil
}, },
%{ %{
"deactivated" => false, "deactivated" => false,
@ -978,7 +995,8 @@ test "load only admins", %{conn: conn, admin: admin} do
"avatar" => User.avatar_url(second_admin) |> MediaProxy.url(), "avatar" => User.avatar_url(second_admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname), "display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => second_admin.ap_id "url" => second_admin.ap_id,
"registration_reason" => nil
} }
] ]
|> Enum.sort_by(& &1["nickname"]) |> Enum.sort_by(& &1["nickname"])
@ -1011,7 +1029,8 @@ test "load only moderators", %{conn: conn} do
"avatar" => User.avatar_url(moderator) |> MediaProxy.url(), "avatar" => User.avatar_url(moderator) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(moderator.name || moderator.nickname), "display_name" => HTML.strip_tags(moderator.name || moderator.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => moderator.ap_id "url" => moderator.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -1037,7 +1056,8 @@ test "load users with tags list", %{conn: conn} do
"avatar" => User.avatar_url(user1) |> MediaProxy.url(), "avatar" => User.avatar_url(user1) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user1.name || user1.nickname), "display_name" => HTML.strip_tags(user1.name || user1.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user1.ap_id "url" => user1.ap_id,
"registration_reason" => nil
}, },
%{ %{
"deactivated" => false, "deactivated" => false,
@ -1049,7 +1069,8 @@ test "load users with tags list", %{conn: conn} do
"avatar" => User.avatar_url(user2) |> MediaProxy.url(), "avatar" => User.avatar_url(user2) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user2.name || user2.nickname), "display_name" => HTML.strip_tags(user2.name || user2.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user2.ap_id "url" => user2.ap_id,
"registration_reason" => nil
} }
] ]
|> Enum.sort_by(& &1["nickname"]) |> Enum.sort_by(& &1["nickname"])
@ -1089,7 +1110,8 @@ test "it works with multiple filters" do
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -1114,7 +1136,8 @@ test "it omits relay user", %{admin: admin, conn: conn} do
"avatar" => User.avatar_url(admin) |> MediaProxy.url(), "avatar" => User.avatar_url(admin) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(admin.name || admin.nickname), "display_name" => HTML.strip_tags(admin.name || admin.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => admin.ap_id "url" => admin.ap_id,
"registration_reason" => nil
} }
] ]
} }
@ -1177,7 +1200,8 @@ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admi
"avatar" => User.avatar_url(user) |> MediaProxy.url(), "avatar" => User.avatar_url(user) |> MediaProxy.url(),
"display_name" => HTML.strip_tags(user.name || user.nickname), "display_name" => HTML.strip_tags(user.name || user.nickname),
"confirmation_pending" => false, "confirmation_pending" => false,
"url" => user.ap_id "url" => user.ap_id,
"registration_reason" => nil
} }
log_entry = Repo.one(ModerationLog) log_entry = Repo.one(ModerationLog)