mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
FEATURE: 'delete user' button in the user card in the admin section
This commit is contained in:
parent
99928cac26
commit
461196f089
|
@ -13,23 +13,20 @@ export default ObjectController.extend({
|
|||
postStream: Em.computed.alias('controllers.topic.postStream'),
|
||||
enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2),
|
||||
viewingTopic: Em.computed.match('controllers.application.currentPath', /^topic\./),
|
||||
viewingAdmin: Em.computed.match('controllers.application.currentPath', /^admin\./),
|
||||
showFilter: Em.computed.and('viewingTopic', 'postStream.hasNoFilters', 'enoughPostsForFiltering'),
|
||||
|
||||
// showFilter: Em.computed.and('postStream.hasNoFilters', 'enoughPostsForFiltering'),
|
||||
showName: Discourse.computed.propertyNotEqual('user.name', 'user.username'),
|
||||
|
||||
hasUserFilters: Em.computed.gt('postStream.userFilters.length', 0),
|
||||
|
||||
isSuspended: Em.computed.notEmpty('user.suspend_reason'),
|
||||
|
||||
showBadges: Discourse.computed.setting('enable_badges'),
|
||||
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
|
||||
canDelete: Em.computed.not("user.deleteForbidden"),
|
||||
showDelete: Em.computed.and("viewingAdmin", "showName", "canDelete"),
|
||||
|
||||
moreBadgesCount: function() {
|
||||
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
||||
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
||||
|
||||
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
|
||||
|
||||
hasCardBadgeImage: function() {
|
||||
var img = this.get('user.card_badge.image');
|
||||
return img && img.indexOf('fa-') !== 0;
|
||||
|
@ -77,7 +74,7 @@ export default ObjectController.extend({
|
|||
self.set('cardTarget', target);
|
||||
|
||||
Discourse.User.findByUsername(username).then(function (user) {
|
||||
self.setProperties({ user: user, avatar: user, visible: true});
|
||||
self.setProperties({ user: Discourse.AdminUser.create(user), avatar: user, visible: true});
|
||||
self.appEvents.trigger('usercard:shown');
|
||||
}).finally(function(){
|
||||
self.set('userLoading', null);
|
||||
|
@ -101,6 +98,10 @@ export default ObjectController.extend({
|
|||
postStream.cancelFilter();
|
||||
postStream.refresh();
|
||||
this.close();
|
||||
},
|
||||
|
||||
deleteUser: function(user) {
|
||||
user.destroy({ deletePosts: true });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,15 @@
|
|||
{{/if}}
|
||||
|
||||
{{#if showFilter}}
|
||||
<li><a class='btn' {{action "togglePosts" user}}>{{fa-icon "filter"}}{{i18n topic.filter_to username="username" post_count="participant.post_count"}}</a></li>
|
||||
<li><a class='btn' {{action "togglePosts" user}}>{{fa-icon "filter"}}{{i18n topic.filter_to username="username" post_count="participant.post_count"}}</a></li>
|
||||
{{/if}}
|
||||
|
||||
{{#if hasUserFilters}}
|
||||
<li><a class='btn' {{action "cancelFilter"}}>{{fa-icon "times"}}{{i18n topic.filters.cancel}}</a></li>
|
||||
<li><a class='btn' {{action "cancelFilter"}}>{{fa-icon "times"}}{{i18n topic.filters.cancel}}</a></li>
|
||||
{{/if}}
|
||||
|
||||
{{#if showDelete}}
|
||||
<li><a class='btn btn-danger' {{action "deleteUser" user}}>{{fa-icon "exclamation-triangle"}}{{i18n admin.user.delete}}</a></li>
|
||||
{{/if}}
|
||||
</ul>
|
||||
|
||||
|
@ -52,10 +56,10 @@
|
|||
{{/if}}
|
||||
|
||||
{{#if user}}
|
||||
<div class="metadata">
|
||||
<h3><span class='desc'>{{i18n last_post}}</span> {{format-date path="user.last_posted_at" leaveAgo="true"}} </h3>
|
||||
<h3><span class='desc'>{{i18n joined}}</span> {{format-date path="user.created_at" leaveAgo="true"}}</h3>
|
||||
</div>
|
||||
<div class="metadata">
|
||||
<h3><span class='desc'>{{i18n last_post}}</span> {{format-date path="user.last_posted_at" leaveAgo="true"}}</h3>
|
||||
<h3><span class='desc'>{{i18n joined}}</span> {{format-date path="user.created_at" leaveAgo="true"}}</h3>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if showBadges}}
|
||||
|
|
|
@ -66,7 +66,8 @@ class UserSerializer < BasicUserSerializer
|
|||
has_many :featured_user_badges, embed: :ids, serializer: UserBadgeSerializer, root: :user_badges
|
||||
has_one :card_badge, embed: :object, serializer: BadgeSerializer
|
||||
|
||||
staff_attributes :number_of_deleted_posts,
|
||||
staff_attributes :post_count,
|
||||
:number_of_deleted_posts,
|
||||
:number_of_flagged_posts,
|
||||
:number_of_flags_given,
|
||||
:number_of_suspensions,
|
||||
|
@ -207,6 +208,10 @@ class UserSerializer < BasicUserSerializer
|
|||
### STAFF ATTRIBUTES
|
||||
###
|
||||
|
||||
def post_count
|
||||
object.user_stat.try(:post_count)
|
||||
end
|
||||
|
||||
def number_of_deleted_posts
|
||||
Post.with_deleted
|
||||
.where(user_id: object.id)
|
||||
|
|
Loading…
Reference in New Issue
Block a user