[#5741] use random string as id for non-system collections and fields

This commit is contained in:
Gani Georgiev
2024-10-29 20:08:16 +02:00
parent 658f0c4177
commit 5a94ec9918
9 changed files with 236 additions and 150 deletions
+7 -2
View File
@@ -660,8 +660,13 @@ func onCollectionDeleteExecute(e *CollectionEvent) error {
// -------------------------------------------------------------------
func (c *Collection) initDefaultId() {
if c.Id == "" && c.Name != "" {
c.Id = "_pbc_" + crc32Checksum(c.Name)
if c.Id == "" {
if c.System && c.Name != "" {
// for system collections we use crc32 checksum for consistency because they cannot be renamed
c.Id = "_pbc_" + crc32Checksum(c.Name)
} else {
c.Id = "_pbc_" + security.RandomStringWithAlphabet(10, DefaultIdAlphabet)
}
}
}
+88 -63
View File
@@ -26,7 +26,7 @@ func TestNewCollection(t *testing.T) {
"",
"",
[]string{
`"id":""`,
`"id":"_pbc_`,
`"name":""`,
`"type":"base"`,
`"system":false`,
@@ -45,7 +45,7 @@ func TestNewCollection(t *testing.T) {
"unknown",
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"base"`,
`"system":false`,
@@ -64,7 +64,7 @@ func TestNewCollection(t *testing.T) {
"base",
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"base"`,
`"system":false`,
@@ -83,7 +83,7 @@ func TestNewCollection(t *testing.T) {
"view",
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"view"`,
`"indexes":[]`,
@@ -100,7 +100,7 @@ func TestNewCollection(t *testing.T) {
"auth",
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"auth"`,
`"fields":[{`,
@@ -148,7 +148,7 @@ func TestNewBaseCollection(t *testing.T) {
{
"",
[]string{
`"id":""`,
`"id":"_pbc_`,
`"name":""`,
`"type":"base"`,
`"system":false`,
@@ -166,7 +166,7 @@ func TestNewBaseCollection(t *testing.T) {
{
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"base"`,
`"system":false`,
@@ -206,7 +206,7 @@ func TestNewViewCollection(t *testing.T) {
{
"",
[]string{
`"id":""`,
`"id":"_pbc_`,
`"name":""`,
`"type":"view"`,
`"indexes":[]`,
@@ -222,7 +222,7 @@ func TestNewViewCollection(t *testing.T) {
{
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"view"`,
`"indexes":[]`,
@@ -286,7 +286,7 @@ func TestNewAuthCollection(t *testing.T) {
{
"test",
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"auth"`,
`"fields":[{`,
@@ -498,10 +498,11 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
defer app.Cleanup()
scenarios := []struct {
name string
raw string
collection func() *core.Collection
expectedCollection func() *core.Collection
name string
raw string
collection func() *core.Collection
expected []string
notExpected []string
}{
{
"base new empty",
@@ -509,12 +510,18 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
func() *core.Collection {
return &core.Collection{}
},
func() *core.Collection {
c := core.NewBaseCollection("test")
c.ListRule = types.Pointer("1=2")
c.AuthRule = types.Pointer("1=3")
c.ViewQuery = "abc"
return c
[]string{
`"type":"base"`,
`"id":"_pbc_`,
`"name":"test"`,
`"listRule":"1=2"`,
`"fields":[`,
`"name":"id"`,
`"indexes":[]`,
},
[]string{
`"authRule":"1=3"`,
`"viewQuery":"abc"`,
},
},
{
@@ -523,12 +530,17 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
func() *core.Collection {
return &core.Collection{}
},
func() *core.Collection {
c := core.NewViewCollection("test")
c.ListRule = types.Pointer("1=2")
c.AuthRule = types.Pointer("1=3")
c.ViewQuery = "abc"
return c
[]string{
`"type":"view"`,
`"id":"_pbc_`,
`"name":"test"`,
`"listRule":"1=2"`,
`"fields":[]`,
`"viewQuery":"abc"`,
`"indexes":[]`,
},
[]string{
`"authRule":"1=3"`,
},
},
{
@@ -537,12 +549,18 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
func() *core.Collection {
return &core.Collection{}
},
func() *core.Collection {
c := core.NewAuthCollection("test")
c.ListRule = types.Pointer("1=2")
c.AuthRule = types.Pointer("1=3")
c.ViewQuery = "abc"
return c
[]string{
`"type":"auth"`,
`"id":"_pbc_`,
`"name":"test"`,
`"listRule":"1=2"`,
`"authRule":"1=3"`,
`"fields":[`,
`"name":"id"`,
},
[]string{
`"indexes":[]`,
`"viewQuery":"abc"`,
},
},
{
@@ -553,14 +571,16 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
c.Type = core.CollectionTypeBase
return c
},
func() *core.Collection {
c := &core.Collection{}
c.Type = core.CollectionTypeBase
c.Name = "test"
c.ListRule = types.Pointer("1=2")
c.AuthRule = types.Pointer("1=3")
c.ViewQuery = "abc"
return c
[]string{
`"type":"base"`,
`"id":""`,
`"name":"test"`,
`"listRule":"1=2"`,
`"fields":[]`,
},
[]string{
`"authRule":"1=3"`,
`"viewQuery":"abc"`,
},
},
{
@@ -570,14 +590,17 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
c, _ := app.FindCollectionByNameOrId("demo1")
return c
},
func() *core.Collection {
c, _ := app.FindCollectionByNameOrId("demo1")
c.Type = core.CollectionTypeAuth
c.Name = "test"
c.ListRule = types.Pointer("1=2")
c.AuthRule = types.Pointer("1=3")
c.ViewQuery = "abc"
return c
[]string{
`"type":"auth"`,
`"name":"test"`,
`"listRule":"1=2"`,
`"authRule":"1=3"`,
`"fields":[`,
`"name":"id"`,
},
[]string{
`"name":"tokenKey"`,
`"viewQuery":"abc"`,
},
},
}
@@ -597,14 +620,16 @@ func TestCollectionUnmarshalJSON(t *testing.T) {
}
rawResultStr := string(rawResult)
rawExpected, err := json.Marshal(s.expectedCollection())
if err != nil {
t.Fatal(err)
for _, part := range s.expected {
if !strings.Contains(rawResultStr, part) {
t.Fatalf("Missing expected %q in\n%v", part, rawResultStr)
}
}
rawExpectedStr := string(rawExpected)
if rawResultStr != rawExpectedStr {
t.Fatalf("Expected collection\n%s\ngot\n%s", rawExpectedStr, rawResultStr)
for _, part := range s.notExpected {
if strings.Contains(rawResultStr, part) {
t.Fatalf("Didn't expected %q in\n%v", part, rawResultStr)
}
}
})
}
@@ -630,7 +655,7 @@ func TestCollectionSerialize(t *testing.T) {
return c
},
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"base"`,
},
@@ -658,7 +683,7 @@ func TestCollectionSerialize(t *testing.T) {
return c
},
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"view"`,
`"viewQuery":"1=1"`,
@@ -686,7 +711,7 @@ func TestCollectionSerialize(t *testing.T) {
return c
},
[]string{
`"id":"_pbc_3632233996"`,
`"id":"_pbc_`,
`"name":"test"`,
`"type":"auth"`,
`"oauth2":{`,
@@ -748,19 +773,19 @@ func TestCollectionDBExport(t *testing.T) {
}{
{
"unknown",
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"bool597745380","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"bool3131674462","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":"{}","system":true,"type":"unknown","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"f1_id","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"f2_id","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":"{}","system":true,"type":"unknown","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
},
{
core.CollectionTypeBase,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"bool597745380","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"bool3131674462","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":"{}","system":true,"type":"base","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"f1_id","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"f2_id","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":"{}","system":true,"type":"base","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
},
{
core.CollectionTypeView,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"bool597745380","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"bool3131674462","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":{"viewQuery":"select 1"},"system":true,"type":"view","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"f1_id","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"f2_id","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":{"viewQuery":"select 1"},"system":true,"type":"view","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
},
{
core.CollectionTypeAuth,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"bool597745380","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"bool3131674462","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":{"authRule":null,"manageRule":"1=6","authAlert":{"enabled":false,"emailTemplate":{"subject":"","body":""}},"oauth2":{"providers":null,"mappedFields":{"id":"","name":"","username":"","avatarURL":""},"enabled":false},"passwordAuth":{"enabled":false,"identityFields":null},"mfa":{"enabled":false,"duration":0,"rule":""},"otp":{"enabled":false,"duration":0,"length":0,"emailTemplate":{"subject":"","body":""}},"authToken":{"duration":0},"passwordResetToken":{"duration":0},"emailChangeToken":{"duration":0},"verificationToken":{"duration":0},"fileToken":{"duration":0},"verificationTemplate":{"subject":"","body":""},"resetPasswordTemplate":{"subject":"","body":""},"confirmEmailChangeTemplate":{"subject":"","body":""}},"system":true,"type":"auth","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
`{"createRule":"1=3","created":"2024-07-01 01:02:03.456Z","deleteRule":"1=5","fields":[{"hidden":false,"id":"f1_id","name":"f1","presentable":false,"required":false,"system":true,"type":"bool"},{"hidden":false,"id":"f2_id","name":"f2","presentable":false,"required":true,"system":false,"type":"bool"}],"id":"test_id","indexes":["CREATE INDEX idx1 on test_name(id)","CREATE INDEX idx2 on test_name(id)"],"listRule":"1=1","name":"test_name","options":{"authRule":null,"manageRule":"1=6","authAlert":{"enabled":false,"emailTemplate":{"subject":"","body":""}},"oauth2":{"providers":null,"mappedFields":{"id":"","name":"","username":"","avatarURL":""},"enabled":false},"passwordAuth":{"enabled":false,"identityFields":null},"mfa":{"enabled":false,"duration":0,"rule":""},"otp":{"enabled":false,"duration":0,"length":0,"emailTemplate":{"subject":"","body":""}},"authToken":{"duration":0},"passwordResetToken":{"duration":0},"emailChangeToken":{"duration":0},"verificationToken":{"duration":0},"fileToken":{"duration":0},"verificationTemplate":{"subject":"","body":""},"resetPasswordTemplate":{"subject":"","body":""},"confirmEmailChangeTemplate":{"subject":"","body":""}},"system":true,"type":"auth","updateRule":"1=4","updated":"2024-07-01 01:02:03.456Z","viewRule":"1=7"}`,
},
}
@@ -782,8 +807,8 @@ func TestCollectionDBExport(t *testing.T) {
c.Updated = date
c.Indexes = types.JSONArray[string]{"CREATE INDEX idx1 on test_name(id)", "CREATE INDEX idx2 on test_name(id)"}
c.ViewQuery = "select 1"
c.Fields.Add(&core.BoolField{Name: "f1", System: true})
c.Fields.Add(&core.BoolField{Name: "f2", Required: true})
c.Fields.Add(&core.BoolField{Id: "f1_id", Name: "f1", System: true})
c.Fields.Add(&core.BoolField{Id: "f2_id", Name: "f2", Required: true})
c.RawOptions = types.JSONRaw(`{"viewQuery": "select 2"}`) // should be ignored
result, err := c.DBExport(app)
+4
View File
@@ -416,6 +416,10 @@ func (validator *collectionValidator) ensureNoSystemFieldsChange(value any) erro
return validators.ErrUnsupportedValueType
}
if validator.original.IsNew() {
return nil // not an update
}
for _, oldField := range validator.original.Fields {
if !oldField.GetSystem() {
continue
+29 -15
View File
@@ -108,13 +108,13 @@ func (l *FieldsList) RemoveByName(fieldName string) {
// Add adds one or more fields to the current list.
//
// If any of the new fields doesn't have an id it will try to set a
// default one based on its type and name.
// By default this method will try to REPLACE existing fields with
// the new ones by their id or by their name if the new field doesn't have an explicit id.
//
// If the list already has a field with the same id,
// then the existing field is replaced with the new one.
// If no matching existing field is found, it will APPEND the field to the end of the list.
//
// Otherwise the new field is appended after the other list fields.
// In all cases, if any of the new fields don't have an explicit id it will auto generate a default one for them
// (the id value doesn't really matter and it is mostly used as a stable identifier in case of a field rename).
func (l *FieldsList) Add(fields ...Field) {
for _, f := range fields {
l.add(f)
@@ -124,7 +124,9 @@ func (l *FieldsList) Add(fields ...Field) {
// AddMarshaledJSON parses the provided raw json data and adds the
// found fields into the current list (following the same rule as the Add method).
//
// rawJSON could be either a serialized array of field objects or a single field object.
// The rawJSON argument could be one of:
// - serialized array of field objects
// - single field object.
//
// Example:
//
@@ -160,29 +162,41 @@ func (l *FieldsList) AddMarshaledJSON(rawJSON []byte) error {
}
func (l *FieldsList) add(newField Field) {
fields := *l
var replaceByName bool
newFieldId := newField.GetId()
// set default id
if newFieldId == "" {
if newField.GetName() != "" {
replaceByName = true
if newField.GetSystem() && newField.GetName() != "" {
// for system fields we use crc32 checksum for consistency because they cannot be renamed
newFieldId = newField.Type() + crc32Checksum(newField.GetName())
} else {
newFieldId = newField.Type() + security.RandomString(5)
newFieldId = newField.Type() + security.RandomString(7)
}
newField.SetId(newFieldId)
}
fields := *l
// replace existing
for i, field := range fields {
// replace existing
if newFieldId != "" && field.GetId() == newFieldId {
(*l)[i] = newField
return
if replaceByName {
if name := newField.GetName(); name != "" && field.GetName() == name {
newField.SetId(field.GetId())
(*l)[i] = newField
return
}
} else {
if field.GetId() == newFieldId {
(*l)[i] = newField
return
}
}
}
// add new field
newField.SetId(newFieldId)
*l = append(fields, newField)
}
+17 -12
View File
@@ -414,6 +414,8 @@ func TestRecordMergeExpand(t *testing.T) {
t.Parallel()
collection := core.NewBaseCollection("test")
collection.Id = "_pbc_123"
m := core.NewRecord(collection)
m.Id = "m"
@@ -497,7 +499,7 @@ func TestRecordMergeExpand(t *testing.T) {
}
rawStr := string(raw)
expected := `{"a":{"collectionId":"_pbc_3632233996","collectionName":"test","expand":{"a1":{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a1"},"a23":[{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a2"},{"collectionId":"_pbc_3632233996","collectionName":"test","expand":{"a31":{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a31"},"a32":[{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a32"},{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a32New"}],"a33New":{"collectionId":"_pbc_3632233996","collectionName":"test","id":"a33New"}},"id":"a3"}]},"id":"a"},"b":[{"collectionId":"_pbc_3632233996","collectionName":"test","expand":{"b1":{"collectionId":"_pbc_3632233996","collectionName":"test","id":"b1"}},"id":"b"},{"collectionId":"_pbc_3632233996","collectionName":"test","id":"bNew"}],"c":[{"collectionId":"_pbc_3632233996","collectionName":"test","id":"c"}],"dNew":{"collectionId":"_pbc_3632233996","collectionName":"test","id":"dNew"}}`
expected := `{"a":{"collectionId":"_pbc_123","collectionName":"test","expand":{"a1":{"collectionId":"_pbc_123","collectionName":"test","id":"a1"},"a23":[{"collectionId":"_pbc_123","collectionName":"test","id":"a2"},{"collectionId":"_pbc_123","collectionName":"test","expand":{"a31":{"collectionId":"_pbc_123","collectionName":"test","id":"a31"},"a32":[{"collectionId":"_pbc_123","collectionName":"test","id":"a32"},{"collectionId":"_pbc_123","collectionName":"test","id":"a32New"}],"a33New":{"collectionId":"_pbc_123","collectionName":"test","id":"a33New"}},"id":"a3"}]},"id":"a"},"b":[{"collectionId":"_pbc_123","collectionName":"test","expand":{"b1":{"collectionId":"_pbc_123","collectionName":"test","id":"b1"}},"id":"b"},{"collectionId":"_pbc_123","collectionName":"test","id":"bNew"}],"c":[{"collectionId":"_pbc_123","collectionName":"test","id":"c"}],"dNew":{"collectionId":"_pbc_123","collectionName":"test","id":"dNew"}}`
if expected != rawStr {
t.Fatalf("Expected \n%v, \ngot \n%v", expected, rawStr)
@@ -508,6 +510,7 @@ func TestRecordMergeExpandNilCheck(t *testing.T) {
t.Parallel()
collection := core.NewBaseCollection("test")
collection.Id = "_pbc_123"
scenarios := []struct {
name string
@@ -517,17 +520,17 @@ func TestRecordMergeExpandNilCheck(t *testing.T) {
{
"nil expand",
nil,
`{"collectionId":"_pbc_3632233996","collectionName":"test","id":""}`,
`{"collectionId":"_pbc_123","collectionName":"test","id":""}`,
},
{
"empty expand",
map[string]any{},
`{"collectionId":"_pbc_3632233996","collectionName":"test","id":""}`,
`{"collectionId":"_pbc_123","collectionName":"test","id":""}`,
},
{
"non-empty expand",
map[string]any{"test": core.NewRecord(collection)},
`{"collectionId":"_pbc_3632233996","collectionName":"test","expand":{"test":{"collectionId":"_pbc_3632233996","collectionName":"test","id":""}},"id":""}`,
`{"collectionId":"_pbc_123","collectionName":"test","expand":{"test":{"collectionId":"_pbc_123","collectionName":"test","id":""}},"id":""}`,
},
}
@@ -1308,9 +1311,11 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
f5 := &core.TextField{Name: "field5", Hidden: true}
colBase := core.NewBaseCollection("test_base")
colBase.Id = "_pbc_base_123"
colBase.Fields.Add(f1, f2, f3, f4, f5)
colAuth := core.NewAuthCollection("test_auth")
colAuth.Id = "_pbc_auth_123"
colAuth.Fields.Add(f1, f2, f3, f4, f5)
scenarios := []struct {
@@ -1330,7 +1335,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
false,
nil,
nil,
`{"collectionId":"_pbc_3318600878","collectionName":"test_base","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id"}`,
`{"collectionId":"_pbc_base_123","collectionName":"test_base","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id"}`,
},
{
"[base] with email visibility",
@@ -1339,7 +1344,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
false,
nil,
nil,
`{"collectionId":"_pbc_3318600878","collectionName":"test_base","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id"}`,
`{"collectionId":"_pbc_base_123","collectionName":"test_base","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id"}`,
},
{
"[base] with custom data",
@@ -1348,7 +1353,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
true,
nil,
nil,
`{"collectionId":"_pbc_3318600878","collectionName":"test_base","email":"test_email","emailVisibility":"test_invalid","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","password":"test_passwordHash","tokenKey":"test_tokenKey","unknown":"test_unknown","verified":true}`,
`{"collectionId":"_pbc_base_123","collectionName":"test_base","email":"test_email","emailVisibility":"test_invalid","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","password":"test_passwordHash","tokenKey":"test_tokenKey","unknown":"test_unknown","verified":true}`,
},
{
"[base] with explicit hide and unhide fields",
@@ -1366,7 +1371,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
true,
nil,
[]string{"field5", "@pbInternalAbc", "email", "tokenKey", "unknown"},
`{"collectionId":"_pbc_3318600878","collectionName":"test_base","email":"test_email","emailVisibility":"test_invalid","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"field5":"field_5","id":"test_id","password":"test_passwordHash","tokenKey":"test_tokenKey","unknown":"test_unknown","verified":true}`,
`{"collectionId":"_pbc_base_123","collectionName":"test_base","email":"test_email","emailVisibility":"test_invalid","expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"field5":"field_5","id":"test_id","password":"test_passwordHash","tokenKey":"test_tokenKey","unknown":"test_unknown","verified":true}`,
},
// auth
@@ -1377,7 +1382,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
false,
nil,
nil,
`{"collectionId":"_pbc_4255619734","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","verified":true}`,
`{"collectionId":"_pbc_auth_123","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","verified":true}`,
},
{
"[auth] with email visibility",
@@ -1386,7 +1391,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
false,
nil,
nil,
`{"collectionId":"_pbc_4255619734","collectionName":"test_auth","email":"test_email","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","verified":true}`,
`{"collectionId":"_pbc_auth_123","collectionName":"test_auth","email":"test_email","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","verified":true}`,
},
{
"[auth] with custom data",
@@ -1395,7 +1400,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
true,
nil,
nil,
`{"collectionId":"_pbc_4255619734","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","unknown":"test_unknown","verified":true}`,
`{"collectionId":"_pbc_auth_123","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"id":"test_id","unknown":"test_unknown","verified":true}`,
},
{
"[auth] with explicit hide and unhide fields",
@@ -1413,7 +1418,7 @@ func TestRecordPublicExportAndMarshalJSON(t *testing.T) {
true,
nil,
[]string{"field5", "@pbInternalAbc", "tokenKey", "unknown", "email"}, // emailVisibility:false has higher priority
`{"collectionId":"_pbc_4255619734","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"field5":"field_5","id":"test_id","unknown":"test_unknown","verified":true}`,
`{"collectionId":"_pbc_auth_123","collectionName":"test_auth","emailVisibility":false,"expand":{"test":123},"field1":"field_1","field2":"field_2.png","field3":["test1","test2"],"field5":"field_5","id":"test_id","unknown":"test_unknown","verified":true}`,
},
}