From: Maxim Filippov Date: Tue, 15 Oct 2019 15:33:29 +0000 (+0200) Subject: DELETE /api/pleroma/admin/users now accepts nicknames array X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=da0e4879bcd12849182a39445174384420fcf064;p=akkoma DELETE /api/pleroma/admin/users now accepts nicknames array --- da0e4879bcd12849182a39445174384420fcf064 diff --cc CHANGELOG.md index 30b765251,e3ccfa4ea..24876d3f2 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@@ -17,8 -17,7 +17,9 @@@ The format is based on [Keep a Changelo - Authentication: Added rate limit for password-authorized actions / login existence checks - Metadata Link: Atom syndication Feed - Mix task to re-count statuses for all users (`mix pleroma.count_statuses`) + - Mastodon API: Add `exclude_visibilities` parameter to the timeline and notification endpoints +- Admin API: `/users/:nickname/toggle_activation` endpoint is now deprecated in favor of: `/users/activate`, `/users/deactivate`, both accept `nicknames` array - - Admin API: `POST /api/pleroma/admin/users/:nickname/permission_group/:permission_group` / `DELETE /api/pleroma/admin/users/:nickname/permission_group/:permission_group` are deprecated in favor of: `POST /api/pleroma/admin/users/permission_group/:permission_group` / `DELETE /api/pleroma/admin/users/permission_group/:permission_group` (both accept `nicknames` array) ++- Admin API: `POST/DELETE /api/pleroma/admin/users/:nickname/permission_group/:permission_group` are deprecated in favor of: `POST/DELETE /api/pleroma/admin/users/permission_group/:permission_group` (both accept `nicknames` array), `DELETE /api/pleroma/admin/users` (`nickname` query param or `nickname` sent in JSON body) is deprecated in favor of: `DELETE /api/pleroma/admin/users` (`nicknames` query array param or `nicknames` sent in JSON body). ### Changed - **Breaking:** Elixir >=1.8 is now required (was >= 1.7) diff --cc docs/API/admin_api.md index 2c8237b57,ee9e68cb1..60755e40a --- a/docs/API/admin_api.md +++ b/docs/API/admin_api.md @@@ -47,7 -47,7 +47,7 @@@ Authentication is required and the use } ``` --## `/api/pleroma/admin/users` ++## DEPRECATED `DELETE /api/pleroma/admin/users` ### Remove a user @@@ -56,6 -56,6 +56,15 @@@ - `nickname` - Response: User’s nickname ++## `DELETE /api/pleroma/admin/users` ++ ++### Remove a user ++ ++- Method `DELETE` ++- Params: ++ - `nicknames` ++- Response: Array of user nicknames ++ ### Create a user - Method: `POST` diff --cc lib/pleroma/moderation_log.ex index 42649ff02,352cad433..e8884e6e8 --- a/lib/pleroma/moderation_log.ex +++ b/lib/pleroma/moderation_log.ex @@@ -352,10 -349,10 +352,10 @@@ defmodule Pleroma.ModerationLog d data: %{ "actor" => %{"nickname" => actor_nickname}, "action" => "delete", -- "subject" => %{"nickname" => subject_nickname, "type" => "user"} ++ "subject" => subjects } }) do -- "@#{actor_nickname} deleted user @#{subject_nickname}" ++ "@#{actor_nickname} deleted users: #{users_to_nicknames_string(subjects)}" end @spec get_log_entry_message(ModerationLog) :: String.t() diff --cc lib/pleroma/user.ex index a76a5ad70,2cfb13a8c..596584062 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@@ -1080,6 -1072,6 +1080,10 @@@ defmodule Pleroma.User d update_info(user, &User.Info.update_notification_settings(&1, settings)) end ++ def delete(users) when is_list(users) do ++ for user <- users, do: delete(user) ++ end ++ def delete(%User{} = user) do BackgroundWorker.enqueue("delete_user", %{"user_id" => user.id}) end diff --cc lib/pleroma/web/admin_api/admin_api_controller.ex index 33e2180ec,513bae800..ab0d0fe0a --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@@ -100,7 -98,7 +100,7 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI ModerationLog.insert_log(%{ actor: admin, -- subject: user, ++ subject: [user], action: "delete" }) @@@ -108,6 -106,6 +108,20 @@@ |> json(nickname) end ++ def user_delete(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do ++ users = nicknames |> Enum.map(&User.get_cached_by_nickname/1) ++ User.delete(users) ++ ++ ModerationLog.insert_log(%{ ++ actor: admin, ++ subject: users, ++ action: "delete" ++ }) ++ ++ conn ++ |> json(nicknames) ++ end ++ def user_follow(%{assigns: %{user: admin}} = conn, %{ "follower" => follower_nick, "followed" => followed_nick diff --cc test/moderation_log_test.exs index ead97e948,a39a00e02..81c0fef12 --- a/test/moderation_log_test.exs +++ b/test/moderation_log_test.exs @@@ -24,13 -24,13 +24,13 @@@ defmodule Pleroma.ModerationLogTest d {:ok, _} = ModerationLog.insert_log(%{ actor: moderator, -- subject: subject1, ++ subject: [subject1], action: "delete" }) log = Repo.one(ModerationLog) -- assert log.data["message"] == "@#{moderator.nickname} deleted user @#{subject1.nickname}" ++ assert log.data["message"] == "@#{moderator.nickname} deleted users: @#{subject1.nickname}" end test "logging user creation by moderator", %{ diff --cc test/web/admin_api/admin_api_controller_test.exs index 81dc5d101,b5c355e66..645b79f57 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@@ -17,8 -17,8 +17,8 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI alias Pleroma.Web.MediaProxy import Pleroma.Factory -- describe "/api/pleroma/admin/users" do -- test "Delete" do ++ describe "DELETE /api/pleroma/admin/users" do ++ test "single user" do admin = insert(:user, info: %{is_admin: true}) user = insert(:user) @@@ -30,15 -30,15 +30,36 @@@ log_entry = Repo.one(ModerationLog) -- assert log_entry.data["subject"]["nickname"] == user.nickname -- assert log_entry.data["action"] == "delete" -- assert ModerationLog.get_log_entry_message(log_entry) == -- "@#{admin.nickname} deleted user @#{user.nickname}" ++ "@#{admin.nickname} deleted users: @#{user.nickname}" assert json_response(conn, 200) == user.nickname end ++ test "multiple users" do ++ admin = insert(:user, info: %{is_admin: true}) ++ user_one = insert(:user) ++ user_two = insert(:user) ++ ++ conn = ++ build_conn() ++ |> assign(:user, admin) ++ |> put_req_header("accept", "application/json") ++ |> delete("/api/pleroma/admin/users", %{ ++ nicknames: [user_one.nickname, user_two.nickname] ++ }) ++ ++ log_entry = Repo.one(ModerationLog) ++ ++ assert ModerationLog.get_log_entry_message(log_entry) == ++ "@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}" ++ ++ response = json_response(conn, 200) ++ assert response -- [user_one.nickname, user_two.nickname] == [] ++ end ++ end ++ ++ describe "/api/pleroma/admin/users" do test "Create" do admin = insert(:user, info: %{is_admin: true})