mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:49:14 +08:00
Add filtering support to flags
This commit is contained in:
parent
be0eb0a554
commit
5e69217793
|
@ -17,6 +17,7 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
<div class="topic-excerpt">
|
||||
{{#unless hideTitle}}
|
||||
<h3>
|
||||
{{#if flaggedPost.topic.isPrivateMessage}}
|
||||
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
|
||||
|
@ -24,6 +25,7 @@
|
|||
{{topic-status topic=flaggedPost.topic}}
|
||||
<a href='{{unbound flaggedPost.url}}'>{{{unbound flaggedPost.topic.fancyTitle}}}</a>
|
||||
</h3>
|
||||
{{/unless}}
|
||||
{{#unless site.mobileView}}
|
||||
{{#if flaggedPost.postAuthorFlagged}}
|
||||
<p>{{{flaggedPost.excerpt}}}</p>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
canAct=canAct
|
||||
showResolvedBy=showResolvedBy
|
||||
removePost=(action "removePost" flaggedPost)
|
||||
}}
|
||||
hideTitle=topic}}
|
||||
{{/each}}
|
||||
|
||||
</tbody>
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
<div class='flagged-topic-details'>
|
||||
<div class='topic-title'>
|
||||
<h1>
|
||||
{{topic-status topic=topic}}
|
||||
<h1>{{{topic.fancyTitle}}}</h1>
|
||||
{{#link-to 'topic' topic target="_blank"}}
|
||||
{{{topic.fancyTitle}}}
|
||||
{{/link-to}}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{{plugin-outlet name="flagged-topic-details-header" args=(hash topic=topic)}}
|
||||
</div>
|
||||
<div class='topic-flags'>
|
||||
{{flagged-posts flaggedPosts=flaggedPosts filter="active"}}
|
||||
{{flagged-posts flaggedPosts=flaggedPosts query="active" topic=topic}}
|
||||
</div>
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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: [] }
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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("<img src=")
|
||||
|
||||
posts, users = FlagQuery.flagged_posts_report(admin, "", 1)
|
||||
posts, users = FlagQuery.flagged_posts_report(admin, offset: 1)
|
||||
expect(posts.count).to eq(1)
|
||||
|
||||
# Try by topic
|
||||
posts = FlagQuery.flagged_posts_report(admin, topic_id: post.topic_id)
|
||||
expect(posts).to be_present
|
||||
posts = FlagQuery.flagged_posts_report(admin, topic_id: -1)
|
||||
expect(posts).to be_blank
|
||||
|
||||
# chuck post in category a mod can not see and make sure its missing
|
||||
category = Fabricate(:category)
|
||||
category.set_permissions(admins: :full)
|
||||
|
@ -60,9 +66,11 @@ describe FlagQuery do
|
|||
post2.topic.category_id = category.id
|
||||
post2.topic.save
|
||||
|
||||
posts, users = FlagQuery.flagged_posts_report(moderator, "")
|
||||
posts, users = FlagQuery.flagged_posts_report(moderator)
|
||||
|
||||
expect(posts.count).to eq(1)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user