mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
FIX: do not include contact url & email in client site settings payload (#13004)
This commit is contained in:
@ -6,20 +6,15 @@ import { gt } from "@ember/object/computed";
|
|||||||
export default Controller.extend({
|
export default Controller.extend({
|
||||||
faqOverriden: gt("siteSettings.faq_url.length", 0),
|
faqOverriden: gt("siteSettings.faq_url.length", 0),
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed("model.contact_url", "model.contact_email")
|
||||||
contactInfo() {
|
contactInfo(url, email) {
|
||||||
if (this.siteSettings.contact_url) {
|
if (url) {
|
||||||
return I18n.t("about.contact_info", {
|
return I18n.t("about.contact_info", {
|
||||||
contact_info:
|
contact_info: `<a href='${url}' target='_blank'>${url}</a>`,
|
||||||
"<a href='" +
|
|
||||||
this.siteSettings.contact_url +
|
|
||||||
"' target='_blank'>" +
|
|
||||||
this.siteSettings.contact_url +
|
|
||||||
"</a>",
|
|
||||||
});
|
});
|
||||||
} else if (this.siteSettings.contact_email) {
|
} else if (email) {
|
||||||
return I18n.t("about.contact_info", {
|
return I18n.t("about.contact_info", {
|
||||||
contact_info: this.siteSettings.contact_email,
|
contact_info: email,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -11,17 +11,6 @@ export default {
|
|||||||
secret: false,
|
secret: false,
|
||||||
type: "string"
|
type: "string"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
setting: "contact_email",
|
|
||||||
description:
|
|
||||||
"Email address of key contact responsible for this site. Used for critical notifications and displayed on the /about page for urgent matters.",
|
|
||||||
default: "",
|
|
||||||
value: "",
|
|
||||||
category: "required",
|
|
||||||
preview: null,
|
|
||||||
secret: false,
|
|
||||||
type: "email"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
setting: "site_contact_username",
|
setting: "site_contact_username",
|
||||||
description:
|
description:
|
||||||
|
@ -22,11 +22,9 @@ class AboutSerializer < ApplicationSerializer
|
|||||||
:locale,
|
:locale,
|
||||||
:version,
|
:version,
|
||||||
:https,
|
:https,
|
||||||
:can_see_about_stats
|
:can_see_about_stats,
|
||||||
|
:contact_url,
|
||||||
def can_see_about_stats
|
:contact_email
|
||||||
scope.can_see_about_stats?
|
|
||||||
end
|
|
||||||
|
|
||||||
def include_stats?
|
def include_stats?
|
||||||
can_see_about_stats
|
can_see_about_stats
|
||||||
@ -35,4 +33,30 @@ class AboutSerializer < ApplicationSerializer
|
|||||||
def stats
|
def stats
|
||||||
object.class.fetch_cached_stats || Jobs::AboutStats.new.execute({})
|
object.class.fetch_cached_stats || Jobs::AboutStats.new.execute({})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_contact_url?
|
||||||
|
can_see_site_contact_details
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_url
|
||||||
|
SiteSetting.contact_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_contact_email?
|
||||||
|
can_see_site_contact_details
|
||||||
|
end
|
||||||
|
|
||||||
|
def contact_email
|
||||||
|
SiteSetting.contact_email
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def can_see_about_stats
|
||||||
|
scope.can_see_about_stats?
|
||||||
|
end
|
||||||
|
|
||||||
|
def can_see_site_contact_details
|
||||||
|
scope.can_see_site_contact_details?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -33,11 +33,9 @@ required:
|
|||||||
default: ""
|
default: ""
|
||||||
client: true
|
client: true
|
||||||
contact_email:
|
contact_email:
|
||||||
client: true
|
|
||||||
default: ""
|
default: ""
|
||||||
type: email
|
type: email
|
||||||
contact_url:
|
contact_url:
|
||||||
client: true
|
|
||||||
default: ""
|
default: ""
|
||||||
notification_email:
|
notification_email:
|
||||||
default: "noreply@unconfigured.discourse.org"
|
default: "noreply@unconfigured.discourse.org"
|
||||||
|
@ -530,6 +530,10 @@ class Guardian
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_see_site_contact_details?
|
||||||
|
!SiteSetting.login_required? || authenticated?
|
||||||
|
end
|
||||||
|
|
||||||
def auth_token
|
def auth_token
|
||||||
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
|
if cookie = request&.cookies[Auth::DefaultCurrentUserProvider::TOKEN_COOKIE]
|
||||||
UserAuthToken.hash_token(cookie)
|
UserAuthToken.hash_token(cookie)
|
||||||
|
@ -3836,4 +3836,34 @@ describe Guardian do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "can_see_site_contact_details" do
|
||||||
|
context "login_required is enabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.login_required = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is false for anonymous users" do
|
||||||
|
expect(Guardian.new.can_see_site_contact_details?).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is true for regular users" do
|
||||||
|
expect(Guardian.new(user).can_see_site_contact_details?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "login_required is disabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.login_required = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is true for anonymous users" do
|
||||||
|
expect(Guardian.new.can_see_site_contact_details?).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is true for regular users" do
|
||||||
|
expect(Guardian.new(user).can_see_site_contact_details?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
48
spec/serializers/about_serializer_spec.rb
Normal file
48
spec/serializers/about_serializer_spec.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe AboutSerializer do
|
||||||
|
|
||||||
|
fab!(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
context "login_required is enabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.login_required = true
|
||||||
|
SiteSetting.contact_url = "https://example.com/contact"
|
||||||
|
SiteSetting.contact_email = "example@foobar.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contact details are hidden from anonymous users" do
|
||||||
|
json = AboutSerializer.new(About.new(nil), scope: Guardian.new(nil), root: nil).as_json
|
||||||
|
expect(json[:contact_url]).to eq(nil)
|
||||||
|
expect(json[:contact_email]).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contact details are visible to regular users" do
|
||||||
|
json = AboutSerializer.new(About.new(user), scope: Guardian.new(user), root: nil).as_json
|
||||||
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
||||||
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "login_required is disabled" do
|
||||||
|
before do
|
||||||
|
SiteSetting.login_required = false
|
||||||
|
SiteSetting.contact_url = "https://example.com/contact"
|
||||||
|
SiteSetting.contact_email = "example@foobar.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contact details are visible to anonymous users" do
|
||||||
|
json = AboutSerializer.new(About.new(nil), scope: Guardian.new(nil), root: nil).as_json
|
||||||
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
||||||
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "contact details are visible to regular users" do
|
||||||
|
json = AboutSerializer.new(About.new(user), scope: Guardian.new(user), root: nil).as_json
|
||||||
|
expect(json[:contact_url]).to eq(SiteSetting.contact_url)
|
||||||
|
expect(json[:contact_email]).to eq(SiteSetting.contact_email)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user