Merge pull request #4746 from techAPJ/site-statistics
FEATURE: anonymized site statistics
This commit is contained in:
commit
39cb0ae108
|
@ -3,7 +3,7 @@ require_dependency 'site_serializer'
|
|||
class SiteController < ApplicationController
|
||||
layout false
|
||||
skip_before_filter :preload_json, :check_xhr
|
||||
skip_before_filter :redirect_to_login_if_required, only: ['basic_info']
|
||||
skip_before_filter :redirect_to_login_if_required, only: ['basic_info', 'statistics']
|
||||
|
||||
def site
|
||||
render json: Site.json_for(guardian)
|
||||
|
@ -42,4 +42,9 @@ class SiteController < ApplicationController
|
|||
# this info is always available cause it can be scraped from a 404 page
|
||||
render json: results
|
||||
end
|
||||
|
||||
def statistics
|
||||
return redirect_to path('/') unless SiteSetting.share_anonymized_statistics?
|
||||
render json: About.fetch_cached_stats
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1395,6 +1395,8 @@ en:
|
|||
|
||||
native_app_install_banner: "Asks recurring visitors to install Discourse native app."
|
||||
|
||||
share_anonymized_statistics: "Share anonymized usage statistics."
|
||||
|
||||
max_prints_per_hour_per_user: "Maximum number of /print page impressions (set to 0 to disable)"
|
||||
|
||||
full_name_required: "Full name is a required field of a user's profile."
|
||||
|
|
|
@ -54,6 +54,7 @@ Discourse::Application.routes.draw do
|
|||
end
|
||||
|
||||
get "site/basic-info" => 'site#basic_info'
|
||||
get "site/statistics" => 'site#statistics'
|
||||
|
||||
get "site_customizations/:key" => "site_customizations#show"
|
||||
|
||||
|
|
|
@ -1308,6 +1308,8 @@ uncategorized:
|
|||
|
||||
native_app_install_banner: false
|
||||
|
||||
share_anonymized_statistics: true
|
||||
|
||||
|
||||
user_preferences:
|
||||
default_email_digest_frequency:
|
||||
|
|
|
@ -24,4 +24,38 @@ describe SiteController do
|
|||
expect(json["mobile_logo_url"]).to eq("https://a.a/a.png")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.statistics' do
|
||||
|
||||
it 'is visible for sites requiring login' do
|
||||
SiteSetting.login_required = true
|
||||
SiteSetting.share_anonymized_statistics = true
|
||||
|
||||
xhr :get, :statistics
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(response).to be_success
|
||||
expect(json["topic_count"]).to be_present
|
||||
expect(json["post_count"]).to be_present
|
||||
expect(json["user_count"]).to be_present
|
||||
expect(json["topics_7_days"]).to be_present
|
||||
expect(json["topics_30_days"]).to be_present
|
||||
expect(json["posts_7_days"]).to be_present
|
||||
expect(json["posts_30_days"]).to be_present
|
||||
expect(json["users_7_days"]).to be_present
|
||||
expect(json["users_30_days"]).to be_present
|
||||
expect(json["active_users_7_days"]).to be_present
|
||||
expect(json["active_users_30_days"]).to be_present
|
||||
expect(json["like_count"]).to be_present
|
||||
expect(json["likes_7_days"]).to be_present
|
||||
expect(json["likes_30_days"]).to be_present
|
||||
end
|
||||
|
||||
it 'is not visible if site setting share_anonymized_statistics is disabled' do
|
||||
SiteSetting.share_anonymized_statistics = false
|
||||
|
||||
xhr :get, :statistics
|
||||
expect(response).to redirect_to '/'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue