DEV: Refactor discover setting reporting (#26706)
This commit is contained in:
parent
e1d9fd479f
commit
98d400f7b5
|
@ -36,20 +36,14 @@ class SiteController < ApplicationController
|
||||||
header_primary_color: ColorScheme.hex_for_name("header_primary") || "333333",
|
header_primary_color: ColorScheme.hex_for_name("header_primary") || "333333",
|
||||||
header_background_color: ColorScheme.hex_for_name("header_background") || "ffffff",
|
header_background_color: ColorScheme.hex_for_name("header_background") || "ffffff",
|
||||||
login_required: SiteSetting.login_required,
|
login_required: SiteSetting.login_required,
|
||||||
|
locale: SiteSetting.default_locale,
|
||||||
|
include_in_discourse_discover: SiteSetting.include_in_discourse_discover,
|
||||||
}
|
}
|
||||||
|
|
||||||
if mobile_logo_url = SiteSetting.site_mobile_logo_url.presence
|
if mobile_logo_url = SiteSetting.site_mobile_logo_url.presence
|
||||||
results[:mobile_logo_url] = UrlHelper.absolute(mobile_logo_url)
|
results[:mobile_logo_url] = UrlHelper.absolute(mobile_logo_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
if guardian.is_discourse_hub_request?
|
|
||||||
DiscourseHub.stats_fetched_at = Time.zone.now
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,12 +98,4 @@ 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
|
||||||
|
|
|
@ -636,10 +636,6 @@ 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)
|
||||||
|
|
|
@ -28,6 +28,12 @@
|
||||||
"login_required": {
|
"login_required": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"locale": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"include_in_discourse_discover": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"mobile_logo_url": {
|
"mobile_logo_url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
@ -42,6 +48,8 @@
|
||||||
"header_primary_color",
|
"header_primary_color",
|
||||||
"header_background_color",
|
"header_background_color",
|
||||||
"login_required",
|
"login_required",
|
||||||
|
"locale",
|
||||||
|
"include_in_discourse_discover",
|
||||||
"mobile_logo_url"
|
"mobile_logo_url"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -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", headers: { "HTTP_USER_AGENT" => "Discourse Hub" }
|
get "/site/basic-info.json"
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
|
|
||||||
expected_url = UrlHelper.absolute(upload.url)
|
expected_url = UrlHelper.absolute(upload.url)
|
||||||
|
@ -29,16 +29,19 @@ RSpec.describe SiteController do
|
||||||
expect(json["header_primary_color"]).to eq("333333")
|
expect(json["header_primary_color"]).to eq("333333")
|
||||||
expect(json["header_background_color"]).to eq("ffffff")
|
expect(json["header_background_color"]).to eq("ffffff")
|
||||||
expect(json["login_required"]).to eq(true)
|
expect(json["login_required"]).to eq(true)
|
||||||
expect(json["discourse_discover_enrolled"]).to eq(true)
|
expect(json["locale"]).to eq("en")
|
||||||
|
expect(json["include_in_discourse_discover"]).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "skips `discourse_discover_enrolled` if `include_in_discourse_discover` setting disabled" do
|
it "includes false values for include_in_discourse_discover and login_required" do
|
||||||
SiteSetting.include_in_discourse_discover = false
|
SiteSetting.include_in_discourse_discover = false
|
||||||
|
SiteSetting.login_required = false
|
||||||
|
|
||||||
get "/site/basic-info.json"
|
get "/site/basic-info.json"
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
|
|
||||||
expect(json.keys).not_to include("discourse_discover_enrolled")
|
expect(json["include_in_discourse_discover"]).to eq(false)
|
||||||
|
expect(json["login_required"]).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue