Remove GET /api/v1/announcements/:id
This commit is contained in:
parent
d569694ae9
commit
881179ec72
@ -25,27 +25,6 @@ defmodule Pleroma.Web.ApiSpec.AnnouncementOperation 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"],
|
||||
|
@ -59,22 +59,4 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementController 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
|
||||
|
@ -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
|
||||
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest 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 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest 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 @@ defmodule Pleroma.Web.MastodonAPI.AnnouncementControllerTest 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"])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user