mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 05:03:39 +08:00
DEV: add logo URL and locale details to the Discover stats. (#26320)
We will be collecting the logo URL and the site's default locale values along with existing basic details to display the site on the Discourse Discover listing page. It will be included only if the site is opted-in by enabling the "`include_in_discourse_discover`" site setting. Also, we no longer going to use `about.json` and `site/statistics.json` endpoints retrieve these data. We will be using only the `site/basic-info.json` endpoint.
This commit is contained in:
parent
3e0898e498
commit
9dc6325821
|
@ -42,9 +42,13 @@ class SiteController < ApplicationController
|
||||||
results[:mobile_logo_url] = UrlHelper.absolute(mobile_logo_url)
|
results[:mobile_logo_url] = UrlHelper.absolute(mobile_logo_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
results[:discourse_discover_enrolled] = true if SiteSetting.include_in_discourse_discover?
|
if guardian.is_discourse_hub_request?
|
||||||
|
DiscourseHub.stats_fetched_at = Time.zone.now
|
||||||
DiscourseHub.stats_fetched_at = Time.zone.now if request.user_agent == "Discourse Hub"
|
discover_data = About.discourse_discover
|
||||||
|
discover_data.each_key do |key|
|
||||||
|
results["discourse_discover_#{key}".to_sym] = discover_data[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# this info is always available cause it can be scraped from a 404 page
|
# this info is always available cause it can be scraped from a 404 page
|
||||||
render json: results
|
render json: results
|
||||||
|
|
|
@ -97,4 +97,12 @@ class About
|
||||||
def category_mods_limit=(number)
|
def category_mods_limit=(number)
|
||||||
@category_mods_limit = number
|
@category_mods_limit = number
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.discourse_discover
|
||||||
|
@discourse_discover ||= {
|
||||||
|
enrolled: SiteSetting.include_in_discourse_discover?,
|
||||||
|
logo_url: UrlHelper.absolute(SiteSetting.site_logo_url),
|
||||||
|
locale: SiteSetting.default_locale,
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,9 +46,6 @@ class Stat
|
||||||
Stat.new("users", show_in_ui: true, expose_via_api: true) { Statistics.users },
|
Stat.new("users", show_in_ui: true, expose_via_api: true) { Statistics.users },
|
||||||
Stat.new("active_users", show_in_ui: true, expose_via_api: true) { Statistics.active_users },
|
Stat.new("active_users", show_in_ui: true, expose_via_api: true) { Statistics.active_users },
|
||||||
Stat.new("likes", show_in_ui: true, expose_via_api: true) { Statistics.likes },
|
Stat.new("likes", show_in_ui: true, expose_via_api: true) { Statistics.likes },
|
||||||
Stat.new("discourse_discover", show_in_ui: false, expose_via_api: true) do
|
|
||||||
Statistics.discourse_discover
|
|
||||||
end,
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,7 @@ class AboutSerializer < ApplicationSerializer
|
||||||
:https,
|
:https,
|
||||||
:can_see_about_stats,
|
:can_see_about_stats,
|
||||||
:contact_url,
|
:contact_url,
|
||||||
:contact_email,
|
:contact_email
|
||||||
:discourse_discover_enrolled
|
|
||||||
|
|
||||||
def include_stats?
|
def include_stats?
|
||||||
can_see_about_stats
|
can_see_about_stats
|
||||||
|
@ -50,14 +49,6 @@ class AboutSerializer < ApplicationSerializer
|
||||||
SiteSetting.contact_email
|
SiteSetting.contact_email
|
||||||
end
|
end
|
||||||
|
|
||||||
def discourse_discover_enrolled
|
|
||||||
SiteSetting.include_in_discourse_discover?
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_discourse_discover_enrolled?
|
|
||||||
SiteSetting.include_in_discourse_discover?
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def can_see_about_stats
|
def can_see_about_stats
|
||||||
|
|
|
@ -637,6 +637,10 @@ class Guardian
|
||||||
other && authenticated? && other.is_a?(User) && @user == other
|
other && authenticated? && other.is_a?(User) && @user == other
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_discourse_hub_request?
|
||||||
|
request&.user_agent == "Discourse Hub"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def is_my_own?(obj)
|
def is_my_own?(obj)
|
||||||
|
|
|
@ -47,8 +47,4 @@ class Statistics
|
||||||
count: User.real.count,
|
count: User.real.count,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.discourse_discover
|
|
||||||
{ enrolled: SiteSetting.include_in_discourse_discover? }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -103,7 +103,6 @@ TEXT
|
||||||
:likes_7_days,
|
:likes_7_days,
|
||||||
:likes_30_days,
|
:likes_30_days,
|
||||||
:likes_count,
|
:likes_count,
|
||||||
:discourse_discover_enrolled,
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -48,17 +48,6 @@ RSpec.describe AboutController do
|
||||||
expect(response.parsed_body["about"].keys).to include("stats")
|
expect(response.parsed_body["about"].keys).to include("stats")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds Discourse Discover status if enabled" do
|
|
||||||
get "/about.json"
|
|
||||||
|
|
||||||
expect(response.parsed_body["about"].keys).not_to include("discourse_discover_enrolled")
|
|
||||||
|
|
||||||
SiteSetting.include_in_discourse_discover = true
|
|
||||||
get "/about.json"
|
|
||||||
|
|
||||||
expect(response.parsed_body["about"]["discourse_discover_enrolled"]).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not serialize stats when 'Guardian#can_see_about_stats?' is false" do
|
it "does not serialize stats when 'Guardian#can_see_about_stats?' is false" do
|
||||||
Guardian.any_instance.stubs(:can_see_about_stats?).returns(false)
|
Guardian.any_instance.stubs(:can_see_about_stats?).returns(false)
|
||||||
get "/about.json"
|
get "/about.json"
|
||||||
|
|
|
@ -15,7 +15,7 @@ RSpec.describe SiteController do
|
||||||
SiteSetting.include_in_discourse_discover = true
|
SiteSetting.include_in_discourse_discover = true
|
||||||
Theme.clear_default!
|
Theme.clear_default!
|
||||||
|
|
||||||
get "/site/basic-info.json"
|
get "/site/basic-info.json", headers: { "HTTP_USER_AGENT" => "Discourse Hub" }
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
|
|
||||||
expected_url = UrlHelper.absolute(upload.url)
|
expected_url = UrlHelper.absolute(upload.url)
|
||||||
|
@ -67,16 +67,6 @@ RSpec.describe SiteController do
|
||||||
expect(json["likes_30_days"]).to be_present
|
expect(json["likes_30_days"]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns Discourse Discover stats" do
|
|
||||||
SiteSetting.include_in_discourse_discover = true
|
|
||||||
About.refresh_stats
|
|
||||||
|
|
||||||
get "/site/statistics.json"
|
|
||||||
json = response.parsed_body
|
|
||||||
|
|
||||||
expect(json["discourse_discover_enrolled"]).to be_truthy
|
|
||||||
end
|
|
||||||
|
|
||||||
it "is not visible if site setting share_anonymized_statistics is disabled" do
|
it "is not visible if site setting share_anonymized_statistics is disabled" do
|
||||||
SiteSetting.share_anonymized_statistics = false
|
SiteSetting.share_anonymized_statistics = false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user