|
@@ -24,7 +24,7 @@ const (
|
24
|
24
|
// 'version' of the database schema
|
25
|
25
|
keySchemaVersion = "db.version"
|
26
|
26
|
// latest schema of the db
|
27
|
|
- latestDbSchema = 17
|
|
27
|
+ latestDbSchema = 18
|
28
|
28
|
|
29
|
29
|
keyCloakSecret = "crypto.cloak_secret"
|
30
|
30
|
)
|
|
@@ -854,6 +854,55 @@ func schemaChangeV16ToV17(config *Config, tx *buntdb.Tx) error {
|
854
|
854
|
return nil
|
855
|
855
|
}
|
856
|
856
|
|
|
857
|
+// #1274: we used to suspend accounts by deleting their "verified" key,
|
|
858
|
+// now we save some metadata under a new key
|
|
859
|
+func schemaChangeV17ToV18(config *Config, tx *buntdb.Tx) error {
|
|
860
|
+ now := time.Now().UTC()
|
|
861
|
+
|
|
862
|
+ exists := "account.exists "
|
|
863
|
+ suspended := "account.suspended "
|
|
864
|
+ verif := "account.verified "
|
|
865
|
+ verifCode := "account.verificationcode "
|
|
866
|
+
|
|
867
|
+ var accounts []string
|
|
868
|
+
|
|
869
|
+ tx.AscendGreaterOrEqual("", exists, func(key, value string) bool {
|
|
870
|
+ if !strings.HasPrefix(key, exists) {
|
|
871
|
+ return false
|
|
872
|
+ }
|
|
873
|
+ account := strings.TrimPrefix(key, exists)
|
|
874
|
+ _, verifiedErr := tx.Get(verif + account)
|
|
875
|
+ _, verifCodeErr := tx.Get(verifCode + account)
|
|
876
|
+ if verifiedErr != nil && verifCodeErr != nil {
|
|
877
|
+ // verified key not present, but there's no code either,
|
|
878
|
+ // this is a suspension
|
|
879
|
+ accounts = append(accounts, account)
|
|
880
|
+ }
|
|
881
|
+ return true
|
|
882
|
+ })
|
|
883
|
+
|
|
884
|
+ type accountSuspensionV18 struct {
|
|
885
|
+ TimeCreated time.Time
|
|
886
|
+ Duration time.Duration
|
|
887
|
+ OperName string
|
|
888
|
+ Reason string
|
|
889
|
+ }
|
|
890
|
+
|
|
891
|
+ for _, account := range accounts {
|
|
892
|
+ var sus accountSuspensionV18
|
|
893
|
+ sus.TimeCreated = now
|
|
894
|
+ sus.OperName = "*"
|
|
895
|
+ sus.Reason = "[unknown]"
|
|
896
|
+ susBytes, err := json.Marshal(sus)
|
|
897
|
+ if err != nil {
|
|
898
|
+ return err
|
|
899
|
+ }
|
|
900
|
+ tx.Set(suspended+account, string(susBytes), nil)
|
|
901
|
+ }
|
|
902
|
+
|
|
903
|
+ return nil
|
|
904
|
+}
|
|
905
|
+
|
857
|
906
|
func getSchemaChange(initialVersion int) (result SchemaChange, ok bool) {
|
858
|
907
|
for _, change := range allChanges {
|
859
|
908
|
if initialVersion == change.InitialVersion {
|
|
@@ -944,4 +993,9 @@ var allChanges = []SchemaChange{
|
944
|
993
|
TargetVersion: 17,
|
945
|
994
|
Changer: schemaChangeV16ToV17,
|
946
|
995
|
},
|
|
996
|
+ {
|
|
997
|
+ InitialVersion: 17,
|
|
998
|
+ TargetVersion: 18,
|
|
999
|
+ Changer: schemaChangeV17ToV18,
|
|
1000
|
+ },
|
947
|
1001
|
}
|