Merge branch 'develop' into feature/admin-api-list-statuses-for-a-given-instance
authorMaxim Filippov <colixer@gmail.com>
Sun, 24 Nov 2019 16:46:18 +0000 (01:46 +0900)
committerMaxim Filippov <colixer@gmail.com>
Sun, 24 Nov 2019 16:46:18 +0000 (01:46 +0900)
1  2 
CHANGELOG.md
lib/pleroma/web/admin_api/admin_api_controller.ex
lib/pleroma/web/router.ex
test/web/admin_api/admin_api_controller_test.exs

diff --cc CHANGELOG.md
index 3e22d7acb23f0404927fe20c3690f8a6c0f80671,8db8039b842efdbd29c772aec076bab6e8aa1029..68a9d93d819a17de2ba3d45c15d7aa47c8792f4e
@@@ -69,7 -70,7 +70,8 @@@ The format is based on [Keep a Changelo
  - Mastodon API: Add the `recipients` parameter to `GET /api/v1/conversations`
  - Configuration: `feed` option for user atom feed.
  - Pleroma API: Add Emoji reactions
 +- Admin API: Add `/api/pleroma/admin/instances/:instance/statuses` - lists all statuses from a given instance
+ - Admin API: `PATCH /api/pleroma/users/confirm_email` to confirm email for multiple users, `PATCH /api/pleroma/users/resend_confirmation_email` to resend confirmation email for multiple users
  </details>
  
  ### Fixed
index 12b676065b97e3ba6a8220d9da5bb3db2b38c0f4,0b54f4ab7b665f1abb67c03f809a549853fa884c..e6c4f6f1495d1c14c6c1eac0218a325e02ab89d5
@@@ -178,8 -178,9 +178,11 @@@ defmodule Pleroma.Web.Router d
      get("/users/:nickname", AdminAPIController, :user_show)
      get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
  
 +    get("/instances/:instance/statuses", AdminAPIController, :list_instance_statuses)
 +
+     patch("/users/confirm_email", AdminAPIController, :confirm_email)
+     patch("/users/resend_confirmation_email", AdminAPIController, :resend_confirmation_email)
      get("/reports", AdminAPIController, :list_reports)
      get("/grouped_reports", AdminAPIController, :list_grouped_reports)
      get("/reports/:id", AdminAPIController, :report_show)
index 471477f2c5182c26dfee6898c7c21b998e38caa6,9b4f359dc8bbf4fc60dfef468de24e3a46f348ec..bb2ca6a62d293ecb7e95ce9845af1b06941f2fde
@@@ -2840,42 -2862,67 +2862,104 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI
      end
    end
  
 +  describe "instances" do
 +    test "GET /instances/:instance/statuses" do
 +      admin = insert(:user, is_admin: true)
 +      user = insert(:user, local: false, nickname: "archaeme@archae.me")
 +      user2 = insert(:user, local: false, nickname: "test@test.com")
 +      insert_pair(:note_activity, user: user)
 +      insert(:note_activity, user: user2)
 +
 +      conn =
 +        build_conn()
 +        |> assign(:user, admin)
 +        |> get("/api/pleroma/admin/instances/archae.me/statuses")
 +
 +      response = json_response(conn, 200)
 +
 +      assert length(response) == 2
 +
 +      conn =
 +        build_conn()
 +        |> assign(:user, admin)
 +        |> get("/api/pleroma/admin/instances/test.com/statuses")
 +
 +      response = json_response(conn, 200)
 +
 +      assert length(response) == 1
 +
 +      conn =
 +        build_conn()
 +        |> assign(:user, admin)
 +        |> get("/api/pleroma/admin/instances/nonexistent.com/statuses")
 +
 +      response = json_response(conn, 200)
 +
 +      assert length(response) == 0
 +    end
 +  end
++
+   describe "PATCH /confirm_email" do
+     setup %{conn: conn} do
+       admin = insert(:user, is_admin: true)
+       %{conn: assign(conn, :user, admin), admin: admin}
+     end
+     test "it confirms emails of two users", %{admin: admin} do
+       [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
+       assert first_user.confirmation_pending == true
+       assert second_user.confirmation_pending == true
+       build_conn()
+       |> assign(:user, admin)
+       |> patch("/api/pleroma/admin/users/confirm_email", %{
+         nicknames: [
+           first_user.nickname,
+           second_user.nickname
+         ]
+       })
+       assert first_user.confirmation_pending == true
+       assert second_user.confirmation_pending == true
+       log_entry = Repo.one(ModerationLog)
+       assert ModerationLog.get_log_entry_message(log_entry) ==
+                "@#{admin.nickname} confirmed email for users: @#{first_user.nickname}, @#{
+                  second_user.nickname
+                }"
+     end
+   end
+   describe "PATCH /resend_confirmation_email" do
+     setup %{conn: conn} do
+       admin = insert(:user, is_admin: true)
+       %{conn: assign(conn, :user, admin), admin: admin}
+     end
+     test "it resend emails for two users", %{admin: admin} do
+       [first_user, second_user] = insert_pair(:user, confirmation_pending: true)
+       build_conn()
+       |> assign(:user, admin)
+       |> patch("/api/pleroma/admin/users/resend_confirmation_email", %{
+         nicknames: [
+           first_user.nickname,
+           second_user.nickname
+         ]
+       })
+       log_entry = Repo.one(ModerationLog)
+       assert ModerationLog.get_log_entry_message(log_entry) ==
+                "@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
+                  second_user.nickname
+                }"
+     end
+   end
  end
  
  # Needed for testing