Remove "magic" Enabled function and use simple bool

This commit is contained in:
Till Faelligen 2022-02-16 10:11:23 +01:00
parent 26accb8c5d
commit 74da1f0fb3
6 changed files with 11 additions and 12 deletions

View file

@ -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

View file

@ -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)

View file

@ -82,7 +82,7 @@ func main() {
}
policyVersion := ""
if cfg.Global.UserConsentOptions.Enabled() {
if cfg.Global.UserConsentOptions.Enabled {
policyVersion = cfg.Global.UserConsentOptions.Version
}

View file

@ -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

View file

@ -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{

View file

@ -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
}