diff --git a/app/assets/javascripts/admin/templates/components/flagged-post.hbs b/app/assets/javascripts/admin/templates/components/flagged-post.hbs
index 1a2ce66c413..dd420a24f92 100644
--- a/app/assets/javascripts/admin/templates/components/flagged-post.hbs
+++ b/app/assets/javascripts/admin/templates/components/flagged-post.hbs
@@ -17,13 +17,15 @@
{{/if}}
-
- {{#if flaggedPost.topic.isPrivateMessage}}
- {{d-icon "envelope"}}
- {{/if}}
- {{topic-status topic=flaggedPost.topic}}
- {{{unbound flaggedPost.topic.fancyTitle}}}
-
+ {{#unless hideTitle}}
+
+ {{#if flaggedPost.topic.isPrivateMessage}}
+ {{d-icon "envelope"}}
+ {{/if}}
+ {{topic-status topic=flaggedPost.topic}}
+ {{{unbound flaggedPost.topic.fancyTitle}}}
+
+ {{/unless}}
{{#unless site.mobileView}}
{{#if flaggedPost.postAuthorFlagged}}
{{{flaggedPost.excerpt}}}
diff --git a/app/assets/javascripts/admin/templates/components/flagged-posts.hbs b/app/assets/javascripts/admin/templates/components/flagged-posts.hbs
index 8a58ce4537e..583b35c11a7 100644
--- a/app/assets/javascripts/admin/templates/components/flagged-posts.hbs
+++ b/app/assets/javascripts/admin/templates/components/flagged-posts.hbs
@@ -15,7 +15,7 @@
canAct=canAct
showResolvedBy=showResolvedBy
removePost=(action "removePost" flaggedPost)
- }}
+ hideTitle=topic}}
{{/each}}
diff --git a/app/assets/javascripts/admin/templates/flags-topics-show.hbs b/app/assets/javascripts/admin/templates/flags-topics-show.hbs
index 95bba4113a2..fae256e8ab2 100644
--- a/app/assets/javascripts/admin/templates/flags-topics-show.hbs
+++ b/app/assets/javascripts/admin/templates/flags-topics-show.hbs
@@ -1,11 +1,15 @@
- {{topic-status topic=topic}}
-
{{{topic.fancyTitle}}}
+
+ {{topic-status topic=topic}}
+ {{#link-to 'topic' topic target="_blank"}}
+ {{{topic.fancyTitle}}}
+ {{/link-to}}
+
{{plugin-outlet name="flagged-topic-details-header" args=(hash topic=topic)}}
- {{flagged-posts flaggedPosts=flaggedPosts filter="active"}}
+ {{flagged-posts flaggedPosts=flaggedPosts query="active" topic=topic}}
diff --git a/app/assets/javascripts/discourse/components/flagged-posts.js.es6 b/app/assets/javascripts/discourse/components/flagged-posts.js.es6
index c381c197601..4d520910bf4 100644
--- a/app/assets/javascripts/discourse/components/flagged-posts.js.es6
+++ b/app/assets/javascripts/discourse/components/flagged-posts.js.es6
@@ -3,6 +3,7 @@ import FlaggedPost from 'admin/models/flagged-post';
export default Ember.Component.extend({
canAct: Ember.computed.equal('filter', 'active'),
showResolvedBy: Ember.computed.equal('filter', 'old'),
+ allLoaded: false,
actions: {
removePost(flaggedPost) {
@@ -10,17 +11,28 @@ export default Ember.Component.extend({
},
loadMore() {
+ if (this.get('allLoaded')) {
+ return;
+ }
+
const flaggedPosts = this.get('flaggedPosts');
- return FlaggedPost.findAll({
+
+ let args = {
filter: this.get('query'),
offset: flaggedPosts.length+1
- }).then(data => {
- if (data.length===0) {
- flaggedPosts.set("allLoaded",true);
+ };
+
+ let topic = this.get('topic');
+ if (topic) {
+ args.topic_id = topic.id;
+ }
+
+ return FlaggedPost.findAll(args).then(data => {
+ if (data.length === 0) {
+ this.set('allLoaded', true);
}
flaggedPosts.addObjects(data);
});
- },
-
+ }
}
});
diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb
index da4e0425337..9c0fcc3f01e 100644
--- a/app/controllers/admin/flags_controller.rb
+++ b/app/controllers/admin/flags_controller.rb
@@ -2,10 +2,21 @@ require 'flag_query'
class Admin::FlagsController < Admin::AdminController
+ def self.flags_per_page
+ 10
+ end
+
def index
# we may get out of sync, fix it here
PostAction.update_flagged_posts_count
- posts, topics, users = FlagQuery.flagged_posts_report(current_user, params[:filter], params[:offset].to_i, 10)
+
+ posts, topics, users = FlagQuery.flagged_posts_report(
+ current_user,
+ filter: params[:filter],
+ offset: params[:offset].to_i,
+ topic_id: params[:topic_id],
+ per_page: Admin::FlagsController.flags_per_page
+ )
if posts.blank?
render json: { posts: [], topics: [], users: [] }
diff --git a/lib/flag_query.rb b/lib/flag_query.rb
index 50ea28dbe9f..be64f9966aa 100644
--- a/lib/flag_query.rb
+++ b/lib/flag_query.rb
@@ -2,15 +2,23 @@ require 'ostruct'
module FlagQuery
- def self.flagged_posts_report(current_user, filter, offset = 0, per_page = 25)
- actions = flagged_post_actions(filter)
+ def self.flagged_posts_report(current_user, opts = nil)
+ opts ||= {}
+ filter = opts[:filter] || 'active'
+ offset = opts[:offset] || 0
+ per_page = opts[:per_page] || 25
+ topic_id = opts[:topic_id]
+
+ actions = flagged_post_actions(opts)
guardian = Guardian.new(current_user)
if !guardian.is_admin?
- actions = actions.where('category_id IN (:allowed_category_ids) OR archetype = :private_message',
+ actions = actions.where(
+ 'category_id IN (:allowed_category_ids) OR archetype = :private_message',
allowed_category_ids: guardian.allowed_category_ids,
- private_message: Archetype.private_message)
+ private_message: Archetype.private_message
+ )
end
post_ids = actions.limit(per_page)
@@ -111,14 +119,18 @@ module FlagQuery
]
end
- def self.flagged_post_actions(filter)
+ def self.flagged_post_actions(opts)
post_actions = PostAction.flags
.joins("INNER JOIN posts ON posts.id = post_actions.post_id")
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
.joins("LEFT JOIN users ON users.id = posts.user_id")
.where("posts.user_id > 0")
- if filter == "old"
+ if opts[:topic_id]
+ post_actions = post_actions.where("topics.id = ?", opts[:topic_id])
+ end
+
+ if opts[:filter] == "old"
post_actions.where("post_actions.disagreed_at IS NOT NULL OR
post_actions.deferred_at IS NOT NULL OR
post_actions.agreed_at IS NOT NULL")
diff --git a/spec/components/flag_query_spec.rb b/spec/components/flag_query_spec.rb
index 58f44063c94..5a63539ea69 100644
--- a/spec/components/flag_query_spec.rb
+++ b/spec/components/flag_query_spec.rb
@@ -10,7 +10,7 @@ describe FlagQuery do
admin = Fabricate(:admin)
post = create_post(user: Discourse.system_user)
PostAction.act(codinghorror, post, PostActionType.types[:spam])
- posts, topics, users = FlagQuery.flagged_posts_report(admin, "")
+ posts, topics, users = FlagQuery.flagged_posts_report(admin)
expect(posts).to be_blank
expect(topics).to be_blank
@@ -34,7 +34,7 @@ describe FlagQuery do
PostAction.act(codinghorror, post2, PostActionType.types[:spam])
PostAction.act(user2, post2, PostActionType.types[:spam])
- posts, topics, users = FlagQuery.flagged_posts_report(admin, "")
+ posts, topics, users = FlagQuery.flagged_posts_report(admin)
expect(posts.count).to eq(2)
first = posts.first
@@ -50,9 +50,15 @@ describe FlagQuery do
expect(second[:post_actions].first[:permalink]).to eq(mod_message.related_post.topic.relative_url)
expect(second[:post_actions].first[:conversation][:response][:excerpt]).to match("