DEV: Guardian for hiding about stats (#9841)

This commit is contained in:
Mark VanLandingham 2020-05-20 10:26:20 -05:00 committed by GitHub
parent cfff8b1f27
commit bd57ae83f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 45 deletions

View File

@ -64,6 +64,7 @@
</section>
{{/each}}
{{/if}}
{{#if model.can_see_about_stats}}
<section class="about stats">
<h3>{{d-icon "far-chart-bar"}} {{i18n "about.stats"}}</h3>
@ -108,6 +109,7 @@
</tbody>
</table>
</section>
{{/if}}
{{#if contactInfo}}
<section class="about contact">

View File

@ -16,7 +16,7 @@ class AboutController < ApplicationController
render :index
end
format.json do
render_serialized(@about, AboutSerializer)
render_json_dump(AboutSerializer.new(@about, scope: guardian))
end
end
end

View File

@ -21,7 +21,16 @@ class AboutSerializer < ApplicationSerializer
:title,
:locale,
:version,
:https
:https,
:can_see_about_stats
def can_see_about_stats
scope.can_see_about_stats?
end
def include_stats?
can_see_about_stats
end
def stats
object.class.fetch_cached_stats || Jobs::AboutStats.new.execute({})

View File

@ -493,6 +493,10 @@ class Guardian
is_staff?
end
def can_see_about_stats?
true
end
def auth_token
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
UserAuthToken.hash_token(cookie)

View File

@ -1,6 +1,7 @@
export default {
"about.json": {
about: {
can_see_about_stats: true,
stats: {
topic_count: 27480,
post_count: 490358,