diff --git a/application.yaml b/application.yaml index 4a437312..7ca1247a 100644 --- a/application.yaml +++ b/application.yaml @@ -99,6 +99,7 @@ auth/email-link: appName: Tenant teamName: Tenant users: &users + defaultReferralName: bogus kyc: kyc-step1-reset-url: https://localhost:443/v1w/face-auth/ disableConsumer: false diff --git a/users/DDL.sql b/users/DDL.sql index 030fe68d..59346a8a 100644 --- a/users/DDL.sql +++ b/users/DDL.sql @@ -48,7 +48,7 @@ ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_step_blocked smallint NOT NULL DE ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_steps_last_updated_at timestamp[]; ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_steps_created_at timestamp[]; INSERT INTO users (created_at,updated_at,phone_number,phone_number_hash,email,id,username,profile_picture_name,referred_by,city,country,mining_blockchain_account_address,blockchain_account_address, lookup) - VALUES (current_timestamp,current_timestamp,'bogus','bogus','bogus','bogus','bogus','bogus.jpg','bogus','bogus','RO','bogus','bogus',to_tsvector('bogus')), + VALUES (current_timestamp,current_timestamp,'%[1]v','%[1]v','%[1]v','%[1]v','%[1]v','%[1]v.jpg','%[1]v','%[1]v','RO','%[1]v','%[1]v',to_tsvector('%[1]v')), (current_timestamp,current_timestamp,'icenetwork','icenetwork','icenetwork','icenetwork','icenetwork','icenetwork.jpg','icenetwork','icenetwork','RO','icenetwork','icenetwork',to_tsvector('icenetwork')) ON CONFLICT DO NOTHING; CREATE INDEX IF NOT EXISTS users_referred_by_ix ON users (referred_by); diff --git a/users/contract.go b/users/contract.go index 4e29f6c8..3b094352 100644 --- a/users/contract.go +++ b/users/contract.go @@ -293,6 +293,7 @@ type ( } // | config holds the configuration of this package mounted from `application.yaml`. config struct { + DefaultReferralName string `yaml:"defaultReferralName"` messagebroker.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope. GlobalAggregationInterval struct { MinMiningSessionDuration stdlibtime.Duration `yaml:"minMiningSessionDuration"` diff --git a/users/users.go b/users/users.go index 6a3cbe63..77887310 100644 --- a/users/users.go +++ b/users/users.go @@ -31,7 +31,8 @@ func New(ctx context.Context, _ context.CancelFunc) Repository { var cfg config appcfg.MustLoadFromKey(applicationYamlKey, &cfg) - db := storage.MustConnect(ctx, ddl, applicationYamlKey) + ddlWithParams := fmt.Sprintf(ddl, cfg.DefaultReferralName) + db := storage.MustConnect(ctx, ddlWithParams, applicationYamlKey) return &repository{ cfg: &cfg, @@ -47,7 +48,8 @@ func StartProcessor(ctx context.Context, cancel context.CancelFunc) Processor { appcfg.MustLoadFromKey(applicationYamlKey, &cfg) var mbConsumer messagebroker.Client - db := storage.MustConnect(ctx, ddl, applicationYamlKey) + ddlWithParams := fmt.Sprintf(ddl, cfg.DefaultReferralName) + db := storage.MustConnect(ctx, ddlWithParams, applicationYamlKey) mbProducer := messagebroker.MustConnect(ctx, applicationYamlKey) prc := &processor{repository: &repository{ cfg: &cfg, diff --git a/users/users_delete.go b/users/users_delete.go index f689ca30..a68d9bbf 100644 --- a/users/users_delete.go +++ b/users/users_delete.go @@ -4,6 +4,7 @@ package users import ( "context" + "fmt" "sync" "github.com/hashicorp/go-multierror" @@ -93,10 +94,10 @@ func (r *repository) updateReferredByForAllT1Referrals(ctx context.Context, user if ctx.Err() != nil { return errors.Wrap(ctx.Err(), "context failed") } - sql := ` + sql := fmt.Sprintf(` WITH randomized AS ( SELECT id, referred_by, created_at, hash_code FROM users - WHERE id != 'bogus' + WHERE id != '%[1]v' AND id != 'icenetwork' AND username != id AND referred_by != id @@ -125,7 +126,7 @@ func (r *repository) updateReferredByForAllT1Referrals(ctx context.Context, user u.ID as id FROM users u WHERE u.referred_by = $1 - AND u.id != $1` + AND u.id != $1`, r.cfg.DefaultReferralName) type resp struct { NewReferredBy UserID ID UserID `db:"id"`