forked from AkkomaGang/akkoma
CommonValidations: Treat deactivated users as not present.
This commit is contained in:
parent
0cfadcf2ca
commit
1a00713744
2 changed files with 27 additions and 4 deletions
|
@ -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)
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue