improved auth record errors reporting and updated nested tx test
This commit is contained in:
parent
4ceab4e7ed
commit
ca528cef03
|
@ -215,7 +215,7 @@ func (dao *Dao) FindAuthRecordByToken(token string, baseTokenKey string) (*model
|
||||||
id, _ := unverifiedClaims["id"].(string)
|
id, _ := unverifiedClaims["id"].(string)
|
||||||
collectionId, _ := unverifiedClaims["collectionId"].(string)
|
collectionId, _ := unverifiedClaims["collectionId"].(string)
|
||||||
if id == "" || collectionId == "" {
|
if id == "" || collectionId == "" {
|
||||||
return nil, errors.New("Missing or invalid token claims.")
|
return nil, errors.New("missing or invalid token claims")
|
||||||
}
|
}
|
||||||
|
|
||||||
record, err := dao.FindRecordById(collectionId, id)
|
record, err := dao.FindRecordById(collectionId, id)
|
||||||
|
@ -242,8 +242,11 @@ func (dao *Dao) FindAuthRecordByToken(token string, baseTokenKey string) (*model
|
||||||
// Returns an error if it is not an auth collection or the record is not found.
|
// Returns an error if it is not an auth collection or the record is not found.
|
||||||
func (dao *Dao) FindAuthRecordByEmail(collectionNameOrId string, email string) (*models.Record, error) {
|
func (dao *Dao) FindAuthRecordByEmail(collectionNameOrId string, email string) (*models.Record, error) {
|
||||||
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
|
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
|
||||||
if err != nil || !collection.IsAuth() {
|
if err != nil {
|
||||||
return nil, errors.New("Missing or not an auth collection.")
|
return nil, fmt.Errorf("failed to fetch auth collection %q (%w)", collectionNameOrId, err)
|
||||||
|
}
|
||||||
|
if !collection.IsAuth() {
|
||||||
|
return nil, fmt.Errorf("%q is not an auth collection", collectionNameOrId)
|
||||||
}
|
}
|
||||||
|
|
||||||
row := dbx.NullStringMap{}
|
row := dbx.NullStringMap{}
|
||||||
|
@ -265,8 +268,11 @@ func (dao *Dao) FindAuthRecordByEmail(collectionNameOrId string, email string) (
|
||||||
// Returns an error if it is not an auth collection or the record is not found.
|
// Returns an error if it is not an auth collection or the record is not found.
|
||||||
func (dao *Dao) FindAuthRecordByUsername(collectionNameOrId string, username string) (*models.Record, error) {
|
func (dao *Dao) FindAuthRecordByUsername(collectionNameOrId string, username string) (*models.Record, error) {
|
||||||
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
|
collection, err := dao.FindCollectionByNameOrId(collectionNameOrId)
|
||||||
if err != nil || !collection.IsAuth() {
|
if err != nil {
|
||||||
return nil, errors.New("Missing or not an auth collection.")
|
return nil, fmt.Errorf("failed to fetch auth collection %q (%w)", collectionNameOrId, err)
|
||||||
|
}
|
||||||
|
if !collection.IsAuth() {
|
||||||
|
return nil, fmt.Errorf("%q is not an auth collection", collectionNameOrId)
|
||||||
}
|
}
|
||||||
|
|
||||||
row := dbx.NullStringMap{}
|
row := dbx.NullStringMap{}
|
||||||
|
@ -497,7 +503,7 @@ func (dao *Dao) deleteRefRecords(mainRecord *models.Record, refRecords []*models
|
||||||
}
|
}
|
||||||
|
|
||||||
if field.Required && len(ids) == 0 {
|
if field.Required && len(ids) == 0 {
|
||||||
return fmt.Errorf("The record cannot be deleted because it is part of a required reference in record %s (%s collection).", refRecord.Id, refRecord.Collection().Name)
|
return fmt.Errorf("the record cannot be deleted because it is part of a required reference in record %s (%s collection)", refRecord.Id, refRecord.Collection().Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the reference changes
|
// save the reference changes
|
||||||
|
|
|
@ -318,12 +318,10 @@ func TestRecordUpsertDrySubmitSuccess(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that the record changes weren't persisted
|
// ensure that the record changes weren't persisted
|
||||||
// ---
|
|
||||||
recordAfter, err := app.Dao().FindRecordById(collection.Id, recordBefore.Id)
|
recordAfter, err := app.Dao().FindRecordById(collection.Id, recordBefore.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if recordAfter.GetString("title") == "dry_test" {
|
if recordAfter.GetString("title") == "dry_test" {
|
||||||
t.Fatalf("Expected record.title to be %v, got %v", recordAfter.GetString("title"), "dry_test")
|
t.Fatalf("Expected record.title to be %v, got %v", recordAfter.GetString("title"), "dry_test")
|
||||||
}
|
}
|
||||||
|
@ -376,6 +374,11 @@ func TestRecordUpsertDrySubmitWithNestedTx(t *testing.T) {
|
||||||
t.Fatalf("Expected callbackCalls to be 1, got %d", callbackCalls)
|
t.Fatalf("Expected callbackCalls to be 1, got %d", callbackCalls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ensure that the original txDao can still be used after the DrySubmit rollback
|
||||||
|
if _, err := txDao.FindRecordById(collection.Id, recordBefore.Id); err != nil {
|
||||||
|
t.Fatalf("Expected the dry submit rollback to not affect the outer tx context, got %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// ensure that the record changes weren't persisted
|
// ensure that the record changes weren't persisted
|
||||||
recordAfter, err := app.Dao().FindRecordById(collection.Id, recordBefore.Id)
|
recordAfter, err := app.Dao().FindRecordById(collection.Id, recordBefore.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue