logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

moderation_log_test.exs (8307B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.ModerationLogTest do
  5. alias Pleroma.Activity
  6. alias Pleroma.ModerationLog
  7. use Pleroma.DataCase
  8. import Pleroma.Factory
  9. describe "user moderation" do
  10. setup do
  11. admin = insert(:user, is_admin: true)
  12. moderator = insert(:user, is_moderator: true)
  13. subject1 = insert(:user)
  14. subject2 = insert(:user)
  15. [admin: admin, moderator: moderator, subject1: subject1, subject2: subject2]
  16. end
  17. test "logging user deletion by moderator", %{moderator: moderator, subject1: subject1} do
  18. {:ok, _} =
  19. ModerationLog.insert_log(%{
  20. actor: moderator,
  21. subject: [subject1],
  22. action: "delete"
  23. })
  24. log = Repo.one(ModerationLog)
  25. assert log.data["message"] == "@#{moderator.nickname} deleted users: @#{subject1.nickname}"
  26. end
  27. test "logging user creation by moderator", %{
  28. moderator: moderator,
  29. subject1: subject1,
  30. subject2: subject2
  31. } do
  32. {:ok, _} =
  33. ModerationLog.insert_log(%{
  34. actor: moderator,
  35. subjects: [subject1, subject2],
  36. action: "create"
  37. })
  38. log = Repo.one(ModerationLog)
  39. assert log.data["message"] ==
  40. "@#{moderator.nickname} created users: @#{subject1.nickname}, @#{subject2.nickname}"
  41. end
  42. test "logging user follow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
  43. {:ok, _} =
  44. ModerationLog.insert_log(%{
  45. actor: admin,
  46. followed: subject1,
  47. follower: subject2,
  48. action: "follow"
  49. })
  50. log = Repo.one(ModerationLog)
  51. assert log.data["message"] ==
  52. "@#{admin.nickname} made @#{subject2.nickname} follow @#{subject1.nickname}"
  53. end
  54. test "logging user unfollow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
  55. {:ok, _} =
  56. ModerationLog.insert_log(%{
  57. actor: admin,
  58. followed: subject1,
  59. follower: subject2,
  60. action: "unfollow"
  61. })
  62. log = Repo.one(ModerationLog)
  63. assert log.data["message"] ==
  64. "@#{admin.nickname} made @#{subject2.nickname} unfollow @#{subject1.nickname}"
  65. end
  66. test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
  67. {:ok, _} =
  68. ModerationLog.insert_log(%{
  69. actor: admin,
  70. nicknames: [subject1.nickname, subject2.nickname],
  71. tags: ["foo", "bar"],
  72. action: "tag"
  73. })
  74. log = Repo.one(ModerationLog)
  75. users =
  76. [subject1.nickname, subject2.nickname]
  77. |> Enum.map(&"@#{&1}")
  78. |> Enum.join(", ")
  79. tags = ["foo", "bar"] |> Enum.join(", ")
  80. assert log.data["message"] == "@#{admin.nickname} added tags: #{tags} to users: #{users}"
  81. end
  82. test "logging user untagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
  83. {:ok, _} =
  84. ModerationLog.insert_log(%{
  85. actor: admin,
  86. nicknames: [subject1.nickname, subject2.nickname],
  87. tags: ["foo", "bar"],
  88. action: "untag"
  89. })
  90. log = Repo.one(ModerationLog)
  91. users =
  92. [subject1.nickname, subject2.nickname]
  93. |> Enum.map(&"@#{&1}")
  94. |> Enum.join(", ")
  95. tags = ["foo", "bar"] |> Enum.join(", ")
  96. assert log.data["message"] ==
  97. "@#{admin.nickname} removed tags: #{tags} from users: #{users}"
  98. end
  99. test "logging user grant by moderator", %{moderator: moderator, subject1: subject1} do
  100. {:ok, _} =
  101. ModerationLog.insert_log(%{
  102. actor: moderator,
  103. subject: [subject1],
  104. action: "grant",
  105. permission: "moderator"
  106. })
  107. log = Repo.one(ModerationLog)
  108. assert log.data["message"] == "@#{moderator.nickname} made @#{subject1.nickname} moderator"
  109. end
  110. test "logging user revoke by moderator", %{moderator: moderator, subject1: subject1} do
  111. {:ok, _} =
  112. ModerationLog.insert_log(%{
  113. actor: moderator,
  114. subject: [subject1],
  115. action: "revoke",
  116. permission: "moderator"
  117. })
  118. log = Repo.one(ModerationLog)
  119. assert log.data["message"] ==
  120. "@#{moderator.nickname} revoked moderator role from @#{subject1.nickname}"
  121. end
  122. test "logging relay follow", %{moderator: moderator} do
  123. {:ok, _} =
  124. ModerationLog.insert_log(%{
  125. actor: moderator,
  126. action: "relay_follow",
  127. target: "https://example.org/relay"
  128. })
  129. log = Repo.one(ModerationLog)
  130. assert log.data["message"] ==
  131. "@#{moderator.nickname} followed relay: https://example.org/relay"
  132. end
  133. test "logging relay unfollow", %{moderator: moderator} do
  134. {:ok, _} =
  135. ModerationLog.insert_log(%{
  136. actor: moderator,
  137. action: "relay_unfollow",
  138. target: "https://example.org/relay"
  139. })
  140. log = Repo.one(ModerationLog)
  141. assert log.data["message"] ==
  142. "@#{moderator.nickname} unfollowed relay: https://example.org/relay"
  143. end
  144. test "logging report update", %{moderator: moderator} do
  145. report = %Activity{
  146. id: "9m9I1F4p8ftrTP6QTI",
  147. data: %{
  148. "type" => "Flag",
  149. "state" => "resolved"
  150. }
  151. }
  152. {:ok, _} =
  153. ModerationLog.insert_log(%{
  154. actor: moderator,
  155. action: "report_update",
  156. subject: report
  157. })
  158. log = Repo.one(ModerationLog)
  159. assert log.data["message"] ==
  160. "@#{moderator.nickname} updated report ##{report.id} with 'resolved' state"
  161. end
  162. test "logging report response", %{moderator: moderator} do
  163. report = %Activity{
  164. id: "9m9I1F4p8ftrTP6QTI",
  165. data: %{
  166. "type" => "Note"
  167. }
  168. }
  169. {:ok, _} =
  170. ModerationLog.insert_log(%{
  171. actor: moderator,
  172. action: "report_note",
  173. subject: report,
  174. text: "look at this"
  175. })
  176. log = Repo.one(ModerationLog)
  177. assert log.data["message"] ==
  178. "@#{moderator.nickname} added note 'look at this' to report ##{report.id}"
  179. end
  180. test "logging status sensitivity update", %{moderator: moderator} do
  181. note = insert(:note_activity)
  182. {:ok, _} =
  183. ModerationLog.insert_log(%{
  184. actor: moderator,
  185. action: "status_update",
  186. subject: note,
  187. sensitive: "true",
  188. visibility: nil
  189. })
  190. log = Repo.one(ModerationLog)
  191. assert log.data["message"] ==
  192. "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
  193. end
  194. test "logging status visibility update", %{moderator: moderator} do
  195. note = insert(:note_activity)
  196. {:ok, _} =
  197. ModerationLog.insert_log(%{
  198. actor: moderator,
  199. action: "status_update",
  200. subject: note,
  201. sensitive: nil,
  202. visibility: "private"
  203. })
  204. log = Repo.one(ModerationLog)
  205. assert log.data["message"] ==
  206. "@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
  207. end
  208. test "logging status sensitivity & visibility update", %{moderator: moderator} do
  209. note = insert(:note_activity)
  210. {:ok, _} =
  211. ModerationLog.insert_log(%{
  212. actor: moderator,
  213. action: "status_update",
  214. subject: note,
  215. sensitive: "true",
  216. visibility: "private"
  217. })
  218. log = Repo.one(ModerationLog)
  219. assert log.data["message"] ==
  220. "@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
  221. end
  222. test "logging status deletion", %{moderator: moderator} do
  223. note = insert(:note_activity)
  224. {:ok, _} =
  225. ModerationLog.insert_log(%{
  226. actor: moderator,
  227. action: "status_delete",
  228. subject_id: note.id
  229. })
  230. log = Repo.one(ModerationLog)
  231. assert log.data["message"] == "@#{moderator.nickname} deleted status ##{note.id}"
  232. end
  233. end
  234. end