github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/sys/builtin/impl_sysisactivevalidation.go (about)

     1  /*
     2   * Copyright (c) 2023-present unTill Pro, Ltd.
     3   * @author Denis Gribanov
     4   */
     5  
     6  package builtin
     7  
     8  import (
     9  	"context"
    10  	"errors"
    11  
    12  	"github.com/voedger/voedger/pkg/appdef"
    13  	"github.com/voedger/voedger/pkg/istructs"
    14  	"github.com/voedger/voedger/pkg/istructsmem"
    15  )
    16  
    17  func provideSysIsActiveValidation(cfg *istructsmem.AppConfigType) {
    18  	cfg.AddCUDValidators(istructs.CUDValidator{
    19  		Match: func(cud istructs.ICUDRow, wsid istructs.WSID, cmdQName appdef.QName) bool {
    20  			return cud.IsNew()
    21  		},
    22  		Validate: func(ctx context.Context, appStructs istructs.IAppStructs, cudRow istructs.ICUDRow, wsid istructs.WSID, cmdQName appdef.QName) error {
    23  			if !cudRow.AsBool(appdef.SystemField_IsActive) {
    24  				return errors.New("inserting a deactivated record is not allowed")
    25  			}
    26  			return nil
    27  		},
    28  	})
    29  }