From: dtluna Date: Sun, 16 Apr 2017 14:08:17 +0000 (+0300) Subject: Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/user-timeline X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=5229b0194477bea6e513d9e8286956a553133545;p=akkoma Merge branch 'develop' of ssh.gitgud.io:lambadalambda/pleroma into feature/user-timeline --- 5229b0194477bea6e513d9e8286956a553133545 diff --cc lib/pleroma/web/twitter_api/twitter_api_controller.ex index 007b96bc7,b0287a7f4..36e2d235b --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@@ -154,11 -143,18 +155,23 @@@ defmodule Pleroma.Web.TwitterAPI.Contro end end + def update_avatar(%{assigns: %{user: user}} = conn, params) do + {:ok, object} = ActivityPub.upload(params) + change = Ecto.Changeset.change(user, %{avatar: object.data}) + {:ok, user} = Repo.update(change) + + response = UserRepresenter.to_map(user, %{for: user}) + |> Poison.encode! + + conn + |> json_reply(200, response) + end + + defp bad_request_reply(conn, error_message) do + json = Poison.encode!(%{"error" => error_message}) + json_reply(conn, 400, json) + end + defp json_reply(conn, status, json) do conn |> put_resp_content_type("application/json") diff --cc test/web/twitter_api/twitter_api_test.exs index 2f7e77773,1e5204db8..9e843e877 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@@ -99,41 -99,9 +99,41 @@@ defmodule Pleroma.Web.TwitterAPI.Twitte assert length(statuses) == 2 assert Enum.at(statuses, 0) == ActivityRepresenter.to_map(activity, %{user: activity_user}) - assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: activity_user, mentioned: [user]}) + assert Enum.at(statuses, 1) == ActivityRepresenter.to_map(direct_activity, %{user: direct_activity_user, mentioned: [user]}) end + test "get a user by params" do + user1_result = {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"}) + {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"}) + + assert {:error, "You need to specify screen_name or user_id"} == TwitterAPI.get_user(nil, nil) + assert user1_result == TwitterAPI.get_user(nil, %{"user_id" => user1.id}) + assert user1_result == TwitterAPI.get_user(nil, %{"screen_name" => user1.nickname}) + assert user1_result == TwitterAPI.get_user(user1, nil) + assert user1_result == TwitterAPI.get_user(user2, %{"user_id" => user1.id}) + assert user1_result == TwitterAPI.get_user(user2, %{"screen_name" => user1.nickname}) + assert {:error, "No user with such screen_name"} == TwitterAPI.get_user(nil, %{"screen_name" => "Satan"}) + assert {:error, "No user with such user_id"} == TwitterAPI.get_user(nil, %{"user_id" => 666}) + end + + test "fetch user's statuses" do + {:ok, user1} = UserBuilder.insert(%{ap_id: "some id", email: "test@pleroma"}) + {:ok, user2} = UserBuilder.insert(%{ap_id: "some other id", nickname: "testname2", email: "test2@pleroma"}) + + {:ok, status1} = ActivityBuilder.insert(%{"id" => 1}, %{user: user1}) + {:ok, status2} = ActivityBuilder.insert(%{"id" => 2}, %{user: user2}) + + user1_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user1.ap_id}) + + assert length(user1_statuses) == 1 + assert Enum.at(user1_statuses, 0) == ActivityRepresenter.to_map(status1, %{user: user1}) + + user2_statuses = TwitterAPI.fetch_user_statuses(user1, %{"actor_id" => user2.ap_id}) + + assert length(user2_statuses) == 1 + assert Enum.at(user2_statuses, 0) == ActivityRepresenter.to_map(status2, %{user: user2}) + end + test "fetch a single status" do {:ok, activity} = ActivityBuilder.insert() {:ok, user} = UserBuilder.insert()