1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ModerationLogTest do
7 alias Pleroma.ModerationLog
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
186 id: "9m9I1F4p8ftrTP6QTI",
189 "state" => "resolved"
194 ModerationLog.insert_log(%{
196 action: "report_update",
200 log = Repo.one(ModerationLog)
202 assert log.data["message"] ==
203 "@#{moderator.nickname} updated report ##{report.id} with 'resolved' state"
206 test "logging report response", %{moderator: moderator} do
208 id: "9m9I1F4p8ftrTP6QTI",
215 ModerationLog.insert_log(%{
217 action: "report_note",
222 log = Repo.one(ModerationLog)
224 assert log.data["message"] ==
225 "@#{moderator.nickname} added note 'look at this' to report ##{report.id}"
228 test "logging status sensitivity update", %{moderator: moderator} do
229 note = insert(:note_activity)
232 ModerationLog.insert_log(%{
234 action: "status_update",
240 log = Repo.one(ModerationLog)
242 assert log.data["message"] ==
243 "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
246 test "logging status visibility update", %{moderator: moderator} do
247 note = insert(:note_activity)
250 ModerationLog.insert_log(%{
252 action: "status_update",
255 visibility: "private"
258 log = Repo.one(ModerationLog)
260 assert log.data["message"] ==
261 "@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
264 test "logging status sensitivity & visibility update", %{moderator: moderator} do
265 note = insert(:note_activity)
268 ModerationLog.insert_log(%{
270 action: "status_update",
273 visibility: "private"
276 log = Repo.one(ModerationLog)
278 assert log.data["message"] ==
279 "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
282 test "logging status deletion", %{moderator: moderator} do
283 note = insert(:note_activity)
286 ModerationLog.insert_log(%{
288 action: "status_delete",
292 log = Repo.one(ModerationLog)
294 assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"