Skip to content

Commit

Permalink
fix: Support filtering notification with contactType
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed May 22, 2020
1 parent 575f1c2 commit ee85dec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/notify/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ type NotificationDetails struct {

UserList jsonutils.JSONObject `json:"user_list"`
}

type NotificationListInput struct {
Scope string `json:"scope"`
ContactType string `json:"contact_type"`
}
12 changes: 8 additions & 4 deletions pkg/notify/models/mod_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,23 @@ func (self *SNotificationManager) syncDatabase(ids []string) error {

// 通知消息列表
func (self *SNotificationManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential,
query jsonutils.JSONObject) (*sqlchemy.SQuery, error) {
input api.NotificationListInput) (*sqlchemy.SQuery, error) {

// no domainID for now
scopeStr, err := query.GetString("scope")
if err != nil {
scopeStr = "system"
scopeStr := "system"
if len(input.Scope) > 0 {
scopeStr = input.Scope
}
scope := rbacutils.TRbacScope(scopeStr)

if !scope.HigherEqual(rbacutils.ScopeSystem) {
q = q.Equals("uid", userCred.GetUserId())
}

if len(input.ContactType) > 0 {
q = q.Equals("contact_type", input.ContactType)
}

q = q.GroupBy("cluster_id").Desc("received_at")
return q, nil
}
Expand Down

0 comments on commit ee85dec

Please sign in to comment.