Expose history and source apis to anon users

This commit is contained in:
Tusooa Zhu 2022-06-11 10:35:36 -04:00 committed by Sol Fisher Romanoff
parent 670cbc368a
commit edbe714435
No known key found for this signature in database
GPG key ID: 9D3F2B64F2341B62
3 changed files with 10 additions and 8 deletions

View file

@ -194,8 +194,9 @@ def create(%{assigns: %{user: _user}, body_params: %{media_ids: _} = params} = c
end
@doc "GET /api/v1/statuses/:id/history"
def show_history(%{assigns: %{user: user}} = conn, %{id: id} = params) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
def show_history(%{assigns: assigns} = conn, %{id: id} = params) do
with user = assigns[:user],
%Activity{} = activity <- Activity.get_by_id_with_object(id),
true <- Visibility.visible_for_user?(activity, user) do
try_render(conn, "history.json",
activity: activity,
@ -209,8 +210,9 @@ def show_history(%{assigns: %{user: user}} = conn, %{id: id} = params) do
end
@doc "GET /api/v1/statuses/:id/source"
def show_source(%{assigns: %{user: user}} = conn, %{id: id} = _params) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
def show_source(%{assigns: assigns} = conn, %{id: id} = _params) do
with user = assigns[:user],
%Activity{} = activity <- Activity.get_by_id_with_object(id),
true <- Visibility.visible_for_user?(activity, user) do
try_render(conn, "source.json",
activity: activity,

View file

@ -537,8 +537,6 @@ defmodule Pleroma.Web.Router do
get("/bookmarks", StatusController, :bookmarks)
post("/statuses", StatusController, :create)
get("/statuses/:id/history", StatusController, :show_history)
get("/statuses/:id/source", StatusController, :show_source)
put("/statuses/:id", StatusController, :update)
delete("/statuses/:id", StatusController, :delete)
post("/statuses/:id/reblog", StatusController, :reblog)
@ -604,6 +602,8 @@ defmodule Pleroma.Web.Router do
get("/statuses/:id/context", StatusController, :context)
get("/statuses/:id/favourited_by", StatusController, :favourited_by)
get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
get("/statuses/:id/history", StatusController, :show_history)
get("/statuses/:id/source", StatusController, :show_source)
get("/custom_emojis", CustomEmojiController, :index)

View file

@ -2045,7 +2045,7 @@ test "posting a quote of a status that doesn't exist", %{conn: conn} do
describe "get status history" do
setup do
oauth_access(["read:statuses"])
%{conn: build_conn()}
end
test "unedited post", %{conn: conn} do
@ -2091,7 +2091,7 @@ test "edited post", %{conn: conn} do
describe "get status source" do
setup do
oauth_access(["read:statuses"])
%{conn: build_conn()}
end
test "it returns the source", %{conn: conn} do