From 860c7f98ec509bfe87d6edba48db2de6c618c4f0 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Thu, 20 Jul 2023 15:30:31 +0800 Subject: [PATCH] fix: update organization node may clear description --- pkg/keystone/models/organization_nodes.go | 17 +++++++++++++++-- .../options/identity/organization_nodes.go | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/keystone/models/organization_nodes.go b/pkg/keystone/models/organization_nodes.go index 9b1e1476a8..7f6ebf3b6a 100644 --- a/pkg/keystone/models/organization_nodes.go +++ b/pkg/keystone/models/organization_nodes.go @@ -104,6 +104,19 @@ func generateId(orgId string, fullLabel string, level int) string { } func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId string, label string, fullLabel string, level int, weight *int, desc string) (*SOrganizationNode, error) { + id := generateId(orgId, fullLabel, level) + obj, err := manager.FetchById(id) + if err != nil { + if errors.Cause(err) != sql.ErrNoRows { + return nil, errors.Wrap(err, "FetchById") + } + // not exist + } else { + // exist + if len(desc) == 0 { + desc = obj.(*SOrganizationNode).Description + } + } node := &SOrganizationNode{ OrgId: orgId, FullLabel: fullLabel, @@ -112,9 +125,9 @@ func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId s } node.Description = desc node.Name = label - node.Id = generateId(orgId, fullLabel, level) + node.Id = id - err := manager.TableSpec().InsertOrUpdate(ctx, node) + err = manager.TableSpec().InsertOrUpdate(ctx, node) if err != nil { return nil, errors.Wrap(err, "InsertOrUpdate") } diff --git a/pkg/mcclient/options/identity/organization_nodes.go b/pkg/mcclient/options/identity/organization_nodes.go index 1170e47336..62470814b1 100644 --- a/pkg/mcclient/options/identity/organization_nodes.go +++ b/pkg/mcclient/options/identity/organization_nodes.go @@ -50,7 +50,8 @@ func (opts *OrganizationNodeIdOptions) Params() (jsonutils.JSONObject, error) { type OrganizationNodeUpdateOptions struct { OrganizationNodeIdOptions - Weigth int `help:"update weight of node"` + Weigth int `help:"update weight of node"` + Description string `help:"update description"` } func (opts *OrganizationNodeUpdateOptions) Params() (jsonutils.JSONObject, error) {