From 881179ec725c3b71868fdcba983fdedd295e5125 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Tue, 8 Mar 2022 19:22:28 -0500 Subject: [PATCH] Remove GET /api/v1/announcements/:id --- .../operations/announcement_operation.ex | 21 ------- .../controllers/announcement_controller.ex | 18 ------ lib/pleroma/web/router.ex | 1 - .../announcement_controller_test.exs | 56 +------------------ 4 files changed, 2 insertions(+), 94 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/announcement_operation.ex b/lib/pleroma/web/api_spec/operations/announcement_operation.ex index c33b9e135..a66073b8b 100644 --- a/lib/pleroma/web/api_spec/operations/announcement_operation.ex +++ b/lib/pleroma/web/api_spec/operations/announcement_operation.ex @@ -25,27 +25,6 @@ def index_operation do } end - def show_operation do - %Operation{ - tags: ["Announcement"], - summary: "Display one announcement", - operationId: "MastodonAPI.AnnouncementController.show", - parameters: [ - Operation.parameter( - :id, - :path, - :string, - "announcement id" - ) - ], - responses: %{ - 200 => Operation.response("Response", "application/json", Announcement), - 403 => Operation.response("Forbidden", "application/json", ApiError), - 404 => Operation.response("Not Found", "application/json", ApiError) - } - } - end - def mark_read_operation do %Operation{ tags: ["Announcement"], diff --git a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex index a2179f934..e6da7892c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/announcement_controller.ex @@ -59,22 +59,4 @@ def mark_read(%{assigns: %{user: user}} = conn, %{id: id} = _params) do {:error, :not_found} end end - - @doc "GET /api/v1/announcements/:id" - def show(%{assigns: %{user: user}} = conn, %{id: id} = _params) do - render_announcement_by_id(conn, id, user) - end - - def show(conn, %{id: id} = _params) do - render_announcement_by_id(conn, id) - end - - def render_announcement_by_id(conn, id, user \\ nil) do - with announcement when not is_nil(announcement) <- Announcement.get_by_id(id) do - render(conn, "show.json", announcement: announcement, user: user) - else - _ -> - {:error, :not_found} - end - end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 5be9891b1..51a9dec6b 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -628,7 +628,6 @@ defmodule Pleroma.Web.Router do get("/directory", DirectoryController, :index) get("/announcements", AnnouncementController, :index) - get("/announcements/:id", AnnouncementController, :show) end scope "/api/v2", Pleroma.Web.MastodonAPI do diff --git a/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs index e9ee1141c..1c748064c 100644 --- a/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/announcement_controller_test.exs @@ -24,7 +24,7 @@ test "it lists all announcements" do end test "it does not list announcements starting after current time" do - time = NaiveDateTime.utc_now() |> NaiveDateTime.add(999999, :second) + time = NaiveDateTime.utc_now() |> NaiveDateTime.add(999_999, :second) insert(:announcement, starts_at: time) response = @@ -36,7 +36,7 @@ test "it does not list announcements starting after current time" do end test "it does not list announcements ending before current time" do - time = NaiveDateTime.utc_now() |> NaiveDateTime.add(-999999, :second) + time = NaiveDateTime.utc_now() |> NaiveDateTime.add(-999_999, :second) insert(:announcement, ends_at: time) response = @@ -77,58 +77,6 @@ test "when authenticated and announcement is read by user" do end end - describe "GET /api/v1/announcements/:id" do - test "it shows one announcement" do - %{id: id} = insert(:announcement) - - response = - build_conn() - |> get("/api/v1/announcements/#{id}") - |> json_response_and_validate_schema(:ok) - - assert %{"id" => ^id} = response - refute Map.has_key?(response, "read") - end - - test "it gives 404 for non-existent announcements" do - %{id: id} = insert(:announcement) - - _response = - build_conn() - |> get("/api/v1/announcements/#{id}xxx") - |> json_response_and_validate_schema(:not_found) - end - - test "when authenticated, also expose read property" do - %{id: id} = insert(:announcement) - - %{conn: conn} = oauth_access(["read:accounts"]) - - response = - conn - |> get("/api/v1/announcements/#{id}") - |> json_response_and_validate_schema(:ok) - - assert %{"id" => ^id, "read" => false} = response - end - - test "when authenticated and announcement is read by user" do - %{id: id} = announcement = insert(:announcement) - user = insert(:user) - - AnnouncementReadRelationship.mark_read(user, announcement) - - %{conn: conn} = oauth_access(["read:accounts"], user: user) - - response = - conn - |> get("/api/v1/announcements/#{id}") - |> json_response_and_validate_schema(:ok) - - assert %{"id" => ^id, "read" => true} = response - end - end - describe "POST /api/v1/announcements/:id/dismiss" do setup do: oauth_access(["write:accounts"])