mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
feat: return the correct error message in the Edit Model (#1504)
This commit is contained in:
parent
75b8357de8
commit
24a824d394
@ -80,7 +80,7 @@ func (c *ApiController) UpdateModel() {
|
||||
return
|
||||
}
|
||||
|
||||
c.Data["json"] = wrapActionResponse(object.UpdateModel(id, &model))
|
||||
c.Data["json"] = wrapErrorResponse(object.UpdateModelWithCheck(id, &model))
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,17 @@ func GetModel(id string) *Model {
|
||||
return getModel(owner, name)
|
||||
}
|
||||
|
||||
func UpdateModelWithCheck(id string, modelObj *Model) error {
|
||||
// check model grammar
|
||||
_, err := model.NewModelFromString(modelObj.ModelText)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
UpdateModel(id, modelObj)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateModel(id string, modelObj *Model) bool {
|
||||
owner, name := util.GetOwnerAndNameFromId(id)
|
||||
if getModel(owner, name) == nil {
|
||||
@ -98,11 +109,6 @@ func UpdateModel(id string, modelObj *Model) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
// check model grammar
|
||||
_, err := model.NewModelFromString(modelObj.ModelText)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(modelObj)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user