diff --git a/etc/gop.yml b/etc/gop.yml index 6f55ab48dfcb35d4649da68832201a357ee44da4..e5d980dce395e16bbdb13317e15eca911ea0d1fd 100644 --- a/etc/gop.yml +++ b/etc/gop.yml @@ -3,11 +3,15 @@ - title: 主机设备 ops: - en: ams_host_mgr_menu - cn: 主机设备管理菜单 + cn: 主机设备管理菜单展示 - en: ams_host_delete cn: 主机设备删除 - en: ams_host_modify cn: 主机设备信息修改 + - en: ams_host_field_mgr_menu + cn: 主机设备扩展字段菜单展示 + - en: ams_host_field_mgr + cn: 主机设备扩展字段管理 # - title: 网络设备 # ops: # - en: ams_netware_mgr_menu diff --git a/src/modules/ams/http/router.go b/src/modules/ams/http/router.go index cfbd4a9c934e5ed53fe0f8e6323998258ba06a13..5932a0e34271d62a88aeef495764214c57fed031 100644 --- a/src/modules/ams/http/router.go +++ b/src/modules/ams/http/router.go @@ -19,8 +19,11 @@ func Config(r *gin.Engine) { userLogin.PUT("/hosts/cate", hostCatePut) userLogin.DELETE("/hosts", hostDel) userLogin.GET("/hosts/search", hostSearchGets) + userLogin.POST("/hosts/fields", hostFieldNew) userLogin.GET("/hosts/fields", hostFieldsGets) userLogin.GET("/hosts/field/:id", hostFieldGet) + userLogin.PUT("/hosts/field/:id", hostFieldPut) + userLogin.DELETE("/hosts/field/:id", hostFieldDel) userLogin.GET("/host/:id/fields", hostFieldGets) userLogin.PUT("/host/:id/fields", hostFieldPuts) } diff --git a/src/modules/ams/http/router_host_field.go b/src/modules/ams/http/router_host_field.go index af42d06580a2bf96893c0e9223083c3816c66387..a625a6580a1723f43deb84e2be4b11725745fb80 100644 --- a/src/modules/ams/http/router_host_field.go +++ b/src/modules/ams/http/router_host_field.go @@ -6,6 +6,15 @@ import ( "github.com/didi/nightingale/src/models" ) +func hostFieldNew(c *gin.Context) { + loginUser(c).CheckPermGlobal("ams_host_field_mgr") + + var obj models.HostField + bind(c, &obj) + + renderMessage(c, models.HostFieldNew(&obj)) +} + func hostFieldsGets(c *gin.Context) { lst, err := models.HostFieldGets() renderData(c, lst, err) @@ -16,6 +25,45 @@ func hostFieldGet(c *gin.Context) { renderData(c, obj, err) } +func hostFieldPut(c *gin.Context) { + loginUser(c).CheckPermGlobal("ams_host_field_mgr") + + var f models.HostField + bind(c, &f) + + obj, err := models.HostFieldGet("id = ?", urlParamInt64(c, "id")) + dangerous(err) + + if obj == nil { + bomb("no such field") + } + + if obj.FieldType != f.FieldType { + bomb("field_type cannot modify") + } + + obj.FieldName = f.FieldName + obj.FieldExtra = f.FieldExtra + obj.FieldRequired = f.FieldRequired + obj.FieldCate = f.FieldCate + + renderMessage(c, obj.Update("field_name", "field_extra", "field_required", "field_cate")) +} + +func hostFieldDel(c *gin.Context) { + loginUser(c).CheckPermGlobal("ams_host_field_mgr") + + obj, err := models.HostFieldGet("id = ?", urlParamInt64(c, "id")) + dangerous(err) + + if obj == nil { + renderMessage(c, nil) + return + } + + renderMessage(c, obj.Del()) +} + func hostFieldGets(c *gin.Context) { lst, err := models.HostFieldValueGets(urlParamInt64(c, "id")) renderData(c, lst, err)