fix(common): batch validate create

This commit is contained in:
Qu Xuan
2021-06-25 15:49:02 +08:00
parent 1766549f2d
commit a87a8f2f41
3 changed files with 9 additions and 8 deletions
+3 -3
View File
@@ -210,13 +210,13 @@ func mergeInputOutputData(data *jsonutils.JSONDict, resVal reflect.Value) *jsonu
return data
}
func ValidateCreateData(manager IModelManager, ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
ret, err := call(manager, "ValidateCreateData", ctx, userCred, ownerId, query, data)
func ValidateCreateData(funcName string, manager IModelManager, ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
ret, err := call(manager, funcName, ctx, userCred, ownerId, query, data)
if err != nil {
return nil, httperrors.NewGeneralError(err)
}
if len(ret) != 2 {
return nil, httperrors.NewInternalServerError("Invald ValidateCreateData return value")
return nil, httperrors.NewInternalServerError("Invald %s return value", funcName)
}
resVal := ret[0]
if err := ValueToError(ret[1]); err != nil {
+5 -4
View File
@@ -1233,11 +1233,11 @@ func _doCreateItem(
}
}
funcName := "ValidateCreateData"
if batchCreate {
dataDict, err = manager.BatchCreateValidateCreateData(ctx, userCred, ownerId, query, dataDict)
} else {
dataDict, err = ValidateCreateData(manager, ctx, userCred, ownerId, query, dataDict)
funcName = "BatchCreateValidateCreateData"
}
dataDict, err = ValidateCreateData(funcName, manager, ctx, userCred, ownerId, query, dataDict)
if err != nil {
return nil, httperrors.NewGeneralError(err)
@@ -1545,7 +1545,8 @@ func managerPerformCheckCreateData(
}()
}
return ValidateCreateData(manager, ctx, userCred, ownerId, query, bodyDict)
funcName := "ValidateCreateData"
return ValidateCreateData(funcName, manager, ctx, userCred, ownerId, query, bodyDict)
}
func (dispatcher *DBModelDispatcher) PerformClassAction(ctx context.Context, action string, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
+1 -1
View File
@@ -86,7 +86,7 @@ type IModelManager interface {
// create hooks
AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool
BatchCreateValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
// BatchCreateValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
// ValidateCreateData dynamic called by dispatcher
// ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error)
OnCreateComplete(ctx context.Context, items []IModel, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject)