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:
@@ -4,19 +4,22 @@ class ModerationReportsController < ApplicationController
|
|||||||
before_action :moderator_only, only: [:index]
|
before_action :moderator_only, only: [:index]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
check_privilege
|
|
||||||
@moderation_report = ModerationReport.new(moderation_report_params)
|
@moderation_report = ModerationReport.new(moderation_report_params)
|
||||||
|
check_privilege(@moderation_report)
|
||||||
respond_with(@moderation_report)
|
respond_with(@moderation_report)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@moderation_reports = ModerationReport.paginated_search(params).includes(:creator, :model)
|
@moderation_reports = ModerationReport.paginated_search(params, count_pages: true).includes(:creator, :model)
|
||||||
respond_with(@moderation_reports)
|
respond_with(@moderation_reports)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
check_privilege
|
@moderation_report = ModerationReport.new(moderation_report_params.merge(creator: CurrentUser.user))
|
||||||
@moderation_report = ModerationReport.create(moderation_report_params.merge(creator: CurrentUser.user))
|
check_privilege(@moderation_report)
|
||||||
|
@moderation_report.save
|
||||||
|
|
||||||
|
flash.now[:notice] = @moderation_report.valid? ? "Report submitted" : @moderation_report.errors.full_messages.join("; ")
|
||||||
respond_with(@moderation_report)
|
respond_with(@moderation_report)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,16 +33,8 @@ class ModerationReportsController < ApplicationController
|
|||||||
params.fetch(:moderation_report, {}).fetch(:model_id)
|
params.fetch(:moderation_report, {}).fetch(:model_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_privilege
|
def check_privilege(moderation_report)
|
||||||
case model_type
|
raise User::PrivilegeError unless moderation_report.model.reportable_by?(CurrentUser.user)
|
||||||
when "User"
|
|
||||||
return if User.find(model_id).reportable_by?(CurrentUser.user)
|
|
||||||
when "Comment"
|
|
||||||
return if Comment.find(model_id).reportable_by?(CurrentUser.user)
|
|
||||||
when "ForumPost"
|
|
||||||
return if ForumPost.find(model_id).reportable_by?(CurrentUser.user)
|
|
||||||
end
|
|
||||||
raise User::PrivilegeError
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def moderation_report_params
|
def moderation_report_params
|
||||||
|
|||||||
@@ -421,6 +421,12 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
concerning :DtextMethods do
|
||||||
|
def dtext_shortlink
|
||||||
|
"#{self.class.name.underscore.tr("_", " ")} ##{id}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
concerning :AttributeMethods do
|
concerning :AttributeMethods do
|
||||||
class_methods do
|
class_methods do
|
||||||
# Defines `<attribute>_string`, `<attribute>_string=`, and `<attribute>=`
|
# Defines `<attribute>_string`, `<attribute>_string=`, and `<attribute>=`
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ class Comment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reportable_by?(user)
|
def reportable_by?(user)
|
||||||
ModerationReport.enabled? && user.is_builder? && creator_id != user.id && !creator.is_moderator?
|
creator_id != user.id && !creator.is_moderator?
|
||||||
end
|
end
|
||||||
|
|
||||||
def voted_by?(user)
|
def voted_by?(user)
|
||||||
|
|||||||
@@ -198,4 +198,8 @@ class Dmail < ApplicationRecord
|
|||||||
def visible_to?(user, key)
|
def visible_to?(user, key)
|
||||||
owner_id == user.id || (user.is_moderator? && key == self.key)
|
owner_id == user.id || (user.is_moderator? && key == self.key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reportable_by?(user)
|
||||||
|
is_recipient? && !is_automated? && !from.is_moderator?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reportable_by?(user)
|
def reportable_by?(user)
|
||||||
ModerationReport.enabled? && user.is_builder? && creator_id != user.id && !creator.is_moderator?
|
creator_id != user.id && !creator.is_moderator?
|
||||||
end
|
end
|
||||||
|
|
||||||
def votable?
|
def votable?
|
||||||
@@ -223,4 +223,8 @@ class ForumPost < ApplicationRecord
|
|||||||
x.body = x.quoted_response
|
x.body = x.quoted_response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dtext_shortlink
|
||||||
|
"forum ##{id}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -177,8 +177,4 @@ class ForumTopic < ApplicationRecord
|
|||||||
def update_orignal_post
|
def update_orignal_post
|
||||||
original_post&.update_columns(:updater_id => updater.id, :updated_at => Time.now)
|
original_post&.update_columns(:updater_id => updater.id, :updated_at => Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
def viewable_moderation_reports
|
|
||||||
CurrentUser.is_moderator? ? moderation_reports.recent : []
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,9 +3,13 @@ class ModerationReport < ApplicationRecord
|
|||||||
belongs_to :creator, class_name: "User"
|
belongs_to :creator, class_name: "User"
|
||||||
|
|
||||||
validates :reason, presence: true
|
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!
|
after_create :create_forum_post!
|
||||||
|
|
||||||
scope :user, -> { where(model_type: "User") }
|
scope :user, -> { where(model_type: "User") }
|
||||||
|
scope :dmail, -> { where(model_type: "Dmail") }
|
||||||
scope :comment, -> { where(model_type: "Comment") }
|
scope :comment, -> { where(model_type: "Comment") }
|
||||||
scope :forum_post, -> { where(model_type: "ForumPost") }
|
scope :forum_post, -> { where(model_type: "ForumPost") }
|
||||||
scope :recent, -> { where("moderation_reports.created_at >= ?", 1.week.ago) }
|
scope :recent, -> { where("moderation_reports.created_at >= ?", 1.week.ago) }
|
||||||
@@ -35,14 +39,7 @@ class ModerationReport < ApplicationRecord
|
|||||||
|
|
||||||
def forum_post_message
|
def forum_post_message
|
||||||
messages = ["[b]Submitted by:[/b] @#{creator.name}"]
|
messages = ["[b]Submitted by:[/b] @#{creator.name}"]
|
||||||
case model_type
|
messages << "[b]Submitted against:[/b] #{model.dtext_shortlink}"
|
||||||
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 << ""
|
messages << ""
|
||||||
messages << "[quote]"
|
messages << "[quote]"
|
||||||
messages << "[b]Reason:[/b]"
|
messages << "[b]Reason:[/b]"
|
||||||
@@ -57,6 +54,10 @@ class ModerationReport < ApplicationRecord
|
|||||||
updater.update(forum_post_message)
|
updater.update(forum_post_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.visible(user = CurrentUser.user)
|
||||||
|
user.is_moderator? ? all : none
|
||||||
|
end
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
q = super
|
q = super
|
||||||
q = q.search_attributes(params, :model_type, :model_id, :creator_id)
|
q = q.search_attributes(params, :model_type, :model_id, :creator_id)
|
||||||
|
|||||||
@@ -1782,8 +1782,4 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
def viewable_moderation_reports
|
|
||||||
CurrentUser.is_moderator? ? moderation_reports.recent : []
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -827,7 +827,7 @@ class User < ApplicationRecord
|
|||||||
@presenter ||= UserPresenter.new(self)
|
@presenter ||= UserPresenter.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def viewable_moderation_reports
|
def dtext_shortlink
|
||||||
CurrentUser.is_moderator? ? moderation_reports.recent : []
|
"<@#{name}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
$("#threshold-comments-notice-for-<%= @post.id %>").hide();
|
$("#threshold-comments-notice-for-<%= @post.id %>").hide();
|
||||||
|
|
||||||
var current_comment_section = $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments");
|
var current_comment_section = $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments");
|
||||||
current_comment_section.html("<%= j(render(partial: 'comments/partials/show/comment', collection: @comments, locals: { context: :index_for_post, dtext_data: DText.preprocess(@comments.map(&:body)), moderation_reports: @post.viewable_moderation_reports })) %>");
|
current_comment_section.html("<%= j(render(partial: 'comments/partials/show/comment', collection: @comments, locals: { context: :index_for_post, dtext_data: DText.preprocess(@comments.map(&:body)), moderation_reports: @post.moderation_reports.visible.recent })) %>");
|
||||||
$(window).trigger("danbooru:index_for_post", [<%= @post.id %>]);
|
$(window).trigger("danbooru:index_for_post", [<%= @post.id %>]);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
<%= render "comments/partials/index/header", :post => post %>
|
<%= render "comments/partials/index/header", :post => post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if post.viewable_moderation_reports.present? %>
|
<% if post.moderation_reports.visible.recent.present? %>
|
||||||
<div class="row moderation-comments-notice">
|
<div class="row moderation-comments-notice">
|
||||||
<span class="info" id="moderation-comments-notice-for-<%= post.id %>">
|
<span class="info" id="moderation-comments-notice-for-<%= post.id %>">
|
||||||
This post has comments reported for moderation! (<%= pluralize(post.viewable_moderation_reports.length, "report") %>)
|
This post has comments reported for moderation! (<%= pluralize(post.moderation_reports.visible.recent.length, "report") %>)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
<div class="list-of-comments list-of-messages">
|
<div class="list-of-comments list-of-messages">
|
||||||
<% if comments.present? %>
|
<% if comments.present? %>
|
||||||
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { context: :index_by_post, dtext_data: DText.preprocess(comments.map(&:body)), moderation_reports: post.viewable_moderation_reports } %>
|
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { context: :index_by_post, dtext_data: DText.preprocess(comments.map(&:body)), moderation_reports: post.moderation_reports.visible.recent } %>
|
||||||
<% elsif post.last_commented_at.present? %>
|
<% elsif post.last_commented_at.present? %>
|
||||||
<p>There are no visible comments.</p>
|
<p>There are no visible comments.</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
<%= link_to "Unvote", comment_comment_votes_path(comment_id: comment.id), method: :delete, remote: true %>
|
<%= link_to "Unvote", comment_comment_votes_path(comment_id: comment.id), method: :delete, remote: true %>
|
||||||
</li>
|
</li>
|
||||||
<% if comment.reportable_by?(CurrentUser.user) %>
|
<% if comment.reportable_by?(CurrentUser.user) %>
|
||||||
<li><%= link_to "Report comment", new_moderation_report_path(moderation_report: { model_type: "Comment", model_id: comment.id }), remote: true %></li>
|
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "Comment", model_id: comment.id }), remote: true %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</menu>
|
</menu>
|
||||||
<% if comment.editable_by?(CurrentUser.user) %>
|
<% if comment.editable_by?(CurrentUser.user) %>
|
||||||
|
|||||||
@@ -33,10 +33,13 @@
|
|||||||
<% if @dmail.is_spam? %>
|
<% if @dmail.is_spam? %>
|
||||||
| <%= link_to "Not spam", ham_dmail_path(@dmail), remote: :true, method: :post %>
|
| <%= link_to "Not spam", ham_dmail_path(@dmail), remote: :true, method: :post %>
|
||||||
<% else %>
|
<% else %>
|
||||||
| <%= link_to "Mark as spam", spam_dmail_path(@dmail), remote: :true, method: :post %>
|
| <%= link_to "Spam", spam_dmail_path(@dmail), remote: :true, method: :post %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% if @dmail.reportable_by?(CurrentUser.user) %>
|
||||||
|
| <%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "Dmail", model_id: @dmail.id }), remote: true, title: "Report this dmail to the moderators" %>
|
||||||
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if forum_post.reportable_by?(CurrentUser.user) %>
|
<% if forum_post.reportable_by?(CurrentUser.user) %>
|
||||||
<li><%= link_to "Report forum", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true %></li>
|
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true, title: "Report this forum post to the moderators" %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if forum_post.votable? %>
|
<% if forum_post.votable? %>
|
||||||
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
|
<ul class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render "forum_posts/listing", forum_posts: @forum_posts, original_forum_post_id: @forum_topic.original_post&.id, dtext_data: DText.preprocess(@forum_posts.map(&:body)), moderation_reports: @forum_topic.viewable_moderation_reports %>
|
<%= render "forum_posts/listing", forum_posts: @forum_posts, original_forum_post_id: @forum_topic.original_post&.id, dtext_data: DText.preprocess(@forum_posts.map(&:body)), moderation_reports: @forum_topic.moderation_reports.visible.recent %>
|
||||||
|
|
||||||
<% if CurrentUser.is_member? %>
|
<% if CurrentUser.is_member? %>
|
||||||
<% if CurrentUser.is_moderator? || !@forum_topic.is_locked? %>
|
<% if CurrentUser.is_moderator? || !@forum_topic.is_locked? %>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Danbooru.notice("Report submitted.");
|
Danbooru.notice("<%= j flash[:notice] %>");
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
<% t.column "Reported", width: "10%" do |report| %>
|
<% t.column "Reported", width: "10%" do |report| %>
|
||||||
<% if report.model_type == "User" %>
|
<% if report.model_type == "User" %>
|
||||||
<%= link_to_user report.model %>
|
<%= link_to_user report.model %>
|
||||||
<% elsif report.model_type == "Comment" %>
|
<% elsif report.model_type == "Dmail" %>
|
||||||
<%= link_to "comment ##{report.model_id}", comment_path(report.model_id) %>
|
<%= link_to report.model.dtext_shortlink, dmail_path(report.model, key: report.model.key) %>
|
||||||
<% elsif report.model_type == "ForumPost" %>
|
<% else %>
|
||||||
<%= link_to "forum ##{report.model_id}", forum_post_path(report.model_id) %>
|
<%= link_to report.model.dtext_shortlink, report.model %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% t.column "Reason" do |report| %>
|
<% t.column "Reason" do |report| %>
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
<div id="a-show">
|
<div id="a-show">
|
||||||
<h1><%= link_to_user @user %></h1>
|
<h1><%= link_to_user @user %></h1>
|
||||||
|
|
||||||
<% if @user.viewable_moderation_reports.present? %>
|
<% if @user.moderation_reports.visible.recent.present? %>
|
||||||
<div class="moderation-users-notice">
|
<div class="moderation-users-notice">
|
||||||
<span class="info" id="moderation-users-notice-for-<%= @user.id %>">
|
<span class="info" id="moderation-users-notice-for-<%= @user.id %>">
|
||||||
This user has been reported for moderation! (<%= pluralize(@user.viewable_moderation_reports.length, "report") %>)
|
This user has been reported for moderation! (<%= pluralize(@user.moderation_reports.visible.recent.length, "report") %>)
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ en:
|
|||||||
url: ""
|
url: ""
|
||||||
forum_post_vote:
|
forum_post_vote:
|
||||||
creator_id: "Your vote"
|
creator_id: "Your vote"
|
||||||
|
moderation_report:
|
||||||
|
creator: "You"
|
||||||
post:
|
post:
|
||||||
approver: "You"
|
approver: "You"
|
||||||
approver_id: "You"
|
approver_id: "You"
|
||||||
|
|||||||
Reference in New Issue
Block a user