Merge branch 'develop' into feature/moderation-log-filters
authorMaxim Filippov <colixer@gmail.com>
Thu, 26 Sep 2019 16:01:54 +0000 (19:01 +0300)
committerMaxim Filippov <colixer@gmail.com>
Thu, 26 Sep 2019 16:01:54 +0000 (19:01 +0300)
1  2 
CHANGELOG.md
lib/pleroma/user/info.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

diff --cc CHANGELOG.md
index 1766b9e4cf26fd1b05be7437a78d8820f6634af4,1a76e6cf85692716a47987e2212d138fe3160d22..d9ddb5b03500e1a60aca9a69db0031cb9f3f8b18
@@@ -113,10 -110,7 +110,8 @@@ The format is based on [Keep a Changelo
  - Admin API: Added moderation log
  - Web response cache (currently, enabled for ActivityPub)
  - Mastodon API: Added an endpoint to get multiple statuses by IDs (`GET /api/v1/statuses/?ids[]=1&ids[]=2`)
+ - ActivityPub: Add ActivityPub actor's `discoverable` parameter.
 +- Admin API: Added moderation log filters (user/start date/end date/search/pagination)
  
  ### Changed
  - Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
Simple merge
index 66804faacb03e238d09642107c03f94e84ae8b32,00e64692aa298664e6fe54d939956683433cd33b..b5c355e66f3eb9c36f6ad41bf676306f8f518c26
@@@ -2359,111 -2354,31 +2357,135 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI
        assert second_entry["message"] ==
                 "@#{admin.nickname} followed relay: https://example.org/relay"
      end
 +
 +    test "filters log by date", %{conn: conn, admin: admin} do
 +      first_date = "2017-08-15T15:47:06Z"
 +      second_date = "2017-08-20T15:47:06Z"
 +
 +      Repo.insert(%ModerationLog{
 +        data: %{
 +          actor: %{
 +            "id" => admin.id,
 +            "nickname" => admin.nickname,
 +            "type" => "user"
 +          },
 +          action: "relay_follow",
 +          target: "https://example.org/relay"
 +        },
 +        inserted_at: NaiveDateTime.from_iso8601!(first_date)
 +      })
 +
 +      Repo.insert(%ModerationLog{
 +        data: %{
 +          actor: %{
 +            "id" => admin.id,
 +            "nickname" => admin.nickname,
 +            "type" => "user"
 +          },
 +          action: "relay_unfollow",
 +          target: "https://example.org/relay"
 +        },
 +        inserted_at: NaiveDateTime.from_iso8601!(second_date)
 +      })
 +
 +      conn1 =
 +        get(
 +          conn,
 +          "/api/pleroma/admin/moderation_log?start_date=#{second_date}"
 +        )
 +
 +      response1 = json_response(conn1, 200)
 +      [first_entry] = response1["items"]
 +
 +      assert response1["total"] == 1
 +      assert first_entry["data"]["action"] == "relay_unfollow"
 +
 +      assert first_entry["message"] ==
 +               "@#{admin.nickname} unfollowed relay: https://example.org/relay"
 +    end
 +
 +    test "returns log filtered by user", %{conn: conn, admin: admin, moderator: moderator} do
 +      Repo.insert(%ModerationLog{
 +        data: %{
 +          actor: %{
 +            "id" => admin.id,
 +            "nickname" => admin.nickname,
 +            "type" => "user"
 +          },
 +          action: "relay_follow",
 +          target: "https://example.org/relay"
 +        }
 +      })
 +
 +      Repo.insert(%ModerationLog{
 +        data: %{
 +          actor: %{
 +            "id" => moderator.id,
 +            "nickname" => moderator.nickname,
 +            "type" => "user"
 +          },
 +          action: "relay_unfollow",
 +          target: "https://example.org/relay"
 +        }
 +      })
 +
 +      conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
 +
 +      response1 = json_response(conn1, 200)
 +      [first_entry] = response1["items"]
 +
 +      assert response1["total"] == 1
 +      assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
 +    end
 +
 +    test "returns log filtered by search", %{conn: conn, moderator: moderator} do
 +      ModerationLog.insert_log(%{
 +        actor: moderator,
 +        action: "relay_follow",
 +        target: "https://example.org/relay"
 +      })
 +
 +      ModerationLog.insert_log(%{
 +        actor: moderator,
 +        action: "relay_unfollow",
 +        target: "https://example.org/relay"
 +      })
 +
 +      conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
 +
 +      response1 = json_response(conn1, 200)
 +      [first_entry] = response1["items"]
 +
 +      assert response1["total"] == 1
 +
 +      assert get_in(first_entry, ["data", "message"]) ==
 +               "@#{moderator.nickname} unfollowed relay: https://example.org/relay"
 +    end
    end
+   describe "PATCH /users/:nickname/force_password_reset" do
+     setup %{conn: conn} do
+       admin = insert(:user, info: %{is_admin: true})
+       user = insert(:user)
+       %{conn: assign(conn, :user, admin), admin: admin, user: user}
+     end
+     test "sets password_reset_pending to true", %{admin: admin, user: user} do
+       assert user.info.password_reset_pending == false
+       conn =
+         build_conn()
+         |> assign(:user, admin)
+         |> patch("/api/pleroma/admin/users/#{user.nickname}/force_password_reset")
+       assert json_response(conn, 204) == ""
+       ObanHelpers.perform_all()
+       assert User.get_by_id(user.id).info.password_reset_pending == true
+     end
+   end
  end
  
  # Needed for testing