mod reports: include reported user and message in forum post.

Also fix it so that reports against dmails include the key in the dmail
link so that mods can view the reported dmail.
This commit is contained in:
evazion
2020-02-03 04:42:09 -06:00
parent bb2022abed
commit 24cb920608
7 changed files with 36 additions and 12 deletions

View File

@@ -424,7 +424,7 @@ class ApplicationRecord < ActiveRecord::Base
end end
concerning :DtextMethods do concerning :DtextMethods do
def dtext_shortlink def dtext_shortlink(**options)
"#{self.class.name.underscore.tr("_", " ")} ##{id}" "#{self.class.name.underscore.tr("_", " ")} ##{id}"
end end
end end

View File

@@ -191,4 +191,8 @@ class Dmail < ApplicationRecord
def reportable_by?(user) def reportable_by?(user)
is_recipient? && !is_automated? && !from.is_moderator? is_recipient? && !is_automated? && !from.is_moderator?
end end
def dtext_shortlink(key: false, **options)
key ? "dmail ##{id}/#{key}" : "dmail ##{id}"
end
end end

View File

@@ -39,15 +39,16 @@ class ModerationReport < ApplicationRecord
end end
def forum_post_message def forum_post_message
messages = ["[b]Submitted by:[/b] @#{creator.name}"] <<~EOS
messages << "[b]Submitted against:[/b] #{model.dtext_shortlink}" [b]Report[/b] modreport ##{id}
messages << "" [b]Submitted by[/b] <@#{creator.name}>
messages << "[quote]" [b]Submitted against[/b] #{model.dtext_shortlink(key: true)} by <@#{reported_user.name}>
messages << "[b]Reason:[/b]" [b]Reason[/b] #{reason}
messages << ""
messages << reason [quote]
messages << "[/quote]" #{model.body}
messages.join("\n") [/quote]
EOS
end end
def create_forum_post! def create_forum_post!

View File

@@ -820,7 +820,7 @@ class User < ApplicationRecord
@presenter ||= UserPresenter.new(self) @presenter ||= UserPresenter.new(self)
end end
def dtext_shortlink def dtext_shortlink(**options)
"<@#{name}>" "<@#{name}>"
end end
end end

View File

@@ -1,6 +1,9 @@
FactoryBot.define do FactoryBot.define do
factory(:dmail) do factory(:dmail) do
to :factory => :user owner factory: :user
from factory: :user
to factory: :user
creator_ip_addr { FFaker::Internet.ip_v4_address }
title {FFaker::Lorem.words.join(" ")} title {FFaker::Lorem.words.join(" ")}
body {FFaker::Lorem.sentences.join(" ")} body {FFaker::Lorem.sentences.join(" ")}
end end

View File

@@ -1,5 +1,6 @@
FactoryBot.define do FactoryBot.define do
factory(:moderation_report) do factory(:moderation_report) do
creator
reason {"xxx"} reason {"xxx"}
end end
end end

View File

@@ -0,0 +1,15 @@
require 'test_helper'
class ModerationReportTest < ActiveSupport::TestCase
context "Moderation reports: " do
context "creating a moderation report" do
should "create a forum post" do
@dmail = create(:dmail)
@modreport = create(:moderation_report, model: @dmail, reason: "blah")
assert_equal(2, ForumPost.count)
assert_match(/blah/, ForumPost.last.body)
end
end
end
end