Remove GET /api/v1/announcements/:id
This commit is contained in:
parent
d569694ae9
commit
881179ec72
|
@ -25,27 +25,6 @@ def index_operation do
|
||||||
}
|
}
|
||||||
end
|
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
|
def mark_read_operation do
|
||||||
%Operation{
|
%Operation{
|
||||||
tags: ["Announcement"],
|
tags: ["Announcement"],
|
||||||
|
|
|
@ -59,22 +59,4 @@ def mark_read(%{assigns: %{user: user}} = conn, %{id: id} = _params) do
|
||||||
{:error, :not_found}
|
{:error, :not_found}
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -628,7 +628,6 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/directory", DirectoryController, :index)
|
get("/directory", DirectoryController, :index)
|
||||||
|
|
||||||
get("/announcements", AnnouncementController, :index)
|
get("/announcements", AnnouncementController, :index)
|
||||||
get("/announcements/:id", AnnouncementController, :show)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/v2", Pleroma.Web.MastodonAPI do
|
scope "/api/v2", Pleroma.Web.MastodonAPI do
|
||||||
|
|
|
@ -24,7 +24,7 @@ test "it lists all announcements" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not list announcements starting after current time" do
|
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)
|
insert(:announcement, starts_at: time)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
@ -36,7 +36,7 @@ test "it does not list announcements starting after current time" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it does not list announcements ending before current time" do
|
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)
|
insert(:announcement, ends_at: time)
|
||||||
|
|
||||||
response =
|
response =
|
||||||
|
@ -77,58 +77,6 @@ test "when authenticated and announcement is read by user" do
|
||||||
end
|
end
|
||||||
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
|
describe "POST /api/v1/announcements/:id/dismiss" do
|
||||||
setup do: oauth_access(["write:accounts"])
|
setup do: oauth_access(["write:accounts"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue