forked from AkkomaGang/akkoma
Add error response to self-repeats
This commit is contained in:
parent
6b6bc9435c
commit
f723b23691
2 changed files with 23 additions and 8 deletions
|
@ -163,12 +163,17 @@ def unfavorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
|
|
||||||
def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
activity = Repo.get(Activity, id)
|
activity = Repo.get(Activity, id)
|
||||||
|
if activity.data["actor"] == user.ap_id do
|
||||||
|
bad_request_reply(conn, "You cannot repeat your own notice.")
|
||||||
|
else
|
||||||
{:ok, status} = TwitterAPI.retweet(user, activity)
|
{:ok, status} = TwitterAPI.retweet(user, activity)
|
||||||
response = Poison.encode!(status)
|
response = Poison.encode!(status)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|
|
||||||
|> json_reply(200, response)
|
|> json_reply(200, response)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def register(conn, params) do
|
def register(conn, params) do
|
||||||
with {:ok, user} <- TwitterAPI.register_user(params) do
|
with {:ok, user} <- TwitterAPI.register_user(params) do
|
||||||
|
|
|
@ -328,11 +328,21 @@ test "without valid credentials", %{conn: conn} do
|
||||||
test "with credentials", %{conn: conn, user: current_user} do
|
test "with credentials", %{conn: conn, user: current_user} do
|
||||||
note_activity = insert(:note_activity)
|
note_activity = insert(:note_activity)
|
||||||
|
|
||||||
conn = conn
|
request_path = "/api/statuses/retweet/#{note_activity.id}.json"
|
||||||
|> with_credentials(current_user.nickname, "test")
|
|
||||||
|> post("/api/statuses/retweet/#{note_activity.id}.json")
|
|
||||||
|
|
||||||
assert json_response(conn, 200)
|
user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||||
|
response = conn
|
||||||
|
|> with_credentials(user.nickname, "test")
|
||||||
|
|> post(request_path)
|
||||||
|
assert json_response(response, 400) == %{"error" => "You cannot repeat your own notice.",
|
||||||
|
"request" => request_path}
|
||||||
|
|
||||||
|
response = conn
|
||||||
|
|> with_credentials(current_user.nickname, "test")
|
||||||
|
|> post(request_path)
|
||||||
|
activity = Repo.get(Activity, note_activity.id)
|
||||||
|
current_user = Repo.get_by(User, ap_id: note_activity.data["actor"])
|
||||||
|
assert json_response(response, 200) == ActivityRepresenter.to_map(activity, %{user: current_user})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue