mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(common): batch validate create
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user