fix: Support filtering notification with contactType

This commit is contained in:
rainzm
2020-05-22 20:54:04 +08:00
parent 3908877d3b
commit 841224b402
2 changed files with 13 additions and 4 deletions
+5
View File
@@ -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"`
}
+8 -4
View File
@@ -275,12 +275,12 @@ 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)
@@ -288,6 +288,10 @@ func (self *SNotificationManager) ListItemFilter(ctx context.Context, q *sqlchem
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
}