mod reports: enable reporting for members, add dmail reporting.

* Add ability to report dmails.
* Enable reports for comments, forum posts, and dmails.
* Allow Members to send reports.
* Don't allow users to report the same thing twice.
This commit is contained in:
evazion
2020-01-27 12:55:59 -06:00
parent 812918556f
commit af044c45db
19 changed files with 56 additions and 49 deletions

View File

@@ -421,6 +421,12 @@ class ApplicationRecord < ActiveRecord::Base
end
end
concerning :DtextMethods do
def dtext_shortlink
"#{self.class.name.underscore.tr("_", " ")} ##{id}"
end
end
concerning :AttributeMethods do
class_methods do
# Defines `<attribute>_string`, `<attribute>_string=`, and `<attribute>=`

View File

@@ -129,7 +129,7 @@ class Comment < ApplicationRecord
end
def reportable_by?(user)
ModerationReport.enabled? && user.is_builder? && creator_id != user.id && !creator.is_moderator?
creator_id != user.id && !creator.is_moderator?
end
def voted_by?(user)

View File

@@ -198,4 +198,8 @@ class Dmail < ApplicationRecord
def visible_to?(user, key)
owner_id == user.id || (user.is_moderator? && key == self.key)
end
def reportable_by?(user)
is_recipient? && !is_automated? && !from.is_moderator?
end
end

View File

@@ -95,7 +95,7 @@ class ForumPost < ApplicationRecord
end
def reportable_by?(user)
ModerationReport.enabled? && user.is_builder? && creator_id != user.id && !creator.is_moderator?
creator_id != user.id && !creator.is_moderator?
end
def votable?
@@ -223,4 +223,8 @@ class ForumPost < ApplicationRecord
x.body = x.quoted_response
end
end
def dtext_shortlink
"forum ##{id}"
end
end

View File

@@ -177,8 +177,4 @@ class ForumTopic < ApplicationRecord
def update_orignal_post
original_post&.update_columns(:updater_id => updater.id, :updated_at => Time.now)
end
def viewable_moderation_reports
CurrentUser.is_moderator? ? moderation_reports.recent : []
end
end

View File

@@ -3,9 +3,13 @@ class ModerationReport < ApplicationRecord
belongs_to :creator, class_name: "User"
validates :reason, presence: true
validates :model_type, inclusion: { in: %w[Comment Dmail ForumPost User] }
validates :creator, uniqueness: { scope: [:model_type, :model_id], message: "have already reported this message." }
after_create :create_forum_post!
scope :user, -> { where(model_type: "User") }
scope :dmail, -> { where(model_type: "Dmail") }
scope :comment, -> { where(model_type: "Comment") }
scope :forum_post, -> { where(model_type: "ForumPost") }
scope :recent, -> { where("moderation_reports.created_at >= ?", 1.week.ago) }
@@ -35,14 +39,7 @@ class ModerationReport < ApplicationRecord
def forum_post_message
messages = ["[b]Submitted by:[/b] @#{creator.name}"]
case model_type
when "User"
messages << "[b]Submitted against:[/b] @#{model.name}"
when "Comment"
messages << "[b]Submitted against[/b]: comment ##{model_id}"
when "ForumPost"
messages << "[b]Submitted against[/b]: forum ##{model_id}"
end
messages << "[b]Submitted against:[/b] #{model.dtext_shortlink}"
messages << ""
messages << "[quote]"
messages << "[b]Reason:[/b]"
@@ -57,6 +54,10 @@ class ModerationReport < ApplicationRecord
updater.update(forum_post_message)
end
def self.visible(user = CurrentUser.user)
user.is_moderator? ? all : none
end
def self.search(params)
q = super
q = q.search_attributes(params, :model_type, :model_id, :creator_id)

View File

@@ -1782,8 +1782,4 @@ class Post < ApplicationRecord
save
end
def viewable_moderation_reports
CurrentUser.is_moderator? ? moderation_reports.recent : []
end
end

View File

@@ -827,7 +827,7 @@ class User < ApplicationRecord
@presenter ||= UserPresenter.new(self)
end
def viewable_moderation_reports
CurrentUser.is_moderator? ? moderation_reports.recent : []
def dtext_shortlink
"<@#{name}>"
end
end