mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #17561 from swordqiu/hotfix/qj-organization-node-description
fix: node description update
This commit is contained in:
@@ -106,8 +106,9 @@ type OrganizationPerformAddLevelsInput struct {
|
||||
}
|
||||
|
||||
type OrganizationPerformAddNodeInput struct {
|
||||
Tags map[string]string
|
||||
Weight int
|
||||
Tags map[string]string
|
||||
Weight int
|
||||
Description string
|
||||
}
|
||||
|
||||
type OrganizationPerformSyncInput struct {
|
||||
|
||||
@@ -103,13 +103,14 @@ func generateId(orgId string, fullLabel string, level int) string {
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId string, label string, fullLabel string, level int, weight *int) (*SOrganizationNode, error) {
|
||||
func (manager *SOrganizationNodeManager) ensureNode(ctx context.Context, orgId string, label string, fullLabel string, level int, weight *int, desc string) (*SOrganizationNode, error) {
|
||||
node := &SOrganizationNode{
|
||||
OrgId: orgId,
|
||||
FullLabel: fullLabel,
|
||||
Level: level,
|
||||
Weight: weight,
|
||||
}
|
||||
node.Description = desc
|
||||
node.Name = label
|
||||
node.Id = generateId(orgId, fullLabel, level)
|
||||
|
||||
@@ -250,7 +251,7 @@ func (orgNode *SOrganizationNode) ValidateUpdateData(
|
||||
return input, errors.Wrap(err, "SStandaloneResourceBase.ValidateUpdateData")
|
||||
}
|
||||
// not allow to update name
|
||||
if input.Name != orgNode.Name {
|
||||
if len(input.Name) > 0 && input.Name != orgNode.Name {
|
||||
return input, errors.Wrap(httperrors.ErrForbidden, "not allow to update name")
|
||||
}
|
||||
return input, nil
|
||||
|
||||
@@ -67,7 +67,7 @@ type SOrganization struct {
|
||||
|
||||
Keys string `width:"256" charset:"utf8" list:"user" create:"admin_optional"`
|
||||
|
||||
Level int `list:"user" create:"admin_required"`
|
||||
Level int `list:"user" create:"admin_optional"`
|
||||
}
|
||||
|
||||
func (manager *SOrganizationManager) fetchOrganizationById(orgId string) (*SOrganization, error) {
|
||||
@@ -257,9 +257,10 @@ func (manager *SOrganizationManager) ValidateCreateData(
|
||||
return input, errors.Wrapf(httperrors.ErrInputParameter, "invalid organization type %s", input.Type)
|
||||
}
|
||||
|
||||
if len(input.Key) == 0 {
|
||||
return input, errors.Wrap(httperrors.ErrInputParameter, "empty key")
|
||||
}
|
||||
// allow empty key
|
||||
// if len(input.Key) == 0 {
|
||||
// return input, errors.Wrap(httperrors.ErrInputParameter, "empty key")
|
||||
// }
|
||||
|
||||
input.Level = len(input.Key)
|
||||
// keys should be uniq
|
||||
@@ -328,6 +329,9 @@ func (org *SOrganization) PerformAddLevel(
|
||||
keys := api.SplitLabel(org.Keys)
|
||||
|
||||
for _, nk := range input.Key {
|
||||
if len(nk) == 0 {
|
||||
return nil, errors.Wrap(httperrors.ErrInputParameter, "empty key")
|
||||
}
|
||||
if utils.IsInArray(nk, keys) {
|
||||
return nil, errors.Wrapf(httperrors.ErrInputParameter, "key %s duplicated", nk)
|
||||
} else {
|
||||
@@ -355,6 +359,8 @@ func (org *SOrganization) PerformAddLevel(
|
||||
return nil, errors.Wrap(err, "Update")
|
||||
}
|
||||
|
||||
OrganizationManager.cache.Update(org)
|
||||
|
||||
db.OpsLog.LogEvent(org, db.ACT_UPDATE, org.GetShortDesc(ctx), userCred)
|
||||
logclient.AddSimpleActionLog(org, logclient.ACT_UPDATE, org.GetShortDesc(ctx), userCred, true)
|
||||
|
||||
@@ -397,10 +403,12 @@ func (org *SOrganization) PerformAddNode(
|
||||
|
||||
for i := 0; i < len(labels); i++ {
|
||||
var weight *int
|
||||
var desc string
|
||||
if i == len(labels)-1 {
|
||||
weight = &input.Weight
|
||||
desc = input.Description
|
||||
}
|
||||
_, err := OrganizationNodeManager.ensureNode(ctx, org.Id, labels[i], api.JoinLabels(labels[0:i+1]...), i+1, weight)
|
||||
_, err := OrganizationNodeManager.ensureNode(ctx, org.Id, labels[i], api.JoinLabels(labels[0:i+1]...), i+1, weight, desc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "fail to insert node %s", api.JoinLabels(labels[i:i]...))
|
||||
}
|
||||
@@ -535,7 +543,7 @@ func (org *SOrganization) syncTagValueMap(ctx context.Context, tagVal map[string
|
||||
if val, ok := tagVal[key]; ok && val != tagutils.NoValue {
|
||||
labels = append(labels, val)
|
||||
log.Debugf("%d %s %s %s", i, key, val, strings.Join(labels, "/"))
|
||||
_, err := OrganizationNodeManager.ensureNode(ctx, org.Id, val, api.JoinLabels(labels...), i+1, nil)
|
||||
_, err := OrganizationNodeManager.ensureNode(ctx, org.Id, val, api.JoinLabels(labels...), i+1, nil, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "fail to insert node %s", api.JoinLabels(labels...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user