mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
FEATURE: add staff counters on user profile
This commit is contained in:
parent
0f52f26587
commit
15120bb583
@ -64,25 +64,40 @@
|
|||||||
|
|
||||||
<div class='details'>
|
<div class='details'>
|
||||||
<div class='primary'>
|
<div class='primary'>
|
||||||
{{bound-avatar model "huge"}}
|
<div class='staff-counters'>
|
||||||
|
{{#if number_of_flags_given}}
|
||||||
|
<div><span class="pill helpful-flags">{{number_of_flags_given}}</span> {{i18n user.staff_counters.flags_given}}</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if number_of_flagged_posts}}
|
||||||
|
<div><span class="pill flagged-posts">{{number_of_flagged_posts}}</span> {{i18n user.staff_counters.flagged_posts}}</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if number_of_deleted_posts}}
|
||||||
|
<div><span class="pill deleted-posts">{{number_of_deleted_posts}}</span> {{i18n user.staff_counters.deleted_posts}}</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if number_of_suspensions}}
|
||||||
|
<div><span class="pill suspensions">{{number_of_suspensions}}</span> {{i18n user.staff_counters.suspensions}}</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="primary-textual">
|
{{bound-avatar model "huge"}}
|
||||||
<h1>{{username}} {{{statusIcon}}}</h1>
|
|
||||||
<h2>{{name}}</h2>
|
|
||||||
|
|
||||||
<div class='bio'>{{{bio_cooked}}}</div>
|
<div class="primary-textual">
|
||||||
|
<h1>{{username}} {{{statusIcon}}}</h1>
|
||||||
|
<h2>{{name}}</h2>
|
||||||
|
|
||||||
{{groups-list groups=custom_groups}}
|
<div class='bio'>{{{bio_cooked}}}</div>
|
||||||
|
|
||||||
{{plugin-outlet "user-profile-primary"}}
|
{{groups-list groups=custom_groups}}
|
||||||
|
|
||||||
{{#if isSuspended}}
|
{{plugin-outlet "user-profile-primary"}}
|
||||||
<div class='suspended'>
|
|
||||||
<i class='fa fa-ban'></i>
|
{{#if isSuspended}}
|
||||||
<b>{{i18n user.suspended_notice date="suspendedTillDate"}}</b><br/>
|
<div class='suspended'>
|
||||||
<b>{{i18n user.suspended_reason}}</b> {{suspend_reason}}
|
<i class='fa fa-ban'></i>
|
||||||
</div>
|
<b>{{i18n user.suspended_notice date="suspendedTillDate"}}</b><br/>
|
||||||
{{/if}}
|
<b>{{i18n user.suspended_reason}}</b> {{suspend_reason}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -190,6 +190,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.primary {
|
.primary {
|
||||||
|
position: relative;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
float: left;
|
float: left;
|
||||||
width: 65%;
|
width: 65%;
|
||||||
@ -248,6 +249,10 @@
|
|||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.staff-counters {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.details {
|
.details {
|
||||||
.secondary { display: none; }
|
.secondary { display: none; }
|
||||||
.bio { display: none; }
|
.bio { display: none; }
|
||||||
@ -332,4 +337,36 @@
|
|||||||
margin-top: -4px;
|
margin-top: -4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.staff-counters {
|
||||||
|
text-align: left;
|
||||||
|
position: absolute;
|
||||||
|
top: -20px;
|
||||||
|
> div {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
font-size: 2em;
|
||||||
|
border-radius: 100%;
|
||||||
|
display: inline-block;
|
||||||
|
height: 30px;
|
||||||
|
width: 40px;
|
||||||
|
text-align: center;
|
||||||
|
vertical-align: middle;
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
.helpful-flags {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
.flagged-posts {
|
||||||
|
background-color: #E49735;
|
||||||
|
}
|
||||||
|
.deleted-posts {
|
||||||
|
background-color: #EC441B;
|
||||||
|
}
|
||||||
|
.suspensions {
|
||||||
|
background-color: #c22020;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
class UserSerializer < BasicUserSerializer
|
class UserSerializer < BasicUserSerializer
|
||||||
|
|
||||||
|
def self.staff_attributes(*attrs)
|
||||||
|
attributes(*attrs)
|
||||||
|
attrs.each do |attr|
|
||||||
|
define_method "include_#{attr}?" do
|
||||||
|
scope.is_staff?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.private_attributes(*attrs)
|
||||||
|
attributes(*attrs)
|
||||||
|
attrs.each do |attr|
|
||||||
|
define_method "include_#{attr}?" do
|
||||||
|
can_edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
attributes :name,
|
attributes :name,
|
||||||
:email,
|
:email,
|
||||||
:last_posted_at,
|
:last_posted_at,
|
||||||
@ -30,27 +48,12 @@ class UserSerializer < BasicUserSerializer
|
|||||||
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
|
||||||
has_many :featured_user_badges, embed: :ids, serializer: UserBadgeSerializer, root: :user_badges
|
has_many :featured_user_badges, embed: :ids, serializer: UserBadgeSerializer, root: :user_badges
|
||||||
|
|
||||||
def self.private_attributes(*attrs)
|
|
||||||
attributes(*attrs)
|
|
||||||
attrs.each do |attr|
|
|
||||||
define_method "include_#{attr}?" do
|
|
||||||
can_edit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def bio_excerpt
|
staff_attributes :number_of_deleted_posts,
|
||||||
# If they have a bio return it
|
:number_of_flagged_posts,
|
||||||
excerpt = object.user_profile.bio_excerpt
|
:number_of_flags_given,
|
||||||
return excerpt if excerpt.present?
|
:number_of_suspensions
|
||||||
|
|
||||||
# Without a bio, determine what message to show
|
|
||||||
if scope.user && scope.user.id == object.id
|
|
||||||
I18n.t('user_profile.no_info_me', username_lower: object.username_lower)
|
|
||||||
else
|
|
||||||
I18n.t('user_profile.no_info_other', name: object.name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private_attributes :email,
|
private_attributes :email,
|
||||||
:locale,
|
:locale,
|
||||||
@ -74,24 +77,44 @@ class UserSerializer < BasicUserSerializer
|
|||||||
:custom_avatar_upload_id,
|
:custom_avatar_upload_id,
|
||||||
:custom_fields
|
:custom_fields
|
||||||
|
|
||||||
def gravatar_avatar_upload_id
|
###
|
||||||
object.user_avatar.try(:gravatar_upload_id)
|
### ATTRIBUTES
|
||||||
|
###
|
||||||
|
|
||||||
|
def bio_raw
|
||||||
|
object.user_profile.bio_raw
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_avatar_upload_id
|
def include_bio_raw?
|
||||||
object.user_avatar.try(:custom_upload_id)
|
bio_raw.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def auto_track_topics_after_msecs
|
def bio_cooked
|
||||||
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
object.user_profile.bio_processed
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_topic_duration_minutes
|
def website
|
||||||
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
object.user_profile.website
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_send_private_message_to_user
|
def include_website?
|
||||||
scope.can_send_private_message?(object)
|
website.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def profile_background
|
||||||
|
object.user_profile.profile_background
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_profile_background?
|
||||||
|
profile_background.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def location
|
||||||
|
object.user_profile.location
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_location?
|
||||||
|
location.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_edit
|
def can_edit
|
||||||
@ -110,45 +133,27 @@ class UserSerializer < BasicUserSerializer
|
|||||||
scope.can_edit_name?(object)
|
scope.can_edit_name?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def location
|
|
||||||
object.user_profile.location
|
|
||||||
end
|
|
||||||
def include_location?
|
|
||||||
location.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def website
|
|
||||||
object.user_profile.website
|
|
||||||
end
|
|
||||||
def include_website?
|
|
||||||
website.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_bio_raw?
|
|
||||||
bio_raw.present?
|
|
||||||
end
|
|
||||||
def bio_raw
|
|
||||||
object.user_profile.bio_raw
|
|
||||||
end
|
|
||||||
|
|
||||||
def bio_cooked
|
|
||||||
object.user_profile.bio_processed
|
|
||||||
end
|
|
||||||
|
|
||||||
def profile_background
|
|
||||||
object.user_profile.profile_background
|
|
||||||
end
|
|
||||||
def include_profile_background?
|
|
||||||
profile_background.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def stats
|
def stats
|
||||||
UserAction.stats(object.id, scope)
|
UserAction.stats(object.id, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_suspended?
|
def can_send_private_message_to_user
|
||||||
object.suspended?
|
scope.can_send_private_message?(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bio_excerpt
|
||||||
|
# If they have a bio return it
|
||||||
|
excerpt = object.user_profile.bio_excerpt
|
||||||
|
return excerpt if excerpt.present?
|
||||||
|
|
||||||
|
# Without a bio, determine what message to show
|
||||||
|
if scope.user && scope.user.id == object.id
|
||||||
|
I18n.t('user_profile.no_info_me', username_lower: object.username_lower)
|
||||||
|
else
|
||||||
|
I18n.t('user_profile.no_info_other', name: object.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def include_suspend_reason?
|
def include_suspend_reason?
|
||||||
object.suspended?
|
object.suspended?
|
||||||
end
|
end
|
||||||
@ -157,6 +162,47 @@ class UserSerializer < BasicUserSerializer
|
|||||||
object.suspended?
|
object.suspended?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
###
|
||||||
|
### STAFF ATTRIBUTES
|
||||||
|
###
|
||||||
|
|
||||||
|
def number_of_deleted_posts
|
||||||
|
Post.with_deleted
|
||||||
|
.where(user_id: object.id)
|
||||||
|
.where(user_deleted: false)
|
||||||
|
.where.not(deleted_by: object.id)
|
||||||
|
.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def number_of_flagged_posts
|
||||||
|
Post.with_deleted
|
||||||
|
.where(user_id: object.id)
|
||||||
|
.where(hidden: true)
|
||||||
|
.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def number_of_flags_given
|
||||||
|
PostAction.where(post_action_type_id: PostActionType.notify_flag_type_ids)
|
||||||
|
.where(user_id: object.id)
|
||||||
|
.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def number_of_suspensions
|
||||||
|
UserHistory.for(object, :suspend_user).count
|
||||||
|
end
|
||||||
|
|
||||||
|
###
|
||||||
|
### PRIVATE ATTRIBUTES
|
||||||
|
###
|
||||||
|
|
||||||
|
def auto_track_topics_after_msecs
|
||||||
|
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
|
||||||
|
end
|
||||||
|
|
||||||
|
def new_topic_duration_minutes
|
||||||
|
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
||||||
|
end
|
||||||
|
|
||||||
def muted_category_ids
|
def muted_category_ids
|
||||||
CategoryUser.lookup(object, :muted).pluck(:category_id)
|
CategoryUser.lookup(object, :muted).pluck(:category_id)
|
||||||
end
|
end
|
||||||
@ -172,4 +218,13 @@ class UserSerializer < BasicUserSerializer
|
|||||||
def private_messages_stats
|
def private_messages_stats
|
||||||
UserAction.private_messages_stats(object.id, scope)
|
UserAction.private_messages_stats(object.id, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gravatar_avatar_upload_id
|
||||||
|
object.user_avatar.try(:gravatar_upload_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def custom_avatar_upload_id
|
||||||
|
object.user_avatar.try(:custom_upload_id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -291,6 +291,12 @@ en:
|
|||||||
delete_yourself_not_allowed: "You cannot delete your account right now. Contact an admin to do delete your account for you."
|
delete_yourself_not_allowed: "You cannot delete your account right now. Contact an admin to do delete your account for you."
|
||||||
unread_message_count: "Messages"
|
unread_message_count: "Messages"
|
||||||
|
|
||||||
|
staff_counters:
|
||||||
|
flags_given: "helpful flags cast"
|
||||||
|
flagged_posts: "flagged posts"
|
||||||
|
deleted_posts: "deleted posts"
|
||||||
|
suspensions: "suspensions"
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
all: "All"
|
all: "All"
|
||||||
mine: "Mine"
|
mine: "Mine"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user