From c9bcda4e0a4876e007725ab8c5b96dd05eda042f Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 20 Jul 2024 22:20:13 -0400 Subject: [PATCH] Document create_system_report and flip argument order --- lib/philomena/comments.ex | 2 +- lib/philomena/conversations.ex | 2 +- lib/philomena/images.ex | 2 +- lib/philomena/posts.ex | 2 +- lib/philomena/reports.ex | 14 ++++++++++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/philomena/comments.ex b/lib/philomena/comments.ex index 90569d6e..8b98b11e 100644 --- a/lib/philomena/comments.ex +++ b/lib/philomena/comments.ex @@ -210,8 +210,8 @@ defmodule Philomena.Comments do def report_non_approved(comment) do Reports.create_system_report( - comment.id, "Comment", + comment.id, "Approval", "Comment contains externally-embedded images and has been flagged for review." ) diff --git a/lib/philomena/conversations.ex b/lib/philomena/conversations.ex index e9ed7500..46a3ce8f 100644 --- a/lib/philomena/conversations.ex +++ b/lib/philomena/conversations.ex @@ -236,8 +236,8 @@ defmodule Philomena.Conversations do def report_non_approved(id) do Reports.create_system_report( - id, "Conversation", + id, "Approval", "PM contains externally-embedded images and has been flagged for review." ) diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 5fea2e35..90bdd5b4 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -193,8 +193,8 @@ defmodule Philomena.Images do defp maybe_suggest_user_verification(%User{id: id, uploads_count: 5, verified: false}) do Reports.create_system_report( - id, "User", + id, "Verification", "User has uploaded enough approved images to be considered for verification." ) diff --git a/lib/philomena/posts.ex b/lib/philomena/posts.ex index fc339c97..bde21f16 100644 --- a/lib/philomena/posts.ex +++ b/lib/philomena/posts.ex @@ -114,8 +114,8 @@ defmodule Philomena.Posts do def report_non_approved(post) do Reports.create_system_report( - post.id, "Post", + post.id, "Approval", "Post contains externally-embedded images and has been flagged for review." ) diff --git a/lib/philomena/reports.ex b/lib/philomena/reports.ex index 4f10391d..f39838d5 100644 --- a/lib/philomena/reports.ex +++ b/lib/philomena/reports.ex @@ -95,7 +95,17 @@ defmodule Philomena.Reports do update: [set: [open: false, state: "closed", admin_id: ^closing_user.id]] end - def create_system_report(reportable_id, reportable_type, category, reason) do + @doc """ + Automatically create a report with the given category and reason on the given + `reportable_id` and `reportable_type`. + + ## Examples + + iex> create_system_report("Comment", 1, "Other", "Custom report reason") + {:ok, %Report{}} + + """ + def create_system_report(reportable_type, reportable_id, category, reason) do attrs = %{ reason: reason, category: category @@ -109,7 +119,7 @@ defmodule Philomena.Reports do "Mozilla/5.0 (X11; Philomena; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0" } - %Report{reportable_id: reportable_id, reportable_type: reportable_type} + %Report{reportable_type: reportable_type, reportable_id: reportable_id} |> Report.creation_changeset(attrs, attributes) |> Repo.insert() |> reindex_after_update()