alert_aggr_view support modify by admin
This commit is contained in:
parent
0581e02cf3
commit
a8c60c9f2b
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
|||
|
||||
NOW = $(shell date -u '+%Y%m%d%I%M%S')
|
||||
|
||||
RELEASE_VERSION = 5.9.1
|
||||
RELEASE_VERSION = 5.9.2
|
||||
|
||||
APP = n9e
|
||||
SERVER_BIN = $(APP)
|
||||
|
|
|
@ -82,7 +82,7 @@ func (v *AlertAggrView) Add() error {
|
|||
return Insert(v)
|
||||
}
|
||||
|
||||
func (v *AlertAggrView) Update(name, rule string) error {
|
||||
func (v *AlertAggrView) Update(name, rule string, cate int) error {
|
||||
if err := v.Verify(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -90,19 +90,24 @@ func (v *AlertAggrView) Update(name, rule string) error {
|
|||
v.UpdateAt = time.Now().Unix()
|
||||
v.Name = name
|
||||
v.Rule = rule
|
||||
v.Cate = cate
|
||||
|
||||
return DB().Model(v).Select("name", "rule", "update_at").Updates(v).Error
|
||||
return DB().Model(v).Select("name", "rule", "cate", "update_at").Updates(v).Error
|
||||
}
|
||||
|
||||
// AlertAggrViewDel: userid for safe delete
|
||||
func AlertAggrViewDel(ids []int64, createBy interface{}) error {
|
||||
func AlertAggrViewDel(ids []int64, createBy ...interface{}) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(createBy) > 0 {
|
||||
return DB().Where("id in ? and create_by = ?", ids, createBy).Delete(new(AlertAggrView)).Error
|
||||
}
|
||||
|
||||
return DB().Where("id in ?", ids).Delete(new(AlertAggrView)).Error
|
||||
}
|
||||
|
||||
func AlertAggrViewGets(createBy interface{}) ([]AlertAggrView, error) {
|
||||
var lst []AlertAggrView
|
||||
err := DB().Where("create_by = ? or cate = 0", createBy).Find(&lst).Error
|
||||
|
|
|
@ -14,13 +14,19 @@ func alertAggrViewGets(c *gin.Context) {
|
|||
ginx.NewRender(c).Data(lst, err)
|
||||
}
|
||||
|
||||
// body: name, rule
|
||||
// body: name, rule, cate
|
||||
func alertAggrViewAdd(c *gin.Context) {
|
||||
var f models.AlertAggrView
|
||||
ginx.BindJSON(c, &f)
|
||||
|
||||
me := c.MustGet("user").(*models.User)
|
||||
if !me.IsAdmin() {
|
||||
// 管理员可以选择当前这个视图是公开呢,还是私有,普通用户的话就只能是私有的
|
||||
f.Cate = 1
|
||||
}
|
||||
|
||||
f.Id = 0
|
||||
f.CreateBy = c.MustGet("userid").(int64)
|
||||
f.CreateBy = me.Id
|
||||
ginx.Dangerous(f.Add())
|
||||
|
||||
ginx.NewRender(c).Data(f, nil)
|
||||
|
@ -30,11 +36,17 @@ func alertAggrViewAdd(c *gin.Context) {
|
|||
func alertAggrViewDel(c *gin.Context) {
|
||||
var f idsForm
|
||||
ginx.BindJSON(c, &f)
|
||||
f.Verify()
|
||||
|
||||
ginx.NewRender(c).Message(models.AlertAggrViewDel(f.Ids, c.MustGet("userid")))
|
||||
me := c.MustGet("user").(*models.User)
|
||||
if me.IsAdmin() {
|
||||
ginx.NewRender(c).Message(models.AlertAggrViewDel(f.Ids))
|
||||
} else {
|
||||
ginx.NewRender(c).Message(models.AlertAggrViewDel(f.Ids, me.Id))
|
||||
}
|
||||
}
|
||||
|
||||
// body: id, name, rule
|
||||
// body: id, name, rule, cate
|
||||
func alertAggrViewPut(c *gin.Context) {
|
||||
var f models.AlertAggrView
|
||||
ginx.BindJSON(c, &f)
|
||||
|
@ -47,11 +59,15 @@ func alertAggrViewPut(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
userid := c.MustGet("userid").(int64)
|
||||
if view.CreateBy != userid {
|
||||
me := c.MustGet("user").(*models.User)
|
||||
if !me.IsAdmin() {
|
||||
f.Cate = 1
|
||||
|
||||
if view.CreateBy != me.Id {
|
||||
ginx.NewRender(c, http.StatusForbidden).Message("forbidden")
|
||||
return
|
||||
}
|
||||
|
||||
ginx.NewRender(c).Message(view.Update(f.Name, f.Rule))
|
||||
}
|
||||
|
||||
ginx.NewRender(c).Message(view.Update(f.Name, f.Rule, f.Cate))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue