FEATURE: add staff counters on user profile

This commit is contained in:
Régis Hanol 2014-06-30 22:46:47 +02:00
parent 0f52f26587
commit 15120bb583
4 changed files with 190 additions and 77 deletions

View File

@ -64,25 +64,40 @@
<div class='details'>
<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>&nbsp;{{i18n user.staff_counters.flags_given}}</div>
{{/if}}
{{#if number_of_flagged_posts}}
<div><span class="pill flagged-posts">{{number_of_flagged_posts}}</span>&nbsp;{{i18n user.staff_counters.flagged_posts}}</div>
{{/if}}
{{#if number_of_deleted_posts}}
<div><span class="pill deleted-posts">{{number_of_deleted_posts}}</span>&nbsp;{{i18n user.staff_counters.deleted_posts}}</div>
{{/if}}
{{#if number_of_suspensions}}
<div><span class="pill suspensions">{{number_of_suspensions}}</span>&nbsp;{{i18n user.staff_counters.suspensions}}</div>
{{/if}}
</div>
<div class="primary-textual">
<h1>{{username}} {{{statusIcon}}}</h1>
<h2>{{name}}</h2>
{{bound-avatar model "huge"}}
<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}}
<div class='suspended'>
<i class='fa fa-ban'></i>
<b>{{i18n user.suspended_notice date="suspendedTillDate"}}</b><br/>
<b>{{i18n user.suspended_reason}}</b> {{suspend_reason}}
</div>
{{/if}}
{{plugin-outlet "user-profile-primary"}}
{{#if isSuspended}}
<div class='suspended'>
<i class='fa fa-ban'></i>
<b>{{i18n user.suspended_notice date="suspendedTillDate"}}</b><br/>
<b>{{i18n user.suspended_reason}}</b> {{suspend_reason}}
</div>
{{/if}}
</div>
</div>

View File

@ -190,6 +190,7 @@
}
.primary {
position: relative;
margin-top: 20px;
float: left;
width: 65%;
@ -248,6 +249,10 @@
margin-top: 0;
}
.staff-counters {
display: none;
}
.details {
.secondary { display: none; }
.bio { display: none; }
@ -332,4 +337,36 @@
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;
}
}

View File

@ -1,5 +1,23 @@
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,
:email,
:last_posted_at,
@ -30,27 +48,12 @@ class UserSerializer < BasicUserSerializer
has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer
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
# If they have a bio return it
excerpt = object.user_profile.bio_excerpt
return excerpt if excerpt.present?
staff_attributes :number_of_deleted_posts,
:number_of_flagged_posts,
:number_of_flags_given,
: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,
:locale,
@ -74,24 +77,44 @@ class UserSerializer < BasicUserSerializer
:custom_avatar_upload_id,
:custom_fields
def gravatar_avatar_upload_id
object.user_avatar.try(:gravatar_upload_id)
###
### ATTRIBUTES
###
def bio_raw
object.user_profile.bio_raw
end
def custom_avatar_upload_id
object.user_avatar.try(:custom_upload_id)
def include_bio_raw?
bio_raw.present?
end
def auto_track_topics_after_msecs
object.auto_track_topics_after_msecs || SiteSetting.auto_track_topics_after
def bio_cooked
object.user_profile.bio_processed
end
def new_topic_duration_minutes
object.new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
def website
object.user_profile.website
end
def can_send_private_message_to_user
scope.can_send_private_message?(object)
def include_website?
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
def can_edit
@ -110,45 +133,27 @@ class UserSerializer < BasicUserSerializer
scope.can_edit_name?(object)
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
UserAction.stats(object.id, scope)
end
def include_suspended?
object.suspended?
def can_send_private_message_to_user
scope.can_send_private_message?(object)
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?
object.suspended?
end
@ -157,6 +162,47 @@ class UserSerializer < BasicUserSerializer
object.suspended?
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
CategoryUser.lookup(object, :muted).pluck(:category_id)
end
@ -172,4 +218,13 @@ class UserSerializer < BasicUserSerializer
def private_messages_stats
UserAction.private_messages_stats(object.id, scope)
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

View File

@ -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."
unread_message_count: "Messages"
staff_counters:
flags_given: "helpful flags cast"
flagged_posts: "flagged posts"
deleted_posts: "deleted posts"
suspensions: "suspensions"
messages:
all: "All"
mine: "Mine"