1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ModerationLogTest do
7 alias Pleroma.ModerationLog
9 use Pleroma.DataCase, async: true
11 import Pleroma.Factory
13 describe "user moderation" do
15 admin = insert(:user, is_admin: true)
16 moderator = insert(:user, is_moderator: true)
17 subject1 = insert(:user)
18 subject2 = insert(:user)
20 [admin: admin, moderator: moderator, subject1: subject1, subject2: subject2]
23 test "logging user deletion by moderator", %{moderator: moderator, subject1: subject1} do
25 ModerationLog.insert_log(%{
31 log = Repo.one(ModerationLog)
33 assert log.data["message"] == "@#{moderator.nickname} deleted users: @#{subject1.nickname}"
36 test "logging user creation by moderator", %{
42 ModerationLog.insert_log(%{
44 subjects: [subject1, subject2],
48 log = Repo.one(ModerationLog)
50 assert log.data["message"] ==
51 "@#{moderator.nickname} created users: @#{subject1.nickname}, @#{subject2.nickname}"
54 test "logging user follow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
56 ModerationLog.insert_log(%{
63 log = Repo.one(ModerationLog)
65 assert log.data["message"] ==
66 "@#{admin.nickname} made @#{subject2.nickname} follow @#{subject1.nickname}"
69 test "logging user unfollow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
71 ModerationLog.insert_log(%{
78 log = Repo.one(ModerationLog)
80 assert log.data["message"] ==
81 "@#{admin.nickname} made @#{subject2.nickname} unfollow @#{subject1.nickname}"
84 test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
86 ModerationLog.insert_log(%{
88 nicknames: [subject1.nickname, subject2.nickname],
93 log = Repo.one(ModerationLog)
96 [subject1.nickname, subject2.nickname]
97 |> Enum.map(&"@#{&1}")
100 tags = ["foo", "bar"] |> Enum.join(", ")
102 assert log.data["message"] == "@#{admin.nickname} added tags: #{tags} to users: #{users}"
105 test "logging user untagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
107 ModerationLog.insert_log(%{
109 nicknames: [subject1.nickname, subject2.nickname],
110 tags: ["foo", "bar"],
114 log = Repo.one(ModerationLog)
117 [subject1.nickname, subject2.nickname]
118 |> Enum.map(&"@#{&1}")
121 tags = ["foo", "bar"] |> Enum.join(", ")
123 assert log.data["message"] ==
124 "@#{admin.nickname} removed tags: #{tags} from users: #{users}"
127 test "logging user grant by moderator", %{moderator: moderator, subject1: subject1} do
129 ModerationLog.insert_log(%{
133 permission: "moderator"
136 log = Repo.one(ModerationLog)
138 assert log.data["message"] == "@#{moderator.nickname} made @#{subject1.nickname} moderator"
141 test "logging user revoke by moderator", %{moderator: moderator, subject1: subject1} do
143 ModerationLog.insert_log(%{
147 permission: "moderator"
150 log = Repo.one(ModerationLog)
152 assert log.data["message"] ==
153 "@#{moderator.nickname} revoked moderator role from @#{subject1.nickname}"
156 test "logging relay follow", %{moderator: moderator} do
158 ModerationLog.insert_log(%{
160 action: "relay_follow",
161 target: "https://example.org/relay"
164 log = Repo.one(ModerationLog)
166 assert log.data["message"] ==
167 "@#{moderator.nickname} followed relay: https://example.org/relay"
170 test "logging relay unfollow", %{moderator: moderator} do
172 ModerationLog.insert_log(%{
174 action: "relay_unfollow",
175 target: "https://example.org/relay"
178 log = Repo.one(ModerationLog)
180 assert log.data["message"] ==
181 "@#{moderator.nickname} unfollowed relay: https://example.org/relay"
184 test "logging report update", %{moderator: moderator} do
188 id: "9m9I1F4p8ftrTP6QTI",
191 "state" => "resolved",
192 "actor" => user.ap_id
197 ModerationLog.insert_log(%{
199 action: "report_update",
204 log = Repo.one(ModerationLog)
206 assert log.data["message"] ==
207 "@#{moderator.nickname} updated report ##{report.id} (on user @#{user.nickname}) with 'resolved' state"
210 test "logging report response", %{moderator: moderator} do
214 id: "9m9I1F4p8ftrTP6QTI",
217 "actor" => user.ap_id
223 action: "report_note",
228 {:ok, log1} = ModerationLog.insert_log(attrs)
229 log = Repo.get(ModerationLog, log1.id)
231 assert log.data["message"] ==
232 "@#{moderator.nickname} added note 'look at this' to report ##{report.id}"
234 {:ok, log2} = ModerationLog.insert_log(Map.merge(attrs, %{subject_actor: user}))
236 log = Repo.get(ModerationLog, log2.id)
238 assert log.data["message"] ==
239 "@#{moderator.nickname} added note 'look at this' to report ##{report.id} on user @#{user.nickname}"
242 test "logging status sensitivity update", %{moderator: moderator} do
243 note = insert(:note_activity)
246 ModerationLog.insert_log(%{
248 action: "status_update",
254 log = Repo.one(ModerationLog)
256 assert log.data["message"] ==
257 "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
260 test "logging status visibility update", %{moderator: moderator} do
261 note = insert(:note_activity)
264 ModerationLog.insert_log(%{
266 action: "status_update",
269 visibility: "private"
272 log = Repo.one(ModerationLog)
274 assert log.data["message"] ==
275 "@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
278 test "logging status sensitivity & visibility update", %{moderator: moderator} do
279 note = insert(:note_activity)
282 ModerationLog.insert_log(%{
284 action: "status_update",
287 visibility: "private"
290 log = Repo.one(ModerationLog)
292 assert log.data["message"] ==
293 "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
296 test "logging status deletion", %{moderator: moderator} do
297 note = insert(:note_activity)
300 ModerationLog.insert_log(%{
302 action: "status_delete",
306 log = Repo.one(ModerationLog)
308 assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"