FEATURE: New modal to show flags received for a user

This commit is contained in:
Robin Ward 2018-01-17 13:03:14 -05:00
parent ec65ae76b9
commit 34ed6088b9
15 changed files with 121 additions and 42 deletions

View File

@ -0,0 +1,3 @@
export default Ember.Component.extend({
classNames: ['flag-user-lists']
});

View File

@ -0,0 +1,3 @@
export default Ember.Component.extend({
tagName: 'h3'
});

View File

@ -64,6 +64,9 @@ export default Ember.Controller.extend(CanCheckEmails, {
anonymize() { return this.get('model').anonymize(); },
destroy() { return this.get('model').destroy(); },
showFlagsReceived() {
this.get('adminTools').showFlagsReceived(this.get('model'));
},
showSuspendModal() {
this.get('adminTools').showSuspendModal(this.get('model'));
},

View File

@ -0,0 +1,17 @@
export default Ember.Controller.extend({
loadingFlags: null,
user: null,
onShow() {
this.set('loadingFlags', true);
this.store.findAll('flagged-post', {
filter: 'without_custom',
user_id: this.get('model.id')
}).then(result => {
this.set('loadingFlags', false);
console.log(result);
this.set('flaggedPosts', result);
});
}
});

View File

@ -22,6 +22,11 @@ export default Post.extend({
});
},
@computed('post_actions')
hasDisposedBy() {
return this.get('post_actions').some(action => action.disposed_by);
},
@computed('post_actions.@each.name_key')
flaggedForSpam() {
return this.get('post_actions').every(action => action.name_key === 'spam');

View File

@ -17,6 +17,10 @@ export default Ember.Service.extend({
this.siteSettings = getOwner(this).lookup('site-settings:main');
},
showFlagsReceived(user) {
showModal(`admin-flags-received`, { admin: true, model: user });
},
checkSpammer(userId) {
return AdminUser.find(userId).then(au => this.spammerDetails(au));
},

View File

@ -0,0 +1,32 @@
<div class='flagged-by'>
<div class='user-list-title'>
{{i18n "admin.flags.flagged_by"}}
</div>
<div class='flag-users'>
{{#each flaggedPost.post_actions as |postAction|}}
{{#flag-user user=postAction.user date=postAction.created_at}}
<div class='flagger-flag-type'>
{{post-action-title postAction.post_action_type_id postAction.name_key}}
</div>
{{/flag-user}}
{{/each}}
</div>
</div>
{{#if showResolvedBy}}
<div class='flagged-post-resolved-by'>
<div class='user-list-title'>
{{i18n "admin.flags.resolved_by"}}
</div>
<div class='flag-users'>
{{#each flaggedPost.post_actions as |postAction|}}
{{#flag-user user=postAction.disposed_by date=postAction.disposed_at}}
{{disposition-icon postAction.disposition}}
{{#if postAction.staff_took_action}}
{{d-icon "gavel" title="admin.flags.took_action"}}
{{/if}}
{{/flag-user}}
{{/each}}
</div>
</div>
{{/if}}

View File

@ -0,0 +1,5 @@
{{#if flaggedPost.topic.isPrivateMessage}}
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
{{/if}}
{{topic-status topic=flaggedPost.topic}}
<a href='{{unbound flaggedPost.url}}'>{{{unbound flaggedPost.topic.fancyTitle}}}</a>

View File

@ -30,13 +30,7 @@
<div class='flagged-post-excerpt'>
{{#unless hideTitle}}
<h3>
{{#if flaggedPost.topic.isPrivateMessage}}
<span class="private-message-glyph">{{d-icon "envelope"}}</span>
{{/if}}
{{topic-status topic=flaggedPost.topic}}
<a href='{{unbound flaggedPost.url}}'>{{{unbound flaggedPost.topic.fancyTitle}}}</a>
</h3>
{{flagged-post-title flaggedPost=flaggedPost}}
{{/unless}}
{{#if flaggedPost.postAuthorFlagged}}
{{#if expanded}}
@ -72,40 +66,7 @@
</div>
{{/each}}
<div class='flag-user-lists'>
<div class='flagged-by'>
<div class='user-list-title'>
{{i18n "admin.flags.flagged_by"}}
</div>
<div class='flag-users'>
{{#each flaggedPost.post_actions as |postAction|}}
{{#flag-user user=postAction.user date=postAction.created_at}}
<div class='flagger-flag-type'>
{{post-action-title postAction.post_action_type_id postAction.name_key}}
</div>
{{/flag-user}}
{{/each}}
</div>
</div>
{{#if showResolvedBy}}
<div class='flagged-post-resolved-by'>
<div class='user-list-title'>
{{i18n "admin.flags.resolved_by"}}
</div>
<div class='flag-users'>
{{#each flaggedPost.post_actions as |postAction|}}
{{#flag-user user=postAction.disposed_by date=postAction.disposed_at}}
{{disposition-icon postAction.disposition}}
{{#if postAction.staff_took_action}}
{{d-icon "gavel" title="admin.flags.took_action"}}
{{/if}}
{{/flag-user}}
{{/each}}
</div>
</div>
{{/if}}
</div>
{{flag-user-lists flaggedPost=flaggedPost showResolvedBy=showResolvedBy}}
{{#if suspended}}
<div class='suspended-message'>

View File

@ -0,0 +1,14 @@
{{#d-modal-body rawTitle=(i18n "admin.user.flags_received_by" username=model.username)}}
{{#conditional-loading-spinner condition=loadingFlags}}
{{#each flaggedPosts as |flaggedPost|}}
<div class='received-flag flagged-post'>
<div class='flagged-post-excerpt'>
{{flagged-post-title flaggedPost=flaggedPost}}
</div>
{{flag-user-lists flaggedPost=flaggedPost showResolvedBy=flaggedPost.hasDisposedBy}}
</div>
{{else}}
{{i18n "admin.user.flags_received_none"}}
{{/each}}
{{/conditional-loading-spinner}}
{{/d-modal-body}}

View File

@ -6,6 +6,7 @@
{{i18n 'admin.user.show_public_profile'}}
{{/link-to}}
{{/if}}
{{#if model.can_view_action_logs}}
{{d-button action="viewActionLogs" actionParam=model.username icon="list-alt" label="admin.user.action_logs"}}
{{/if}}
@ -466,7 +467,18 @@
</div>
<div class='display-row'>
<div class='field'>{{i18n 'admin.user.flags_given_received_count'}}</div>
<div class='value'>{{model.flags_given_count}} / {{model.flags_received_count}}</div>
<div class='value'>
{{model.flags_given_count}} / {{model.flags_received_count}}
</div>
<div class='controls'>
{{#if model.flags_received_count}}
{{d-button
action=(action "showFlagsReceived")
label="admin.user.show_flags_received"
icon="flag"
}}
{{/if}}
</div>
</div>
<div class='display-row'>
<div class='field'>{{i18n 'admin.user.private_topics_count'}}</div>

View File

@ -16,6 +16,7 @@ class Admin::FlagsController < Admin::AdminController
posts, topics, users, post_actions, total_rows = FlagQuery.flagged_posts_report(
current_user,
filter: params[:filter],
user_id: params[:user_id],
offset: offset,
topic_id: params[:topic_id],
per_page: per_page,

View File

@ -3392,6 +3392,9 @@ en:
grant_moderation: 'Grant Moderation'
unsuspend: 'Unsuspend'
suspend: 'Suspend'
show_flags_received: "Show Flags Received"
flags_received_by: "Flags Received by %{username}"
flags_received_none: "This user has not received any flags."
reputation: Reputation
permissions: Permissions
activity: Activity

View File

@ -145,6 +145,16 @@ module FlagQuery
post_actions = post_actions.where("topics.id = ?", opts[:topic_id])
end
if opts[:user_id]
post_actions = post_actions.where("posts.user_id = ?", opts[:user_id])
end
if opts[:filter] == 'without_custom'
return post_actions.where(
'post_action_type_id' => PostActionType.flag_types_without_custom.values
)
end
if opts[:filter] == "old"
post_actions.where("post_actions.disagreed_at IS NOT NULL OR
post_actions.deferred_at IS NOT NULL OR

View File

@ -59,6 +59,12 @@ describe FlagQuery do
posts = FlagQuery.flagged_posts_report(admin, topic_id: -1)
expect(posts[0]).to be_blank
# Try by user
posts = FlagQuery.flagged_posts_report(admin, user_id: post.user_id)
expect(posts).to be_present
posts = FlagQuery.flagged_posts_report(admin, user_id: -1000)
expect(posts[0]).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)