Skip to content

Commit 3c3f909

Browse files
committed
feat:模型属性添加is_hidden隐藏配置 --story=132514098 前端隐藏模型的字段
1 parent a77dca8 commit 3c3f909

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed

src/common/definitions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ const (
640640
// BKIsPre the ispre field
641641
BKIsPre = "ispre"
642642

643+
// BKIsHidden the is_hidden field
644+
BKIsHidden = "is_hidden"
645+
643646
// BKObjectUniqueKeys object unique keys field
644647
BKObjectUniqueKeys = "keys"
645648

src/common/metadata/attribute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type Attribute struct {
114114
IsRequired bool `field:"isrequired" json:"isrequired" bson:"isrequired" mapstructure:"isrequired"`
115115
IsReadOnly bool `field:"isreadonly" json:"isreadonly" bson:"isreadonly" mapstructure:"isreadonly"`
116116
IsOnly bool `field:"isonly" json:"isonly" bson:"isonly" mapstructure:"isonly"`
117+
IsHidden bool `field:"is_hidden" json:"is_hidden" bson:"is_hidden" mapstructure:"is_hidden"`
117118
IsSystem bool `field:"bk_issystem" json:"bk_issystem" bson:"bk_issystem" mapstructure:"bk_issystem"`
118119
IsAPI bool `field:"bk_isapi" json:"bk_isapi" bson:"bk_isapi" mapstructure:"bk_isapi"`
119120
PropertyType string `field:"bk_property_type" json:"bk_property_type" bson:"bk_property_type" mapstructure:"bk_property_type"`

src/scene_server/admin_server/imports.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ import (
110110
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202408071435"
111111
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202410091435"
112112
_ "configcenter/src/scene_server/admin_server/upgrader/y3.13.202410311500"
113+
114+
_ "configcenter/src/scene_server/admin_server/upgrader/y3.14.202603111314"
113115
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
4+
* Copyright (C) 2017 THL A29 Limited,
5+
* a Tencent company. All rights reserved.
6+
* Licensed under the MIT License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the License is distributed on
11+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
* either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
* We undertake not to change the open source license (MIT license) applicable
15+
* to the current version of the project delivered to anyone in the future.
16+
*/
17+
18+
package y3_14_202603111314
19+
20+
import (
21+
"context"
22+
23+
"configcenter/src/common/blog"
24+
"configcenter/src/scene_server/admin_server/upgrader"
25+
"configcenter/src/storage/dal"
26+
)
27+
28+
func init() {
29+
upgrader.RegistUpgrader("y3.14.202603111314", upgrade)
30+
}
31+
32+
func upgrade(ctx context.Context, db dal.RDB, conf *upgrader.Config) (err error) {
33+
34+
blog.Infof("start execute y3.14.202603111314")
35+
err = upsertObjAttIsHidden(ctx, db, conf)
36+
if err != nil {
37+
blog.Errorf("upgrade y3.14.202603111314 upsert attribute with `is_hidden=false` failed, error: %v", err)
38+
return err
39+
}
40+
blog.Infof("execute y3.14.202603111314, upsert attribute with `is_hidden=false` success!")
41+
42+
return nil
43+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* 蓝鲸智云 - 配置平台 (BlueKing - Configuration System) available.
4+
* Copyright (C) 2017 THL A29 Limited,
5+
* a Tencent company. All rights reserved.
6+
* Licensed under the MIT License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the License is distributed on
11+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
* either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
* We undertake not to change the open source license (MIT license) applicable
15+
* to the current version of the project delivered to anyone in the future.
16+
*/
17+
18+
package y3_14_202603111314
19+
20+
import (
21+
"configcenter/src/common"
22+
"configcenter/src/common/blog"
23+
"configcenter/src/scene_server/admin_server/upgrader"
24+
"configcenter/src/storage/dal"
25+
"context"
26+
27+
"go.mongodb.org/mongo-driver/bson"
28+
)
29+
30+
// Migration logic:
31+
//
32+
// For all existing documents where `is_hidden` is missing
33+
// or null, set the default value to false.
34+
//
35+
// Mongo command:
36+
//
37+
// db.cc_ObjAttDes.updateMany(
38+
// { $or: [{ is_hidden: { $exists: false } }, { is_hidden: null }] },
39+
// { $set: { is_hidden: false } }
40+
// )
41+
//
42+
// Impact:
43+
// Only updates legacy documents.
44+
// New documents created after this migration will contain the field.
45+
46+
// Idempotent:
47+
//
48+
// Running multiple times will not change existing correct data.
49+
func upsertObjAttIsHidden(ctx context.Context, db dal.RDB, conf *upgrader.Config) error {
50+
updateCond := bson.M{
51+
common.BKDBOR: bson.A{
52+
bson.M{common.BKIsHidden: bson.M{
53+
common.BKDBExists: false,
54+
}},
55+
bson.M{common.BKIsHidden: nil},
56+
},
57+
}
58+
updateData := map[string]interface{}{common.BKIsHidden: false}
59+
if err := db.Table(common.BKTableNameObjAttDes).Update(ctx, updateCond, updateData); err != nil {
60+
blog.Errorf("upsert attribute failed, err: %v, cond: %v, updateData: %v", err, updateCond,
61+
updateData)
62+
return err
63+
}
64+
return nil
65+
}

src/scene_server/topo_server/service/object_attribute.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (s *Service) CreateObjectAttribute(ctx *rest.Contexts) {
5858
}
5959
}
6060

61+
attr.IsHidden = false
6162
// do not support add preset attribute by api
6263
attr.IsPre = false
6364
isBizCustomField := false
@@ -356,6 +357,40 @@ func (s *Service) UpdateObjectAttribute(ctx *rest.Contexts) {
356357
ctx.RespEntity(nil)
357358
}
358359

360+
// AttributeHidden attribute hiding configuration
361+
type AttributeHidden struct {
362+
IsHidden bool `field:"is_hidden" json:"is_hidden" bson:"is_hidden"`
363+
}
364+
365+
// UpdateObjectAttributeHidden update the object attribute : is_hidden
366+
func (s *Service) UpdateObjectAttributeHidden(ctx *rest.Contexts) {
367+
var data AttributeHidden
368+
if err := ctx.DecodeInto(&data); err != nil {
369+
ctx.RespAutoError(err)
370+
return
371+
}
372+
// adapt input path param with bk_biz_id and attr id.
373+
id, bizID, err := getAttrIDAndBizID(ctx)
374+
if err != nil {
375+
ctx.RespAutoError(err)
376+
return
377+
}
378+
tags := mapstr.SetValueToMapStrByTags(data)
379+
txnErr := s.Engine.CoreAPI.CoreService().Txn().AutoRunTxn(ctx.Kit.Ctx, ctx.Kit.Header, func() error {
380+
err := s.Logics.AttributeOperation().UpdateObjectAttribute(ctx.Kit, tags, id, bizID, false)
381+
if err != nil {
382+
return err
383+
}
384+
return nil
385+
})
386+
387+
if txnErr != nil {
388+
ctx.RespAutoError(txnErr)
389+
return
390+
}
391+
ctx.RespEntity(nil)
392+
}
393+
359394
// updateObjectTableAttribute update the table object attribute
360395
func (s *Service) updateObjectTableAttribute(ctx *rest.Contexts, id, bizID int64, data mapstr.MapStr) error {
361396

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

416+
// UpdateObjectAttribute should not update is_hidden
417+
data.Remove(common.BKIsHidden)
418+
381419
// UpdateObjectAttribute should not update bk_property_index、bk_property_group
382420
data.Remove(common.BKPropertyIndexField)
383421
data.Remove(common.BKPropertyGroupField)

src/scene_server/topo_server/service/service_business_initfunc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func (s *Service) initBusinessObjectAttribute(web *restful.WebService) {
7979
Handler: s.ListHostModelAttribute})
8080
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/{id}",
8181
Handler: s.UpdateObjectAttribute})
82+
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/hidden/{id}",
83+
Handler: s.UpdateObjectAttributeHidden})
8284
utility.AddHandler(rest.Action{Verb: http.MethodPut, Path: "/update/objectattr/biz/{bk_biz_id}/id/{id}",
8385
Handler: s.UpdateObjectAttribute})
8486
utility.AddHandler(rest.Action{Verb: http.MethodDelete, Path: "/delete/objectattr/{id}",

0 commit comments

Comments
 (0)