DEV: Allow plugins to hide user stats by new guardian method (#9772)

This commit is contained in:
Mark VanLandingham 2020-05-14 11:57:35 -05:00 committed by GitHub
parent 87b9488137
commit bec6bace53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 44 deletions

View File

@ -1,53 +1,55 @@
{{#d-section pageClass="user-summary" tagName=""}}
<div class="user-content">
<div class="top-section stats-section">
<h3 class="stats-title">{{i18n "user.summary.stats"}}</h3>
<ul>
<li>
{{user-stat value=model.days_visited label="user.summary.days_visited"}}
</li>
<li>
{{user-stat value=timeRead label="user.summary.time_read" type="string"}}
</li>
{{#if showRecentTimeRead}}
{{#if model.can_see_summary_stats}}
<div class="top-section stats-section">
<h3 class="stats-title">{{i18n "user.summary.stats"}}</h3>
<ul>
<li>
{{user-stat value=recentTimeRead label="user.summary.recent_time_read" type="string"}}
{{user-stat value=model.days_visited label="user.summary.days_visited"}}
</li>
<li>
{{user-stat value=timeRead label="user.summary.time_read" type="string"}}
</li>
{{#if showRecentTimeRead}}
<li>
{{user-stat value=recentTimeRead label="user.summary.recent_time_read" type="string"}}
</li>
{{/if}}
<li>
{{user-stat value=model.topics_entered label="user.summary.topics_entered"}}
</li>
<li>
{{user-stat value=model.posts_read_count label="user.summary.posts_read"}}
</li>
{{/if}}
<li>
{{user-stat value=model.topics_entered label="user.summary.topics_entered"}}
</li>
<li>
{{user-stat value=model.posts_read_count label="user.summary.posts_read"}}
</li>
<li class="linked-stat">
{{#link-to "userActivity.likesGiven"}}
{{user-stat value=model.likes_given icon="heart" label="user.summary.likes_given"}}
{{/link-to}}
</li>
{{#if model.bookmark_count}}
<li class="linked-stat">
{{#link-to "userActivity.bookmarks"}}
{{user-stat value=model.bookmark_count label="user.summary.bookmark_count"}}
{{#link-to "userActivity.likesGiven"}}
{{user-stat value=model.likes_given icon="heart" label="user.summary.likes_given"}}
{{/link-to}}
</li>
{{/if}}
<li class="linked-stat">
{{#link-to "userActivity.topics"}}
{{user-stat value=model.topic_count label="user.summary.topic_count"}}
{{/link-to}}
</li>
<li class="linked-stat">
{{#link-to "userActivity.replies"}}
{{user-stat value=model.post_count label="user.summary.post_count"}}
{{/link-to}}
</li>
<li>
{{user-stat value=model.likes_received icon="heart" label="user.summary.likes_received"}}
</li>
{{plugin-outlet name="user-summary-stat" tagName="" connectorTagName="li" args=(hash model=model)}}
</ul>
</div>
{{#if model.bookmark_count}}
<li class="linked-stat">
{{#link-to "userActivity.bookmarks"}}
{{user-stat value=model.bookmark_count label="user.summary.bookmark_count"}}
{{/link-to}}
</li>
{{/if}}
<li class="linked-stat">
{{#link-to "userActivity.topics"}}
{{user-stat value=model.topic_count label="user.summary.topic_count"}}
{{/link-to}}
</li>
<li class="linked-stat">
{{#link-to "userActivity.replies"}}
{{user-stat value=model.post_count label="user.summary.post_count"}}
{{/link-to}}
</li>
<li>
{{user-stat value=model.likes_received icon="heart" label="user.summary.likes_received"}}
</li>
{{plugin-outlet name="user-summary-stat" tagName="" connectorTagName="li" args=(hash model=model)}}
</ul>
</div>
{{/if}}
<div class="top-section">
{{#user-summary-section title="top_replies" class="replies-section pull-left"}}

View File

@ -112,6 +112,10 @@ class UserSummary
@user.id
end
def user
@user
end
def user_stat
@user.user_stat
end

View File

@ -56,7 +56,12 @@ class UserSummarySerializer < ApplicationSerializer
:post_count,
:time_read,
:recent_time_read,
:bookmark_count
:bookmark_count,
:can_see_summary_stats
def can_see_summary_stats
scope.can_see_summary_stats?(object.user)
end
def include_badges?
SiteSetting.enable_badges
@ -73,4 +78,40 @@ class UserSummarySerializer < ApplicationSerializer
def recent_time_read
object.recent_time_read
end
def include_likes_given?
can_see_summary_stats
end
def include_likes_received?
can_see_summary_stats
end
def include_topics_entered?
can_see_summary_stats
end
def include_posts_read_count?
can_see_summary_stats
end
def include_days_visited?
can_see_summary_stats
end
def include_topic_count?
can_see_summary_stats
end
def include_post_count?
can_see_summary_stats
end
def include_time_read?
can_see_summary_stats
end
def include_recent_time_read?
can_see_summary_stats
end
end

View File

@ -154,4 +154,8 @@ module UserGuardian
.exists?
)
end
def can_see_summary_stats?(target_user)
true
end
end