FEATURE: List moderator warnings on admin dashboard

This commit is contained in:
Robin Ward 2014-09-08 13:23:40 -04:00
parent 0ccb1dcca6
commit 4f6b9815ae
8 changed files with 18 additions and 5 deletions

View File

@ -98,7 +98,7 @@ class Notification < ActiveRecord::Base
def self.recent_report(user, count = nil)
count ||= 10
notifications = user.notifications.recent(count).includes({:topic => :warning}).to_a
notifications = user.notifications.recent(count).includes(:topic).to_a
if notifications.present?
notifications += user.notifications

View File

@ -39,7 +39,7 @@ class ListableTopicSerializer < BasicTopicSerializer
end
def is_warning
object.private_message? && object.warning.present?
object.subtype == TopicSubtype.moderator_warning
end
def include_is_warning?

View File

@ -14,7 +14,7 @@ class NotificationSerializer < ApplicationSerializer
end
def is_warning
object.topic.present? && object.topic.warning.present?
object.topic.present? && object.topic.subtype == TopicSubtype.moderator_warning
end
def include_is_warning?

View File

@ -113,7 +113,7 @@ class TopicViewSerializer < ApplicationSerializer
def is_warning
object.topic.private_message? && object.topic.warning.present?
object.topic.private_message? && object.topic.subtype == TopicSubtype.moderator_warning
end
def include_is_warning?

View File

@ -0,0 +1,8 @@
class MigrateWarningTopicSubtypes < ActiveRecord::Migration
def change
execute "UPDATE topics AS t
SET subtype = 'moderator_warning'
FROM warnings AS w
WHERE w.topic_id = t.id"
end
end

View File

@ -75,6 +75,9 @@ class TopicCreator
topic_params[key] = @opts[key] if @opts[key].present?
end
# Automatically give it a moderator warning subtype if specified
topic_params[:subtype] = TopicSubtype.moderator_warning if @opts[:is_warning]
category = find_category
@guardian.ensure_can_create!(Topic, category)

View File

@ -165,7 +165,7 @@ class TopicQuery
options.reverse_merge!(per_page: SiteSetting.topics_per_page)
# Start with a list of all topics
result = Topic.includes(:allowed_users).includes(:warning)
result = Topic.includes(:allowed_users)
.where("topics.id IN (SELECT topic_id FROM topic_allowed_users WHERE user_id = #{user.id.to_i})")
.joins("LEFT OUTER JOIN topic_users AS tu ON (topics.id = tu.topic_id AND tu.user_id = #{user.id.to_i})")
.order(TopicQuerySQL.order_nocategory_basic_bumped)

View File

@ -354,6 +354,7 @@ describe PostCreator do
post.topic.warning.should be_blank
post.topic.archetype.should == Archetype.private_message
post.topic.subtype.should == TopicSubtype.user_to_user
post.topic.topic_allowed_users.count.should == 3
# PMs can't have a category
@ -404,6 +405,7 @@ describe PostCreator do
topic = post.topic
topic.should be_present
topic.warning.should be_present
topic.subtype.should == TopicSubtype.moderator_warning
topic.warning.user.should == target_user1
topic.warning.created_by.should == user
target_user1.warnings.count.should == 1