Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ const (
// BKIsPre the ispre field
BKIsPre = "ispre"

// BKIsHidden the is_hidden field
BKIsHidden = "is_hidden"

// BKObjectUniqueKeys object unique keys field
BKObjectUniqueKeys = "keys"

Expand Down
1 change: 1 addition & 0 deletions src/common/metadata/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type Attribute struct {
IsRequired bool `field:"isrequired" json:"isrequired" bson:"isrequired" mapstructure:"isrequired"`
IsReadOnly bool `field:"isreadonly" json:"isreadonly" bson:"isreadonly" mapstructure:"isreadonly"`
IsOnly bool `field:"isonly" json:"isonly" bson:"isonly" mapstructure:"isonly"`
IsHidden bool `field:"is_hidden" json:"is_hidden" bson:"is_hidden" mapstructure:"is_hidden"`
IsSystem bool `field:"bk_issystem" json:"bk_issystem" bson:"bk_issystem" mapstructure:"bk_issystem"`
IsAPI bool `field:"bk_isapi" json:"bk_isapi" bson:"bk_isapi" mapstructure:"bk_isapi"`
PropertyType string `field:"bk_property_type" json:"bk_property_type" bson:"bk_property_type" mapstructure:"bk_property_type"`
Expand Down
2 changes: 2 additions & 0 deletions src/scene_server/admin_server/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ import (
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202408071435"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202410091435"
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202410311500"

_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603111314"
)
43 changes: 43 additions & 0 deletions src/scene_server/admin_server/upgrader/y3.14.202603111314/pkg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Tencent is pleased to support the open source community by making
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
* Copyright (C) 2017 THL A29 Limited,
* a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package y3_14_202603111314

import (
"context"

"configcenter/src/common/blog"
"configcenter/src/scene_server/admin_server/upgrader"
"configcenter/src/storage/dal"
)

func init() {
upgrader.RegistUpgrader("y3.14.202603111314", upgrade)
}

func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {

blog.Infof("start execute y3.14.202603111314")
err = upsertObjAttIsHidden(ctx, db, conf)
if err != nil {
blog.Errorf("upgrade y3.14.202603111314 upsert attribute with `is_hidden=false` failed, error: %v", err)
return err
}
blog.Infof("execute y3.14.202603111314, upsert attribute with `is_hidden=false` success!")

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Tencent is pleased to support the open source community by making
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
* Copyright (C) 2017 THL A29 Limited,
* a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* We undertake not to change the open source license (MIT license) applicable
* to the current version of the project delivered to anyone in the future.
*/

package y3_14_202603111314

import (
"configcenter/src/common"
"configcenter/src/common/blog"
"configcenter/src/scene_server/admin_server/upgrader"
"configcenter/src/storage/dal"
"context"

"go.mongodb.org/mongo-driver/bson"
)

// Migration logic:
//
// For all existing documents where `is_hidden` is missing
// or null, set the default value to false.
//
// Mongo command:
//
// db.cc_ObjAttDes.updateMany(
// { $or: [{ is_hidden: { $exists: false } }, { is_hidden: null }] },
// { $set: { is_hidden: false } }
// )
//
// Impact:
// Only updates legacy documents.
// New documents created after this migration will contain the field.

// Idempotent:
//
// Running multiple times will not change existing correct data.
func upsertObjAttIsHidden(ctx context.Context, db dal.RDB, conf *upgrader.Config) error {
updateCond := bson.M{
common.BKDBOR: bson.A{
bson.M{common.BKIsHidden: bson.M{
common.BKDBExists: false,
}},
bson.M{common.BKIsHidden: nil},
},
}
updateData := map[string]interface{}{common.BKIsHidden: false}
if err := db.Table(common.BKTableNameObjAttDes).Update(ctx, updateCond, updateData); err != nil {
blog.Errorf("upsert attribute failed, err: %v, cond: %v, updateData: %v", err, updateCond,
updateData)
return err
}
return nil
}
38 changes: 38 additions & 0 deletions src/scene_server/topo_server/service/object_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *Service) CreateObjectAttribute(ctx *rest.Contexts) {
}
}

attr.IsHidden = false
// do not support add preset attribute by api
attr.IsPre = false
isBizCustomField := false
Expand Down Expand Up @@ -356,6 +357,40 @@ func (s *Service) UpdateObjectAttribute(ctx *rest.Contexts) {
ctx.RespEntity(nil)
}

// AttributeHidden attribute hiding configuration
type AttributeHidden struct {
IsHidden bool `field:"is_hidden" json:"is_hidden" bson:"is_hidden"`
}

// UpdateObjectAttributeHidden update the object attribute : is_hidden
func (s *Service) UpdateObjectAttributeHidden(ctx *rest.Contexts) {
var data AttributeHidden
if err := ctx.DecodeInto(&data); err != nil {
ctx.RespAutoError(err)
return
}
// adapt input path param with bk_biz_id and attr id.
id, bizID, err := getAttrIDAndBizID(ctx)
if err != nil {
ctx.RespAutoError(err)
return
}
tags := mapstr.SetValueToMapStrByTags(data)
txnErr := s.Engine.CoreAPI.CoreService().Txn().AutoRunTxn(ctx.Kit.Ctx, ctx.Kit.Header, func() error {
err := s.Logics.AttributeOperation().UpdateObjectAttribute(ctx.Kit, tags, id, bizID, false)
if err != nil {
return err
}
return nil
})

if txnErr != nil {
ctx.RespAutoError(txnErr)
return
}
ctx.RespEntity(nil)
}

// updateObjectTableAttribute update the table object attribute
func (s *Service) updateObjectTableAttribute(ctx *rest.Contexts, id, bizID int64, data mapstr.MapStr) error {

Expand All @@ -378,6 +413,9 @@ func removeImmutableFields(data mapstr.MapStr) mapstr.MapStr {
data.Remove(metadata.BKMetadata)
data.Remove(common.BKAppIDField)

// UpdateObjectAttribute should not update is_hidden
data.Remove(common.BKIsHidden)

// UpdateObjectAttribute should not update bk_property_index、bk_property_group
data.Remove(common.BKPropertyIndexField)
data.Remove(common.BKPropertyGroupField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func (s *Service) initBusinessObjectAttribute(web *restful.WebService) {
Handler: s.ListHostModelAttribute})
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/{id}",
Handler: s.UpdateObjectAttribute})
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/hidden/{id}",
Handler: s.UpdateObjectAttributeHidden})
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/biz/{bk_biz_id}/id/{id}",
Handler: s.UpdateObjectAttribute})
utility.AddHandler(rest.Action{Verb: http.MethodDelete, Path: "/delete/objectattr/{id}",
Expand Down