mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:41:45 +08:00
Add filtering support to flags
This commit is contained in:
parent
be0eb0a554
commit
5e69217793
|
@ -17,13 +17,15 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div class="topic-excerpt">
|
<div class="topic-excerpt">
|
||||||
<h3>
|
{{#unless hideTitle}}
|
||||||
{{#if flaggedPost.topic.isPrivateMessage}}
|
<h3>
|
||||||
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
|
{{#if flaggedPost.topic.isPrivateMessage}}
|
||||||
{{/if}}
|
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
|
||||||
{{topic-status topic=flaggedPost.topic}}
|
{{/if}}
|
||||||
<a href='{{unbound flaggedPost.url}}'>{{{unbound flaggedPost.topic.fancyTitle}}}</a>
|
{{topic-status topic=flaggedPost.topic}}
|
||||||
</h3>
|
<a href='{{unbound flaggedPost.url}}'>{{{unbound flaggedPost.topic.fancyTitle}}}</a>
|
||||||
|
</h3>
|
||||||
|
{{/unless}}
|
||||||
{{#unless site.mobileView}}
|
{{#unless site.mobileView}}
|
||||||
{{#if flaggedPost.postAuthorFlagged}}
|
{{#if flaggedPost.postAuthorFlagged}}
|
||||||
<p>{{{flaggedPost.excerpt}}}</p>
|
<p>{{{flaggedPost.excerpt}}}</p>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
canAct=canAct
|
canAct=canAct
|
||||||
showResolvedBy=showResolvedBy
|
showResolvedBy=showResolvedBy
|
||||||
removePost=(action "removePost" flaggedPost)
|
removePost=(action "removePost" flaggedPost)
|
||||||
}}
|
hideTitle=topic}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
<div class='flagged-topic-details'>
|
<div class='flagged-topic-details'>
|
||||||
<div class='topic-title'>
|
<div class='topic-title'>
|
||||||
{{topic-status topic=topic}}
|
<h1>
|
||||||
<h1>{{{topic.fancyTitle}}}</h1>
|
{{topic-status topic=topic}}
|
||||||
|
{{#link-to 'topic' topic target="_blank"}}
|
||||||
|
{{{topic.fancyTitle}}}
|
||||||
|
{{/link-to}}
|
||||||
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{plugin-outlet name="flagged-topic-details-header" args=(hash topic=topic)}}
|
{{plugin-outlet name="flagged-topic-details-header" args=(hash topic=topic)}}
|
||||||
</div>
|
</div>
|
||||||
<div class='topic-flags'>
|
<div class='topic-flags'>
|
||||||
{{flagged-posts flaggedPosts=flaggedPosts filter="active"}}
|
{{flagged-posts flaggedPosts=flaggedPosts query="active" topic=topic}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import FlaggedPost from 'admin/models/flagged-post';
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
canAct: Ember.computed.equal('filter', 'active'),
|
canAct: Ember.computed.equal('filter', 'active'),
|
||||||
showResolvedBy: Ember.computed.equal('filter', 'old'),
|
showResolvedBy: Ember.computed.equal('filter', 'old'),
|
||||||
|
allLoaded: false,
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
removePost(flaggedPost) {
|
removePost(flaggedPost) {
|
||||||
|
@ -10,17 +11,28 @@ export default Ember.Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
loadMore() {
|
loadMore() {
|
||||||
|
if (this.get('allLoaded')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const flaggedPosts = this.get('flaggedPosts');
|
const flaggedPosts = this.get('flaggedPosts');
|
||||||
return FlaggedPost.findAll({
|
|
||||||
|
let args = {
|
||||||
filter: this.get('query'),
|
filter: this.get('query'),
|
||||||
offset: flaggedPosts.length+1
|
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);
|
flaggedPosts.addObjects(data);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,10 +2,21 @@ require 'flag_query'
|
||||||
|
|
||||||
class Admin::FlagsController < Admin::AdminController
|
class Admin::FlagsController < Admin::AdminController
|
||||||
|
|
||||||
|
def self.flags_per_page
|
||||||
|
10
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
# we may get out of sync, fix it here
|
# we may get out of sync, fix it here
|
||||||
PostAction.update_flagged_posts_count
|
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?
|
if posts.blank?
|
||||||
render json: { posts: [], topics: [], users: [] }
|
render json: { posts: [], topics: [], users: [] }
|
||||||
|
|
|
@ -2,15 +2,23 @@ require 'ostruct'
|
||||||
|
|
||||||
module FlagQuery
|
module FlagQuery
|
||||||
|
|
||||||
def self.flagged_posts_report(current_user, filter, offset = 0, per_page = 25)
|
def self.flagged_posts_report(current_user, opts = nil)
|
||||||
actions = flagged_post_actions(filter)
|
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)
|
guardian = Guardian.new(current_user)
|
||||||
|
|
||||||
if !guardian.is_admin?
|
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,
|
allowed_category_ids: guardian.allowed_category_ids,
|
||||||
private_message: Archetype.private_message)
|
private_message: Archetype.private_message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
post_ids = actions.limit(per_page)
|
post_ids = actions.limit(per_page)
|
||||||
|
@ -111,14 +119,18 @@ module FlagQuery
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.flagged_post_actions(filter)
|
def self.flagged_post_actions(opts)
|
||||||
post_actions = PostAction.flags
|
post_actions = PostAction.flags
|
||||||
.joins("INNER JOIN posts ON posts.id = post_actions.post_id")
|
.joins("INNER JOIN posts ON posts.id = post_actions.post_id")
|
||||||
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
|
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
|
||||||
.joins("LEFT JOIN users ON users.id = posts.user_id")
|
.joins("LEFT JOIN users ON users.id = posts.user_id")
|
||||||
.where("posts.user_id > 0")
|
.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.where("post_actions.disagreed_at IS NOT NULL OR
|
||||||
post_actions.deferred_at IS NOT NULL OR
|
post_actions.deferred_at IS NOT NULL OR
|
||||||
post_actions.agreed_at IS NOT NULL")
|
post_actions.agreed_at IS NOT NULL")
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe FlagQuery do
|
||||||
admin = Fabricate(:admin)
|
admin = Fabricate(:admin)
|
||||||
post = create_post(user: Discourse.system_user)
|
post = create_post(user: Discourse.system_user)
|
||||||
PostAction.act(codinghorror, post, PostActionType.types[:spam])
|
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(posts).to be_blank
|
||||||
expect(topics).to be_blank
|
expect(topics).to be_blank
|
||||||
|
@ -34,7 +34,7 @@ describe FlagQuery do
|
||||||
PostAction.act(codinghorror, post2, PostActionType.types[:spam])
|
PostAction.act(codinghorror, post2, PostActionType.types[:spam])
|
||||||
PostAction.act(user2, 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)
|
expect(posts.count).to eq(2)
|
||||||
first = posts.first
|
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[:permalink]).to eq(mod_message.related_post.topic.relative_url)
|
||||||
expect(second[:post_actions].first[:conversation][:response][:excerpt]).to match("<img src=")
|
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)
|
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
|
# chuck post in category a mod can not see and make sure its missing
|
||||||
category = Fabricate(:category)
|
category = Fabricate(:category)
|
||||||
category.set_permissions(admins: :full)
|
category.set_permissions(admins: :full)
|
||||||
|
@ -60,9 +66,11 @@ describe FlagQuery do
|
||||||
post2.topic.category_id = category.id
|
post2.topic.category_id = category.id
|
||||||
post2.topic.save
|
post2.topic.save
|
||||||
|
|
||||||
posts, users = FlagQuery.flagged_posts_report(moderator, "")
|
posts, users = FlagQuery.flagged_posts_report(moderator)
|
||||||
|
|
||||||
expect(posts.count).to eq(1)
|
expect(posts.count).to eq(1)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user