1
0
Fork 0
forked from AkkomaGang/akkoma
akkoma/test/pleroma/moderation_log_test.exs

314 lines
8.6 KiB
Elixir
Raw Normal View History

2019-08-25 19:39:37 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
2019-08-25 19:39:37 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.ModerationLogTest do
alias Pleroma.Activity
alias Pleroma.ModerationLog
use Pleroma.DataCase, async: true
2019-08-25 19:39:37 +00:00
import Pleroma.Factory
describe "user moderation" do
setup do
admin = insert(:user, is_admin: true)
moderator = insert(:user, is_moderator: true)
2019-08-25 19:39:37 +00:00
subject1 = insert(:user)
subject2 = insert(:user)
[admin: admin, moderator: moderator, subject1: subject1, subject2: subject2]
end
test "logging user deletion by moderator", %{moderator: moderator, subject1: subject1} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
subject: [subject1],
2019-08-25 19:39:37 +00:00
action: "delete"
})
log = Repo.one(ModerationLog)
assert log.data["message"] == "@#{moderator.nickname} deleted users: @#{subject1.nickname}"
2019-08-25 19:39:37 +00:00
end
test "logging user creation by moderator", %{
moderator: moderator,
subject1: subject1,
subject2: subject2
} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
subjects: [subject1, subject2],
action: "create"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} created users: @#{subject1.nickname}, @#{subject2.nickname}"
end
test "logging user follow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: admin,
followed: subject1,
follower: subject2,
action: "follow"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{admin.nickname} made @#{subject2.nickname} follow @#{subject1.nickname}"
end
test "logging user unfollow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: admin,
followed: subject1,
follower: subject2,
action: "unfollow"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{admin.nickname} made @#{subject2.nickname} unfollow @#{subject1.nickname}"
end
test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: admin,
nicknames: [subject1.nickname, subject2.nickname],
tags: ["foo", "bar"],
action: "tag"
})
log = Repo.one(ModerationLog)
users =
[subject1.nickname, subject2.nickname]
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["foo", "bar"] |> Enum.join(", ")
2019-08-30 21:57:15 +00:00
assert log.data["message"] == "@#{admin.nickname} added tags: #{tags} to users: #{users}"
2019-08-25 19:39:37 +00:00
end
test "logging user untagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: admin,
nicknames: [subject1.nickname, subject2.nickname],
tags: ["foo", "bar"],
action: "untag"
})
log = Repo.one(ModerationLog)
users =
[subject1.nickname, subject2.nickname]
|> Enum.map(&"@#{&1}")
|> Enum.join(", ")
tags = ["foo", "bar"] |> Enum.join(", ")
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
end
test "logging user grant by moderator", %{moderator: moderator, subject1: subject1} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
subject: [subject1],
2019-08-25 19:39:37 +00:00
action: "grant",
permission: "moderator"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] == "@#{moderator.nickname} made @#{subject1.nickname} moderator"
2019-08-25 19:39:37 +00:00
end
test "logging user revoke by moderator", %{moderator: moderator, subject1: subject1} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
subject: [subject1],
2019-08-25 19:39:37 +00:00
action: "revoke",
permission: "moderator"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} revoked moderator role from @#{subject1.nickname}"
end
test "logging relay follow", %{moderator: moderator} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "relay_follow",
target: "https://example.org/relay"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} followed relay: https://example.org/relay"
end
test "logging relay unfollow", %{moderator: moderator} do
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "relay_unfollow",
target: "https://example.org/relay"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
end
test "logging report update", %{moderator: moderator} do
2020-11-25 13:44:11 +00:00
user = insert(:user)
2019-08-25 19:39:37 +00:00
report = %Activity{
id: "9m9I1F4p8ftrTP6QTI",
data: %{
"type" => "Flag",
2020-11-19 19:13:45 +00:00
"state" => "resolved",
2020-11-25 13:44:11 +00:00
"actor" => user.ap_id
2019-08-25 19:39:37 +00:00
}
}
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "report_update",
2020-11-25 13:44:11 +00:00
subject: report,
subject_actor: user
2019-08-25 19:39:37 +00:00
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2020-11-25 13:44:11 +00:00
"@#{moderator.nickname} updated report ##{report.id} (on user @#{user.nickname}) with 'resolved' state"
2019-08-25 19:39:37 +00:00
end
test "logging report response", %{moderator: moderator} do
2020-11-19 19:13:45 +00:00
user = insert(:user)
2019-08-25 19:39:37 +00:00
report = %Activity{
id: "9m9I1F4p8ftrTP6QTI",
data: %{
2020-11-19 19:13:45 +00:00
"type" => "Note",
"actor" => user.ap_id
2019-08-25 19:39:37 +00:00
}
}
2020-11-19 19:13:45 +00:00
attrs = %{
actor: moderator,
action: "report_note",
subject: report,
text: "look at this"
}
2019-08-25 19:39:37 +00:00
2020-11-19 19:13:45 +00:00
{:ok, log1} = ModerationLog.insert_log(attrs)
log = Repo.get(ModerationLog, log1.id)
2019-08-25 19:39:37 +00:00
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-12-08 08:35:38 +00:00
"@#{moderator.nickname} added note 'look at this' to report ##{report.id}"
2020-11-19 19:13:45 +00:00
{:ok, log2} = ModerationLog.insert_log(Map.merge(attrs, %{subject_actor: user}))
log = Repo.get(ModerationLog, log2.id)
assert log.data["message"] ==
"@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{
user.nickname
}"
2019-08-25 19:39:37 +00:00
end
test "logging status sensitivity update", %{moderator: moderator} do
note = insert(:note_activity)
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "status_update",
subject: note,
sensitive: "true",
visibility: nil
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
end
test "logging status visibility update", %{moderator: moderator} do
note = insert(:note_activity)
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "status_update",
subject: note,
sensitive: nil,
visibility: "private"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
end
test "logging status sensitivity & visibility update", %{moderator: moderator} do
note = insert(:note_activity)
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "status_update",
subject: note,
sensitive: "true",
visibility: "private"
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] ==
2019-08-25 19:39:37 +00:00
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
end
test "logging status deletion", %{moderator: moderator} do
note = insert(:note_activity)
{:ok, _} =
ModerationLog.insert_log(%{
actor: moderator,
action: "status_delete",
subject_id: note.id
})
log = Repo.one(ModerationLog)
2019-08-30 21:57:15 +00:00
assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"
2019-08-25 19:39:37 +00:00
end
end
end