From d9b92a7daad8a40230ade1d96a60a07233385d0b Mon Sep 17 00:00:00 2001 From: David Barroso Date: Thu, 16 Nov 2023 13:13:09 +0100 Subject: [PATCH] fix: added support for signupDisabled (#803) --- cmd/config/example.go | 3 +- cmd/config/validate_test.go | 5 +- dockercompose/auth_test.go | 1 + dockercompose/main_test.go | 3 +- go.mod | 2 +- go.sum | 2 + nix/overlay.nix | 5 +- .../be/services/mimir/model/cuegraph_gen.go | 71 ++++++++++++++++--- .../mimir/schema/appconfig/hasura_auth.go | 11 ++- .../nhost/be/services/mimir/schema/schema.cue | 5 +- .../services/mimir/schema/schema_gen.graphqls | 9 ++- vendor/modules.txt | 2 +- 12 files changed, 99 insertions(+), 20 deletions(-) diff --git a/cmd/config/example.go b/cmd/config/example.go index ac882e5e6..55f1774ff 100644 --- a/cmd/config/example.go +++ b/cmd/config/example.go @@ -105,7 +105,8 @@ func commandExample(cCtx *cli.Context) error { //nolint:funlen,maintidx }, }, SignUp: &model.ConfigAuthSignUp{ - Enabled: ptr(true), + Enabled: ptr(true), + DisableNewUsers: ptr(false), }, User: &model.ConfigAuthUser{ Roles: &model.ConfigAuthUserRoles{ diff --git a/cmd/config/validate_test.go b/cmd/config/validate_test.go index 5cc72417e..362dc36c3 100644 --- a/cmd/config/validate_test.go +++ b/cmd/config/validate_test.go @@ -58,7 +58,10 @@ func expectedConfig() *model.ConfigConfig { ClientUrl: ptr("http://localhost:3000"), AllowedUrls: []string{}, }, - SignUp: &model.ConfigAuthSignUp{Enabled: ptr(true)}, + SignUp: &model.ConfigAuthSignUp{ + Enabled: ptr(true), + DisableNewUsers: ptr(false), + }, User: &model.ConfigAuthUser{ Roles: &model.ConfigAuthUserRoles{ Default: ptr("user"), diff --git a/dockercompose/auth_test.go b/dockercompose/auth_test.go index 5eafc17ee..e28e5d888 100644 --- a/dockercompose/auth_test.go +++ b/dockercompose/auth_test.go @@ -28,6 +28,7 @@ func expectedAuth() *Service { "AUTH_API_PREFIX": "/v1", "AUTH_CLIENT_URL": "http://localhost:3000", "AUTH_DISABLE_NEW_USERS": "false", + "AUTH_DISABLE_SIGNUP": "false", "AUTH_EMAIL_PASSWORDLESS_ENABLED": "true", "AUTH_EMAIL_SIGNIN_EMAIL_VERIFIED_REQUIRED": "true", "AUTH_GRAVATAR_DEFAULT": "gravatarDefault", diff --git a/dockercompose/main_test.go b/dockercompose/main_test.go index d9740acd4..9fc53f5ac 100644 --- a/dockercompose/main_test.go +++ b/dockercompose/main_test.go @@ -153,7 +153,8 @@ func getConfig() *model.ConfigConfig { //nolint:maintidx }, }, SignUp: &model.ConfigAuthSignUp{ - Enabled: ptr(true), + Enabled: ptr(true), + DisableNewUsers: ptr(false), }, Totp: &model.ConfigAuthTotp{ Enabled: ptr(true), diff --git a/go.mod b/go.mod index f6da4df5e..9a2e3b6da 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/go-git/go-git/v5 v5.9.0 github.com/google/go-cmp v0.6.0 github.com/hashicorp/go-getter v1.7.3 - github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2 + github.com/nhost/be v0.0.0-20231115145121-4df40f281955 github.com/pelletier/go-toml/v2 v2.1.0 github.com/urfave/cli/v2 v2.25.7 github.com/wI2L/jsondiff v0.4.0 diff --git a/go.sum b/go.sum index 0459c587e..8d9abb296 100644 --- a/go.sum +++ b/go.sum @@ -446,6 +446,8 @@ github.com/nhost/be v0.0.0-20231107143741-114c8c189274 h1:53zsrfBgz1EjWIz04btAbO github.com/nhost/be v0.0.0-20231107143741-114c8c189274/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg= github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2 h1:KhTGs5SUCi7zWYAS9Dag2POf6ok6rWUCW+On8KakoME= github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg= +github.com/nhost/be v0.0.0-20231115145121-4df40f281955 h1:2IW0EEbAnz6QoOa4SztmAAImZqOZW6zpstSznyaenU4= +github.com/nhost/be v0.0.0-20231115145121-4df40f281955/go.mod h1:wYw8iVi1dZG6IAK0eCSOFAWHAISTa+9sjGA6Vx/x1Sg= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= diff --git a/nix/overlay.nix b/nix/overlay.nix index 7488a4de7..34b49a57a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -2,13 +2,12 @@ go = prev.go_1_21.overrideAttrs (finalAttrs: previousAttrs: rec { - version = "1.21.3"; + version = "1.21.4"; src = final.fetchurl { url = "https://go.dev/dl/go${version}.src.tar.gz"; - sha256 = "sha256-GG8rb4yLcE5paCGwmrIEGlwe4T3LwxVqE63PdZMe5Ig="; + sha256 = "sha256-R7Jqg9K2WjwcG8rOJztpvuSaentRaKdgTe09JqN714c="; }; - }); buildGoModule = prev.buildGoModule.override { go = go; }; diff --git a/vendor/github.com/nhost/be/services/mimir/model/cuegraph_gen.go b/vendor/github.com/nhost/be/services/mimir/model/cuegraph_gen.go index 2740c4ad0..f10d76df7 100644 --- a/vendor/github.com/nhost/be/services/mimir/model/cuegraph_gen.go +++ b/vendor/github.com/nhost/be/services/mimir/model/cuegraph_gen.go @@ -5427,8 +5427,10 @@ func (exp *ConfigAuthSessionRefreshTokenComparisonExp) Matches(o *ConfigAuthSess } type ConfigAuthSignUp struct { - // Inverse of AUTH_DISABLE_NEW_USERS + // Inverse of AUTH_DISABLE_SIGNUP Enabled *bool `json:"enabled" toml:"enabled"` + // AUTH_DISABLE_NEW_USERS + DisableNewUsers *bool `json:"disableNewUsers" toml:"disableNewUsers"` } func (o *ConfigAuthSignUp) MarshalJSON() ([]byte, error) { @@ -5436,6 +5438,9 @@ func (o *ConfigAuthSignUp) MarshalJSON() ([]byte, error) { if o.Enabled != nil { m["enabled"] = o.Enabled } + if o.DisableNewUsers != nil { + m["disableNewUsers"] = o.DisableNewUsers + } return json.Marshal(m) } @@ -5446,9 +5451,18 @@ func (o *ConfigAuthSignUp) GetEnabled() *bool { return o.Enabled } +func (o *ConfigAuthSignUp) GetDisableNewUsers() *bool { + if o == nil { + o = &ConfigAuthSignUp{} + } + return o.DisableNewUsers +} + type ConfigAuthSignUpUpdateInput struct { - Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"` - IsSetEnabled bool `json:"-"` + Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"` + IsSetEnabled bool `json:"-"` + DisableNewUsers *bool `json:"disableNewUsers,omitempty" toml:"disableNewUsers,omitempty"` + IsSetDisableNewUsers bool `json:"-"` } func (o *ConfigAuthSignUpUpdateInput) UnmarshalGQL(v interface{}) error { @@ -5473,6 +5487,23 @@ func (o *ConfigAuthSignUpUpdateInput) UnmarshalGQL(v interface{}) error { } o.IsSetEnabled = true } + if v, ok := m["disableNewUsers"]; ok { + if v == nil { + o.DisableNewUsers = nil + } else { + // clearly a not very efficient shortcut + b, err := json.Marshal(v) + if err != nil { + return err + } + var x bool + if err := json.Unmarshal(b, &x); err != nil { + return err + } + o.DisableNewUsers = &x + } + o.IsSetDisableNewUsers = true + } return nil } @@ -5491,6 +5522,13 @@ func (o *ConfigAuthSignUpUpdateInput) GetEnabled() *bool { return o.Enabled } +func (o *ConfigAuthSignUpUpdateInput) GetDisableNewUsers() *bool { + if o == nil { + o = &ConfigAuthSignUpUpdateInput{} + } + return o.DisableNewUsers +} + func (s *ConfigAuthSignUp) Update(v *ConfigAuthSignUpUpdateInput) { if v == nil { return @@ -5498,10 +5536,14 @@ func (s *ConfigAuthSignUp) Update(v *ConfigAuthSignUpUpdateInput) { if v.IsSetEnabled || v.Enabled != nil { s.Enabled = v.Enabled } + if v.IsSetDisableNewUsers || v.DisableNewUsers != nil { + s.DisableNewUsers = v.DisableNewUsers + } } type ConfigAuthSignUpInsertInput struct { - Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"` + Enabled *bool `json:"enabled,omitempty" toml:"enabled,omitempty"` + DisableNewUsers *bool `json:"disableNewUsers,omitempty" toml:"disableNewUsers,omitempty"` } func (o *ConfigAuthSignUpInsertInput) GetEnabled() *bool { @@ -5511,8 +5553,16 @@ func (o *ConfigAuthSignUpInsertInput) GetEnabled() *bool { return o.Enabled } +func (o *ConfigAuthSignUpInsertInput) GetDisableNewUsers() *bool { + if o == nil { + o = &ConfigAuthSignUpInsertInput{} + } + return o.DisableNewUsers +} + func (s *ConfigAuthSignUp) Insert(v *ConfigAuthSignUpInsertInput) { s.Enabled = v.Enabled + s.DisableNewUsers = v.DisableNewUsers } func (s *ConfigAuthSignUp) Clone() *ConfigAuthSignUp { @@ -5522,14 +5572,16 @@ func (s *ConfigAuthSignUp) Clone() *ConfigAuthSignUp { v := &ConfigAuthSignUp{} v.Enabled = s.Enabled + v.DisableNewUsers = s.DisableNewUsers return v } type ConfigAuthSignUpComparisonExp struct { - And []*ConfigAuthSignUpComparisonExp `json:"_and,omitempty"` - Not *ConfigAuthSignUpComparisonExp `json:"_not,omitempty"` - Or []*ConfigAuthSignUpComparisonExp `json:"_or,omitempty"` - Enabled *ConfigBooleanComparisonExp `json:"enabled,omitempty"` + And []*ConfigAuthSignUpComparisonExp `json:"_and,omitempty"` + Not *ConfigAuthSignUpComparisonExp `json:"_not,omitempty"` + Or []*ConfigAuthSignUpComparisonExp `json:"_or,omitempty"` + Enabled *ConfigBooleanComparisonExp `json:"enabled,omitempty"` + DisableNewUsers *ConfigBooleanComparisonExp `json:"disableNewUsers,omitempty"` } func (exp *ConfigAuthSignUpComparisonExp) Matches(o *ConfigAuthSignUp) bool { @@ -5543,6 +5595,9 @@ func (exp *ConfigAuthSignUpComparisonExp) Matches(o *ConfigAuthSignUp) bool { if o.Enabled != nil && !exp.Enabled.Matches(*o.Enabled) { return false } + if o.DisableNewUsers != nil && !exp.DisableNewUsers.Matches(*o.DisableNewUsers) { + return false + } if exp.And != nil && !all(exp.And, o) { return false diff --git a/vendor/github.com/nhost/be/services/mimir/schema/appconfig/hasura_auth.go b/vendor/github.com/nhost/be/services/mimir/schema/appconfig/hasura_auth.go index 50b326a01..5988f2088 100644 --- a/vendor/github.com/nhost/be/services/mimir/schema/appconfig/hasura_auth.go +++ b/vendor/github.com/nhost/be/services/mimir/schema/appconfig/hasura_auth.go @@ -224,8 +224,15 @@ func HasuraAuthEnv( //nolint:funlen,cyclop,maintidx ), }, { - Name: "AUTH_DISABLE_NEW_USERS", - Value: Stringify(!*config.GetAuth().GetSignUp().GetEnabled()), + Name: "AUTH_DISABLE_SIGNUP", + Value: Stringify(!unptr(config.GetAuth().GetSignUp().GetEnabled())), + }, + { + Name: "AUTH_DISABLE_NEW_USERS", + Value: Stringify( + !unptr(config.GetAuth().GetSignUp().GetEnabled()) || + unptr(config.GetAuth().GetSignUp().GetDisableNewUsers()), + ), }, } diff --git a/vendor/github.com/nhost/be/services/mimir/schema/schema.cue b/vendor/github.com/nhost/be/services/mimir/schema/schema.cue index f01f8342e..e7d568ab9 100644 --- a/vendor/github.com/nhost/be/services/mimir/schema/schema.cue +++ b/vendor/github.com/nhost/be/services/mimir/schema/schema.cue @@ -249,8 +249,11 @@ import ( } signUp: { - // Inverse of AUTH_DISABLE_NEW_USERS + // Inverse of AUTH_DISABLE_SIGNUP enabled: bool | *true + + // AUTH_DISABLE_NEW_USERS + disableNewUsers: bool | *false } user: { diff --git a/vendor/github.com/nhost/be/services/mimir/schema/schema_gen.graphqls b/vendor/github.com/nhost/be/services/mimir/schema/schema_gen.graphqls index f060fbb93..8449b716c 100644 --- a/vendor/github.com/nhost/be/services/mimir/schema/schema_gen.graphqls +++ b/vendor/github.com/nhost/be/services/mimir/schema/schema_gen.graphqls @@ -908,17 +908,23 @@ input ConfigAuthSessionRefreshTokenComparisonExp { """ type ConfigAuthSignUp { """ - Inverse of AUTH_DISABLE_NEW_USERS + Inverse of AUTH_DISABLE_SIGNUP """ enabled: Boolean + """ + AUTH_DISABLE_NEW_USERS + """ + disableNewUsers: Boolean } input ConfigAuthSignUpUpdateInput { enabled: Boolean + disableNewUsers: Boolean } input ConfigAuthSignUpInsertInput { enabled: Boolean + disableNewUsers: Boolean } input ConfigAuthSignUpComparisonExp { @@ -926,6 +932,7 @@ input ConfigAuthSignUpComparisonExp { _not: ConfigAuthSignUpComparisonExp _or: [ConfigAuthSignUpComparisonExp!] enabled: ConfigBooleanComparisonExp + disableNewUsers: ConfigBooleanComparisonExp } """ diff --git a/vendor/modules.txt b/vendor/modules.txt index a6deec296..769c518b7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -397,7 +397,7 @@ github.com/muesli/reflow/wrap # github.com/muesli/termenv v0.15.2 ## explicit; go 1.17 github.com/muesli/termenv -# github.com/nhost/be v0.0.0-20231107151453-7e54cb68abc2 +# github.com/nhost/be v0.0.0-20231115145121-4df40f281955 ## explicit; go 1.21 github.com/nhost/be/services/mimir/model github.com/nhost/be/services/mimir/schema