Skip to content

Commit 761beab

Browse files
authored
feat:add identifier to plugin. (#4289)
* feat:add identifier to plugin. Signed-off-by: leozhang2018 <[email protected]> * fix:fix handler. Signed-off-by: leozhang2018 <[email protected]> * fix:fix filter not update. Signed-off-by: leozhang2018 <[email protected]> --------- Signed-off-by: leozhang2018 <[email protected]>
1 parent b0da1ac commit 761beab

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

pkg/microservice/aslan/core/common/repository/models/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import "go.mongodb.org/mongo-driver/bson/primitive"
2121
type Plugin struct {
2222
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
2323
Name string `bson:"name" json:"name"`
24+
Identifier string `bson:"identifier" json:"identifier"`
2425
Index int `bson:"index" json:"index"`
2526
Type string `bson:"type" json:"type"` // page or tab
2627
Description string `bson:"description" json:"description"`

pkg/microservice/aslan/core/common/repository/mongodb/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (c *PluginColl) Update(id string, m *models.Plugin) error {
9494
}
9595
change := bson.M{"$set": bson.M{
9696
"name": m.Name,
97+
"identifier": m.Identifier,
9798
"index": m.Index,
9899
"type": m.Type,
99100
"description": m.Description,

pkg/microservice/aslan/core/system/handler/plugin.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func CreatePlugin(c *gin.Context) {
6868
ctx.RespErr = e.ErrInvalidParam.AddDesc("name is required")
6969
return
7070
}
71+
args.Identifier = c.PostForm("identifier")
7172
if idxStr := c.PostForm("index"); idxStr != "" {
7273
if parsed, err := strconv.Atoi(idxStr); err == nil {
7374
args.Index = parsed
@@ -78,6 +79,16 @@ func CreatePlugin(c *gin.Context) {
7879
args.Route = c.PostForm("route")
7980
args.Enabled = c.PostForm("enabled") == "true"
8081

82+
// parse filters if provided
83+
if filtersStr := c.PostForm("filters"); filtersStr != "" {
84+
var filters []*commonmodels.PluginFilter
85+
if err := json.Unmarshal([]byte(filtersStr), &filters); err != nil {
86+
ctx.RespErr = e.ErrInvalidParam.AddDesc("invalid filters format, should be JSON array")
87+
return
88+
}
89+
args.Filters = filters
90+
}
91+
8192
file, header, err := c.Request.FormFile("file")
8293
if err != nil {
8394
ctx.RespErr = e.ErrInvalidParam.AddDesc("file is required")
@@ -119,6 +130,7 @@ func UpdatePlugin(c *gin.Context) {
119130
}
120131
args := new(commonmodels.Plugin)
121132
args.Name = c.PostForm("name")
133+
args.Identifier = c.PostForm("identifier")
122134
if idxStr := c.PostForm("index"); idxStr != "" {
123135
if parsed, err := strconv.Atoi(idxStr); err == nil {
124136
args.Index = parsed
@@ -129,6 +141,16 @@ func UpdatePlugin(c *gin.Context) {
129141
args.Route = c.PostForm("route")
130142
args.Enabled = c.PostForm("enabled") == "true"
131143

144+
// parse filters if provided
145+
if filtersStr := c.PostForm("filters"); filtersStr != "" {
146+
var filters []*commonmodels.PluginFilter
147+
if err := json.Unmarshal([]byte(filtersStr), &filters); err != nil {
148+
ctx.RespErr = e.ErrInvalidParam.AddDesc("invalid filters format, should be JSON array")
149+
return
150+
}
151+
args.Filters = filters
152+
}
153+
132154
// try file
133155
file, header, err := c.Request.FormFile("file")
134156
if err == nil {

0 commit comments

Comments
 (0)