mirror of
https://git.pleroma.social/sjw/pleroma.git
synced 2024-12-29 18:45:21 +01:00
Merge branch 'twitterapi-show-user' into 'develop'
TwitterAPI: Add /users/show. See merge request pleroma/pleroma!19
This commit is contained in:
commit
1eb7a862d2
@ -140,6 +140,7 @@ defmodule Pleroma.Web.Router do
|
||||
get "/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline
|
||||
get "/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
|
||||
get "/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline
|
||||
get "/users/show", TwitterAPI.Controller, :show_user
|
||||
|
||||
get "/statuses/show/:id", TwitterAPI.Controller, :fetch_status
|
||||
get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
|
||||
|
@ -65,6 +65,19 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
||||
|> json_reply(200, json)
|
||||
end
|
||||
|
||||
def show_user(conn, params) do
|
||||
with {:ok, shown} <- TwitterAPI.get_user(params) do
|
||||
if user = conn.assigns.user do
|
||||
render conn, UserView, "show.json", %{user: shown, for: user}
|
||||
else
|
||||
render conn, UserView, "show.json", %{user: shown}
|
||||
end
|
||||
else
|
||||
{:error, msg} ->
|
||||
bad_request_reply(conn, msg)
|
||||
end
|
||||
end
|
||||
|
||||
def user_timeline(%{assigns: %{user: user}} = conn, params) do
|
||||
case TwitterAPI.get_user(user, params) do
|
||||
{:ok, target_user} ->
|
||||
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.TwitterAPI.UserView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@ -101,6 +102,45 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/show.json" do
|
||||
test "gets user with screen_name", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"screen_name" => user.nickname})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["id"] == user.id
|
||||
end
|
||||
|
||||
test "gets user with user_id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["id"] == user.id
|
||||
end
|
||||
|
||||
test "gets a user for a logged in user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
logged_in = insert(:user)
|
||||
|
||||
{:ok, logged_in, user, _activity} = TwitterAPI.follow(logged_in, %{"user_id" => user.id})
|
||||
|
||||
conn = conn
|
||||
|> with_credentials(logged_in.nickname, "test")
|
||||
|> get("/api/users/show.json", %{"user_id" => user.id})
|
||||
|
||||
response = json_response(conn, 200)
|
||||
|
||||
assert response["following"] == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /statusnet/conversation/:id.json" do
|
||||
test "returns the statuses in the conversation", %{conn: conn} do
|
||||
{:ok, _user} = UserBuilder.insert
|
||||
|
Loading…
Reference in New Issue
Block a user