修改编辑方法逻辑,前端细节调整
This commit is contained in:
@@ -30,7 +30,7 @@ func CreateApi(a model.SysApi) (err error) {
|
||||
// @return error
|
||||
func DeleteApi(a model.SysApi) (err error) {
|
||||
err = global.GVA_DB.Delete(a).Error
|
||||
ClearCasbin(1, a.Path)
|
||||
ClearCasbin(1, a.Path,a.Method)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -111,15 +111,19 @@ func GetApiById(id float64) (err error, api model.SysApi) {
|
||||
// @return error
|
||||
func UpdateApi(a model.SysApi) (err error) {
|
||||
var oldA model.SysApi
|
||||
flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
|
||||
if !flag {
|
||||
return errors.New("存在相同api路径")
|
||||
}
|
||||
|
||||
err = global.GVA_DB.Where("id = ?", a.ID).First(&oldA).Error
|
||||
|
||||
if oldA.Path != a.Path || oldA.Method != a.Method{
|
||||
flag := global.GVA_DB.Where("path = ? AND method = ?", a.Path, a.Method).Find(&model.SysApi{}).RecordNotFound()
|
||||
if !flag {
|
||||
return errors.New("存在相同api路径")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
err = UpdateCasbinApi(oldA.Path, a.Path)
|
||||
err = UpdateCasbinApi(oldA.Path, a.Path,oldA.Method,a.Method)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
|
@@ -51,9 +51,9 @@ func AddCasbin(cm model.CasbinModel) bool {
|
||||
// @param oldPath string
|
||||
// @param newPath string
|
||||
// @return error
|
||||
func UpdateCasbinApi(oldPath string, newPath string) error {
|
||||
func UpdateCasbinApi(oldPath string, newPath string,oldMethod string, newMethod string) error {
|
||||
var cs []model.CasbinModel
|
||||
err := global.GVA_DB.Table("casbin_rule").Where("v1 = ?", oldPath).Find(&cs).Update("v1", newPath).Error
|
||||
err := global.GVA_DB.Table("casbin_rule").Where("v1 = ? AND v2 = ?", oldPath,oldMethod).Find(&cs).Update("v1", newPath).Update("v2", newMethod).Error
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@ func GetPolicyPathByAuthorityId(authorityId string) []string {
|
||||
// @param v int
|
||||
// @param p string
|
||||
// @return bool
|
||||
func ClearCasbin(v int, p string) bool {
|
||||
func ClearCasbin(v int, p ...string) bool {
|
||||
e := Casbin()
|
||||
return e.RemoveFilteredPolicy(v, p)
|
||||
return e.RemoveFilteredPolicy(v, p...)
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user