From 2fa97cd09ade0ae742b04307d1bb6a684dc710ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 28 Feb 2024 17:51:37 +0800 Subject: [PATCH] fix(notify): add capability for notify config (#19569) --- cmd/climc/shell/notify/config.go | 1 + pkg/mcclient/options/notify/config.go | 11 ++++++++++ pkg/notify/models/config.go | 30 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/cmd/climc/shell/notify/config.go b/cmd/climc/shell/notify/config.go index d57fd3145a..c383d94105 100644 --- a/cmd/climc/shell/notify/config.go +++ b/cmd/climc/shell/notify/config.go @@ -27,4 +27,5 @@ func init() { cmd.Update(new(options.ConfigUpdateOptions)) cmd.Show(new(options.ConfigOptions)) cmd.Delete(new(options.ConfigOptions)) + cmd.GetProperty(new(options.ConfigCapabilityOptions)) } diff --git a/pkg/mcclient/options/notify/config.go b/pkg/mcclient/options/notify/config.go index c9363c2559..3df8b6c40b 100644 --- a/pkg/mcclient/options/notify/config.go +++ b/pkg/mcclient/options/notify/config.go @@ -80,3 +80,14 @@ func (cu *ConfigUpdateOptions) Params() (jsonutils.JSONObject, error) { d.Set("content", configs) return d, nil } + +type ConfigCapabilityOptions struct { +} + +func (c *ConfigCapabilityOptions) Property() string { + return "capability" +} + +func (c *ConfigCapabilityOptions) Params() (jsonutils.JSONObject, error) { + return nil, nil +} diff --git a/pkg/notify/models/config.go b/pkg/notify/models/config.go index 5ab1201c75..fb52726b13 100644 --- a/pkg/notify/models/config.go +++ b/pkg/notify/models/config.go @@ -103,6 +103,36 @@ func (cm *SConfigManager) ValidateCreateData(ctx context.Context, userCred mccli return input, nil } +func (manager *SConfigManager) GetPropertyCapability(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) { + q := manager.Query() + configs := []SConfig{} + err := db.FetchModelObjects(manager, q, &configs) + if err != nil { + return nil, err + } + ret := struct { + System []string `json:"system,allowempty"` + Domain map[string][]string `json:"domain,allowempty"` + }{ + System: []string{}, + Domain: map[string][]string{}, + } + + for _, config := range configs { + switch config.Attribution { + case api.CONFIG_ATTRIBUTION_SYSTEM: + ret.System = append(ret.System, config.Type) + case api.CONFIG_ATTRIBUTION_DOMAIN: + _, ok := ret.Domain[config.DomainId] + if !ok { + ret.Domain[config.DomainId] = []string{} + } + ret.Domain[config.DomainId] = append(ret.Domain[config.DomainId], config.Type) + } + } + return jsonutils.Marshal(ret), nil +} + func (c *SConfig) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) { c.SDomainLevelResourceBase.PostCreate(ctx, userCred, ownerId, query, data) err := c.StartRepullSubcontactTask(ctx, userCred, false)