Merge branch 'deactivated-user-posts' into 'develop'

Deactivated user posts

Closes #2011

See merge request pleroma/pleroma!2845
This commit is contained in:
rinpatch 2020-08-04 19:17:30 +00:00
commit b1b6a7dfa8
7 changed files with 46 additions and 9 deletions

View File

@ -120,6 +120,8 @@
config :tzdata, :autoupdate, :disabled config :tzdata, :autoupdate, :disabled
config :pleroma, :mrf, policies: []
if File.exists?("./config/test.secret.exs") do if File.exists?("./config/test.secret.exs") do
import_config "test.secret.exs" import_config "test.secret.exs"
else else

View File

@ -34,9 +34,14 @@ def validate_actor_presence(cng, options \\ []) do
cng cng
|> validate_change(field_name, fn field_name, actor -> |> validate_change(field_name, fn field_name, actor ->
if User.get_cached_by_ap_id(actor) do case User.get_cached_by_ap_id(actor) do
%User{deactivated: true} ->
[{field_name, "user is deactivated"}]
%User{} ->
[] []
else
_ ->
[{field_name, "can't find user"}] [{field_name, "can't find user"}]
end end
end) end)

View File

@ -50,13 +50,13 @@ test "with errors" do
defp assert_app(name, redirect, scopes) do defp assert_app(name, redirect, scopes) do
app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name) app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "#{name} successfully created:" assert message == "#{name} successfully created:"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "App client_id: #{app.client_id}" assert message == "App client_id: #{app.client_id}"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "App client_secret: #{app.client_secret}" assert message == "App client_secret: #{app.client_secret}"
assert app.scopes == scopes assert app.scopes == scopes

View File

@ -124,6 +124,24 @@ test "it fetches the actor if they aren't in our system" do
{:ok, %Activity{} = _activity} = Transmogrifier.handle_incoming(data) {:ok, %Activity{} = _activity} = Transmogrifier.handle_incoming(data)
end end
test "it doesn't work for deactivated users" do
data =
File.read!("test/fixtures/create-chat-message.json")
|> Poison.decode!()
_author =
insert(:user,
ap_id: data["actor"],
local: false,
last_refreshed_at: DateTime.utc_now(),
deactivated: true
)
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
assert {:error, _} = Transmogrifier.handle_incoming(data)
end
test "it inserts it and creates a chat" do test "it inserts it and creates a chat" do
data = data =
File.read!("test/fixtures/create-chat-message.json") File.read!("test/fixtures/create-chat-message.json")

View File

@ -163,6 +163,14 @@ test "it does not crash if the object in inReplyTo can't be fetched" do
end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil" end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
end end
test "it does not work for deactivated users" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
insert(:user, ap_id: data["actor"], deactivated: true)
assert {:error, _} = Transmogrifier.handle_incoming(data)
end
test "it works for incoming notices" do test "it works for incoming notices" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!() data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()

View File

@ -458,6 +458,11 @@ test "it adds emoji in the object" do
end end
describe "posting" do describe "posting" do
test "deactivated users can't post" do
user = insert(:user, deactivated: true)
assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
end
test "it supports explicit addressing" do test "it supports explicit addressing" do
user = insert(:user) user = insert(:user)
user_two = insert(:user) user_two = insert(:user)

View File

@ -17,8 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
test "returns error when followed user is deactivated" do test "returns error when followed user is deactivated" do
follower = insert(:user) follower = insert(:user)
user = insert(:user, local: true, deactivated: true) user = insert(:user, local: true, deactivated: true)
{:error, error} = MastodonAPI.follow(follower, user) assert {:error, _error} = MastodonAPI.follow(follower, user)
assert error == :rejected
end end
test "following for user" do test "following for user" do