From bd57ae83f1a4b1dea92ae9234013e2ebd41df6b6 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Wed, 20 May 2020 10:26:20 -0500 Subject: [PATCH] DEV: Guardian for hiding about stats (#9841) --- .../discourse/app/templates/about.hbs | 88 ++++++++++--------- app/controllers/about_controller.rb | 2 +- app/serializers/about_serializer.rb | 11 ++- lib/guardian.rb | 4 + test/javascripts/fixtures/about.js | 1 + 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/discourse/app/templates/about.hbs b/app/assets/javascripts/discourse/app/templates/about.hbs index 63cae2c2609..2659b0ebac4 100644 --- a/app/assets/javascripts/discourse/app/templates/about.hbs +++ b/app/assets/javascripts/discourse/app/templates/about.hbs @@ -64,50 +64,52 @@ {{/each}} {{/if}} -
-

{{d-icon "far-chart-bar"}} {{i18n "about.stats"}}

+ {{#if model.can_see_about_stats}} +
+

{{d-icon "far-chart-bar"}} {{i18n "about.stats"}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 {{i18n "about.stat.last_7_days"}}{{i18n "about.stat.last_30_days"}}{{i18n "about.stat.all_time"}}
{{i18n "about.topic_count"}}{{number model.stats.topics_7_days}}{{number model.stats.topics_30_days}}{{number model.stats.topic_count}}
{{i18n "about.post_count"}}{{number model.stats.posts_7_days}}{{number model.stats.posts_30_days}}{{number model.stats.post_count}}
{{i18n "about.user_count"}}{{number model.stats.users_7_days}}{{number model.stats.users_30_days}}{{number model.stats.user_count}}
{{i18n "about.active_user_count"}}{{number model.stats.active_users_7_days}}{{number model.stats.active_users_30_days}}
{{i18n "about.like_count"}}{{number model.stats.likes_7_days}}{{number model.stats.likes_30_days}}{{number model.stats.like_count}}
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 {{i18n "about.stat.last_7_days"}}{{i18n "about.stat.last_30_days"}}{{i18n "about.stat.all_time"}}
{{i18n "about.topic_count"}}{{number model.stats.topics_7_days}}{{number model.stats.topics_30_days}}{{number model.stats.topic_count}}
{{i18n "about.post_count"}}{{number model.stats.posts_7_days}}{{number model.stats.posts_30_days}}{{number model.stats.post_count}}
{{i18n "about.user_count"}}{{number model.stats.users_7_days}}{{number model.stats.users_30_days}}{{number model.stats.user_count}}
{{i18n "about.active_user_count"}}{{number model.stats.active_users_7_days}}{{number model.stats.active_users_30_days}}
{{i18n "about.like_count"}}{{number model.stats.likes_7_days}}{{number model.stats.likes_30_days}}{{number model.stats.like_count}}
+
+ {{/if}} {{#if contactInfo}}
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index fe2d3a2327d..3f3f9e15a36 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -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 diff --git a/app/serializers/about_serializer.rb b/app/serializers/about_serializer.rb index 308f990fd6c..8230c590a4c 100644 --- a/app/serializers/about_serializer.rb +++ b/app/serializers/about_serializer.rb @@ -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({}) diff --git a/lib/guardian.rb b/lib/guardian.rb index 00d496e46eb..456461fead6 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -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) diff --git a/test/javascripts/fixtures/about.js b/test/javascripts/fixtures/about.js index 7f9f17cbba5..4c7de6a87a3 100644 --- a/test/javascripts/fixtures/about.js +++ b/test/javascripts/fixtures/about.js @@ -1,6 +1,7 @@ export default { "about.json": { about: { + can_see_about_stats: true, stats: { topic_count: 27480, post_count: 490358,