From 74da1f0fb3584437a163134f1e0edcbc41ff3867 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Wed, 16 Feb 2022 10:11:23 +0100 Subject: [PATCH] Remove "magic" Enabled function and use simple bool --- clientapi/routing/register.go | 4 ++-- clientapi/routing/routing.go | 2 +- cmd/create-account/main.go | 2 +- dendrite-config.yaml | 4 ++-- internal/httputil/httpapi.go | 2 +- setup/config/config_global.go | 9 ++++----- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/clientapi/routing/register.go b/clientapi/routing/register.go index 53f811088..496c05b39 100644 --- a/clientapi/routing/register.go +++ b/clientapi/routing/register.go @@ -699,7 +699,7 @@ func handleApplicationServiceRegistration( } policyVersion := "" - if cfg.Matrix.UserConsentOptions.Enabled() { + if cfg.Matrix.UserConsentOptions.Enabled { policyVersion = cfg.Matrix.UserConsentOptions.Version } @@ -725,7 +725,7 @@ func checkAndCompleteFlow( ) util.JSONResponse { if checkFlowCompleted(flow, cfg.Derived.Registration.Flows) { policyVersion := "" - if cfg.Matrix.UserConsentOptions.Enabled() { + if cfg.Matrix.UserConsentOptions.Enabled { policyVersion = cfg.Matrix.UserConsentOptions.Version } // This flow was completed, registration can continue diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index ea05604a8..6eae02a3d 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -118,7 +118,7 @@ func Setup( } // unspecced consent tracking - if cfg.Matrix.UserConsentOptions.Enabled() { + if cfg.Matrix.UserConsentOptions.Enabled { consentAPIMux.Handle("/consent", httputil.MakeHTMLAPI("consent", func(writer http.ResponseWriter, request *http.Request) *util.JSONResponse { return consent(writer, request, userAPI, cfg) diff --git a/cmd/create-account/main.go b/cmd/create-account/main.go index 9a79c50f2..d13ef31fa 100644 --- a/cmd/create-account/main.go +++ b/cmd/create-account/main.go @@ -82,7 +82,7 @@ func main() { } policyVersion := "" - if cfg.Global.UserConsentOptions.Enabled() { + if cfg.Global.UserConsentOptions.Enabled { policyVersion = cfg.Global.UserConsentOptions.Version } diff --git a/dendrite-config.yaml b/dendrite-config.yaml index f6671b452..250b76b5f 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -69,9 +69,9 @@ global: disable_federation: false # Consent tracking configuration - # If either require_at_registration or send_server_notice_to_guest are true, consent - # messages will be sent to the users. user_consent: + # If the user consent tracking is enabled or not + enabled: false # Randomly generated string to be used to calculate the HMAC form_secret: "superSecretRandomlyGeneratedSecret" # Require consent when user registers for the first time diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index 89b43b3a6..eaa3e349a 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -87,7 +87,7 @@ func MakeAuthAPI( } }() - if userConsentCfg.Enabled() && requireConsent { + if userConsentCfg.Enabled && requireConsent { consentError := checkConsent(req.Context(), device.UserID, userAPI, userConsentCfg) if consentError != nil { return util.JSONResponse{ diff --git a/setup/config/config_global.go b/setup/config/config_global.go index d5ad9333e..cada7bc9a 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -213,6 +213,8 @@ func (c *DNSCacheOptions) Verify(configErrs *ConfigErrors, isMonolith bool) { // If either require_at_registration or send_server_notice_to_guest are true, consent // messages will be sent to the users. type UserConsentOptions struct { + // If consent tracking is enabled or not + Enabled bool `yaml:"enabled"` // Randomly generated string to be used to calculate the HMAC FormSecret string `yaml:"form_secret"` // Require consent when user registers for the first time @@ -241,6 +243,7 @@ type UserConsentOptions struct { } func (c *UserConsentOptions) Defaults(baseURL string) { + c.Enabled = false c.RequireAtRegistration = false c.SendServerNoticeToGuest = false c.PolicyName = "Privacy Policy" @@ -250,7 +253,7 @@ func (c *UserConsentOptions) Defaults(baseURL string) { } func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool) { - if c.Enabled() { + if c.Enabled { checkNotEmpty(configErrors, "template_dir", c.TemplateDir) checkNotEmpty(configErrors, "version", c.Version) checkNotEmpty(configErrors, "policy_name", c.PolicyName) @@ -281,7 +284,3 @@ func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool) } } } - -func (c *UserConsentOptions) Enabled() bool { - return c.RequireAtRegistration || c.SendServerNoticeToGuest -}