forked from AkkomaGang/akkoma
Merge branch 'fix/follow-imports' into 'develop'
Handle new-style mastodon follow lists Closes #814 See merge request pleroma/pleroma!1067
This commit is contained in:
commit
5f31e7ec6b
2 changed files with 21 additions and 1 deletions
|
@ -304,7 +304,12 @@ def follow_import(conn, %{"list" => %Plug.Upload{} = listfile}) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_import(%{assigns: %{user: follower}} = conn, %{"list" => list}) do
|
def follow_import(%{assigns: %{user: follower}} = conn, %{"list" => list}) do
|
||||||
with followed_identifiers <- String.split(list),
|
with lines <- String.split(list, "\n"),
|
||||||
|
followed_identifiers <-
|
||||||
|
Enum.map(lines, fn line ->
|
||||||
|
String.split(line, ",") |> List.first()
|
||||||
|
end)
|
||||||
|
|> List.delete("Account address"),
|
||||||
{:ok, _} = Task.start(fn -> User.follow_import(follower, followed_identifiers) end) do
|
{:ok, _} = Task.start(fn -> User.follow_import(follower, followed_identifiers) end) do
|
||||||
json(conn, "job started")
|
json(conn, "job started")
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,21 @@ test "it returns HTTP 200", %{conn: conn} do
|
||||||
assert response == "job started"
|
assert response == "job started"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it imports new-style mastodon follow lists", %{conn: conn} do
|
||||||
|
user1 = insert(:user)
|
||||||
|
user2 = insert(:user)
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user1)
|
||||||
|
|> post("/api/pleroma/follow_import", %{
|
||||||
|
"list" => "Account address,Show boosts\n#{user2.ap_id},true"
|
||||||
|
})
|
||||||
|
|> json_response(:ok)
|
||||||
|
|
||||||
|
assert response == "job started"
|
||||||
|
end
|
||||||
|
|
||||||
test "requires 'follow' permission", %{conn: conn} do
|
test "requires 'follow' permission", %{conn: conn} do
|
||||||
token1 = insert(:oauth_token, scopes: ["read", "write"])
|
token1 = insert(:oauth_token, scopes: ["read", "write"])
|
||||||
token2 = insert(:oauth_token, scopes: ["follow"])
|
token2 = insert(:oauth_token, scopes: ["follow"])
|
||||||
|
|
Loading…
Reference in a new issue