You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2023/10/10 14:45:46 UTC

[incubator-devlake] branch main updated: fix(plugins): update connection scope config helper, set connection id by default (#6210)

This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 6eaf61988 fix(plugins): update  connection scope config helper, set connection id by default (#6210)
6eaf61988 is described below

commit 6eaf61988c02fb8a572f87e1db5ad8cd03a43ed8
Author: Lynwee <li...@merico.dev>
AuthorDate: Tue Oct 10 22:45:39 2023 +0800

    fix(plugins): update  connection scope config helper, set connection id by default (#6210)
---
 backend/core/models/common/base.go                 |  8 +++++++-
 .../pluginhelper/api/scope_config_helper.go        | 23 ++++++++++++----------
 backend/plugins/bamboo/api/init.go                 |  4 ++--
 backend/plugins/bamboo/models/scope_config.go      |  5 +++++
 backend/plugins/bitbucket/api/init.go              |  4 ++--
 backend/plugins/bitbucket/models/scope_config.go   |  5 +++++
 backend/plugins/circleci/api/init.go               |  4 ++--
 backend/plugins/circleci/models/scope_config.go    |  5 +++++
 backend/plugins/jenkins/api/init.go                |  4 ++--
 backend/plugins/jenkins/models/scope_config.go     |  5 +++++
 backend/plugins/jira/api/init.go                   |  4 ++--
 backend/plugins/jira/models/scope_config.go        |  5 +++++
 backend/plugins/tapd/api/init.go                   |  4 ++--
 backend/plugins/tapd/models/scope_config.go        |  5 +++++
 backend/plugins/trello/api/init.go                 |  4 ++--
 backend/plugins/trello/models/scope_config.go      |  5 +++++
 backend/plugins/zentao/api/init.go                 |  4 ++--
 backend/plugins/zentao/models/scope_config.go      |  5 +++++
 18 files changed, 76 insertions(+), 27 deletions(-)

diff --git a/backend/core/models/common/base.go b/backend/core/models/common/base.go
index 43c6675a8..a505f74e7 100644
--- a/backend/core/models/common/base.go
+++ b/backend/core/models/common/base.go
@@ -18,6 +18,7 @@ limitations under the License.
 package common
 
 import (
+	"github.com/apache/incubator-devlake/core/dal"
 	"time"
 )
 
@@ -98,7 +99,7 @@ type ScopeConfig struct {
 	Model
 	Entities     []string `gorm:"type:json;serializer:json" json:"entities" mapstructure:"entities"`
 	ConnectionId uint64   `json:"connectionId" gorm:"index" validate:"required" mapstructure:"connectionId,omitempty"`
-	Name         string   `mapstructure:"name" json:"name" gorm:"type:varchar(255)" validate:"required"`
+	//Name         string   `mapstructure:"name" json:"name" gorm:"type:varchar(255)" validate:"required"`
 }
 
 func (s ScopeConfig) ScopeConfigConnectionId() uint64 {
@@ -107,3 +108,8 @@ func (s ScopeConfig) ScopeConfigConnectionId() uint64 {
 func (s ScopeConfig) ScopeConfigId() uint64 {
 	return s.ID
 }
+
+type ScopeConfigOperator[T dal.Tabler] interface {
+	*T
+	SetConnectionId(t *T, connectionId uint64)
+}
diff --git a/backend/helpers/pluginhelper/api/scope_config_helper.go b/backend/helpers/pluginhelper/api/scope_config_helper.go
index 0b9a3cb74..e1da762f5 100644
--- a/backend/helpers/pluginhelper/api/scope_config_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_config_helper.go
@@ -18,6 +18,7 @@ limitations under the License.
 package api
 
 import (
+	"github.com/apache/incubator-devlake/core/models/common"
 	"net/http"
 	"reflect"
 	"strconv"
@@ -32,7 +33,7 @@ import (
 )
 
 // ScopeConfigHelper is used to write the CURD of scope config
-type ScopeConfigHelper[ScopeConfig dal.Tabler] struct {
+type ScopeConfigHelper[ScopeConfig dal.Tabler, ScopeConfigOperator common.ScopeConfigOperator[ScopeConfig]] struct {
 	log        log.Logger
 	db         dal.Dal
 	validator  *validator.Validate
@@ -40,15 +41,15 @@ type ScopeConfigHelper[ScopeConfig dal.Tabler] struct {
 }
 
 // NewScopeConfigHelper creates a ScopeConfigHelper for scope config management
-func NewScopeConfigHelper[Tr dal.Tabler](
+func NewScopeConfigHelper[Tr dal.Tabler, ScopeConfigOperator common.ScopeConfigOperator[Tr]](
 	basicRes context.BasicRes,
 	vld *validator.Validate,
 	pluginName string,
-) *ScopeConfigHelper[Tr] {
+) *ScopeConfigHelper[Tr, ScopeConfigOperator] {
 	if vld == nil {
 		vld = validator.New()
 	}
-	return &ScopeConfigHelper[Tr]{
+	return &ScopeConfigHelper[Tr, ScopeConfigOperator]{
 		log:        basicRes.GetLogger(),
 		db:         basicRes.GetDal(),
 		validator:  vld,
@@ -56,7 +57,7 @@ func NewScopeConfigHelper[Tr dal.Tabler](
 	}
 }
 
-func (t ScopeConfigHelper[ScopeConfig]) Create(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) Create(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
 	connectionId, e := strconv.ParseUint(input.Params["connectionId"], 10, 64)
 	if e != nil || connectionId == 0 {
 		return nil, errors.Default.Wrap(e, "the connection ID should be an non-zero integer")
@@ -65,6 +66,8 @@ func (t ScopeConfigHelper[ScopeConfig]) Create(input *plugin.ApiResourceInput) (
 	if err := DecodeMapStruct(input.Body, config, false); err != nil {
 		return nil, errors.Default.Wrap(err, "error in decoding scope config")
 	}
+	var scopeConfigOperator ScopeConfigOperator = new(ScopeConfig)
+	scopeConfigOperator.SetConnectionId(config, connectionId)
 	if t.validator != nil {
 		if err := t.validator.Struct(config); err != nil {
 			return nil, errors.Default.Wrap(err, "error validating scope config")
@@ -90,7 +93,7 @@ func (t ScopeConfigHelper[ScopeConfig]) Create(input *plugin.ApiResourceInput) (
 	return &plugin.ApiResourceOutput{Body: config, Status: http.StatusOK}, nil
 }
 
-func (t ScopeConfigHelper[ScopeConfig]) Update(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) Update(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
 	scopeConfigId, e := strconv.ParseUint(input.Params["id"], 10, 64)
 	if e != nil {
 		return nil, errors.Default.Wrap(e, "the scope config ID should be an integer")
@@ -120,7 +123,7 @@ func (t ScopeConfigHelper[ScopeConfig]) Update(input *plugin.ApiResourceInput) (
 	return &plugin.ApiResourceOutput{Body: config, Status: http.StatusOK}, nil
 }
 
-func (t ScopeConfigHelper[ScopeConfig]) Get(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) Get(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
 	scopeConfigId, err := strconv.ParseUint(input.Params["id"], 10, 64)
 	if err != nil {
 		return nil, errors.Default.Wrap(err, "the scope config ID should be an integer")
@@ -133,7 +136,7 @@ func (t ScopeConfigHelper[ScopeConfig]) Get(input *plugin.ApiResourceInput) (*pl
 	return &plugin.ApiResourceOutput{Body: config, Status: http.StatusOK}, nil
 }
 
-func (t ScopeConfigHelper[ScopeConfig]) List(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) List(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
 	connectionId, e := strconv.ParseUint(input.Params["connectionId"], 10, 64)
 	if e != nil || connectionId == 0 {
 		return nil, errors.Default.Wrap(e, "the connection ID should be an non-zero integer")
@@ -147,7 +150,7 @@ func (t ScopeConfigHelper[ScopeConfig]) List(input *plugin.ApiResourceInput) (*p
 	return &plugin.ApiResourceOutput{Body: configs, Status: http.StatusOK}, nil
 }
 
-func (t ScopeConfigHelper[ScopeConfig]) Delete(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) Delete(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
 	scopeConfigId, err := errors.Convert01(strconv.ParseUint(input.Params["id"], 10, 64))
 	if err != nil {
 		return nil, errors.Default.Wrap(err, "the scope config ID should be an integer")
@@ -167,7 +170,7 @@ func (t ScopeConfigHelper[ScopeConfig]) Delete(input *plugin.ApiResourceInput) (
 	}
 	return &plugin.ApiResourceOutput{Body: nil, Status: http.StatusOK}, nil
 }
-func (t ScopeConfigHelper[ScopeConfig]) nullOutScopeReferences(scopeConfigId uint64) errors.Error {
+func (t ScopeConfigHelper[ScopeConfig, ScopeConfigOperator]) nullOutScopeReferences(scopeConfigId uint64) errors.Error {
 	p, _ := plugin.GetPlugin(t.pluginName)
 	pluginSrc, ok := p.(plugin.PluginSource)
 	if !ok {
diff --git a/backend/plugins/bamboo/api/init.go b/backend/plugins/bamboo/api/init.go
index 47eec3408..64e838a35 100644
--- a/backend/plugins/bamboo/api/init.go
+++ b/backend/plugins/bamboo/api/init.go
@@ -29,7 +29,7 @@ var vld *validator.Validate
 var connectionHelper *api.ConnectionApiHelper
 var scopeHelper *api.ScopeApiHelper[models.BambooConnection, models.BambooPlan, models.BambooScopeConfig]
 var remoteHelper *api.RemoteApiHelper[models.BambooConnection, models.BambooPlan, models.ApiBambooPlan, api.NoRemoteGroupResponse]
-var scopeConfigHelper *api.ScopeConfigHelper[models.BambooScopeConfig]
+var scopeConfigHelper *api.ScopeConfigHelper[models.BambooScopeConfig, *models.BambooScopeConfig]
 
 var basicRes context.BasicRes
 
@@ -62,7 +62,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scopeConfigHelper = api.NewScopeConfigHelper[models.BambooScopeConfig](
+	scopeConfigHelper = api.NewScopeConfigHelper[models.BambooScopeConfig, *models.BambooScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/bamboo/models/scope_config.go b/backend/plugins/bamboo/models/scope_config.go
index 5a14304ed..35c816a44 100644
--- a/backend/plugins/bamboo/models/scope_config.go
+++ b/backend/plugins/bamboo/models/scope_config.go
@@ -37,6 +37,11 @@ func (BambooScopeConfig) TableName() string {
 	return "_tool_bamboo_scope_configs"
 }
 
+func (cfg *BambooScopeConfig) SetConnectionId(c *BambooScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
+
 func (cfg *BambooScopeConfig) GetRepoIdMap() map[int]string {
 	repoMap := make(map[int]string)
 	for k, v := range cfg.RepoMap {
diff --git a/backend/plugins/bitbucket/api/init.go b/backend/plugins/bitbucket/api/init.go
index 349522473..633124ea1 100644
--- a/backend/plugins/bitbucket/api/init.go
+++ b/backend/plugins/bitbucket/api/init.go
@@ -29,7 +29,7 @@ var vld *validator.Validate
 var connectionHelper *api.ConnectionApiHelper
 var scopeHelper *api.ScopeApiHelper[models.BitbucketConnection, models.BitbucketRepo, models.BitbucketScopeConfig]
 var remoteHelper *api.RemoteApiHelper[models.BitbucketConnection, models.BitbucketRepo, models.BitbucketApiRepo, models.GroupResponse]
-var scHelper *api.ScopeConfigHelper[models.BitbucketScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.BitbucketScopeConfig, *models.BitbucketScopeConfig]
 var basicRes context.BasicRes
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
@@ -61,7 +61,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scHelper = api.NewScopeConfigHelper[models.BitbucketScopeConfig](
+	scHelper = api.NewScopeConfigHelper[models.BitbucketScopeConfig, *models.BitbucketScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/bitbucket/models/scope_config.go b/backend/plugins/bitbucket/models/scope_config.go
index e25759f58..846ed7bb4 100644
--- a/backend/plugins/bitbucket/models/scope_config.go
+++ b/backend/plugins/bitbucket/models/scope_config.go
@@ -40,3 +40,8 @@ type BitbucketScopeConfig struct {
 func (BitbucketScopeConfig) TableName() string {
 	return "_tool_bitbucket_scope_configs"
 }
+
+func (cfg *BitbucketScopeConfig) SetConnectionId(c *BitbucketScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
diff --git a/backend/plugins/circleci/api/init.go b/backend/plugins/circleci/api/init.go
index 802b9211a..1ac90035f 100644
--- a/backend/plugins/circleci/api/init.go
+++ b/backend/plugins/circleci/api/init.go
@@ -28,7 +28,7 @@ import (
 var vld *validator.Validate
 var connectionHelper *helper.ConnectionApiHelper
 var scopeHelper *helper.ScopeApiHelper[models.CircleciConnection, models.CircleciProject, models.CircleciScopeConfig]
-var scHelper *helper.ScopeConfigHelper[models.CircleciScopeConfig]
+var scHelper *helper.ScopeConfigHelper[models.CircleciScopeConfig, *models.CircleciScopeConfig]
 var remoteHelper *helper.RemoteApiHelper[models.CircleciConnection, models.CircleciProject, RemoteProject, helper.NoRemoteGroupResponse]
 var basicRes context.BasicRes
 
@@ -60,7 +60,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scHelper = helper.NewScopeConfigHelper[models.CircleciScopeConfig](
+	scHelper = helper.NewScopeConfigHelper[models.CircleciScopeConfig, *models.CircleciScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/circleci/models/scope_config.go b/backend/plugins/circleci/models/scope_config.go
index 920e4e7a4..bad26995c 100644
--- a/backend/plugins/circleci/models/scope_config.go
+++ b/backend/plugins/circleci/models/scope_config.go
@@ -32,3 +32,8 @@ type CircleciScopeConfig struct {
 func (t CircleciScopeConfig) TableName() string {
 	return "_tool_circleci_scope_configs"
 }
+
+func (t *CircleciScopeConfig) SetConnectionId(c *CircleciScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
diff --git a/backend/plugins/jenkins/api/init.go b/backend/plugins/jenkins/api/init.go
index ef3ccc2ae..08f78716f 100644
--- a/backend/plugins/jenkins/api/init.go
+++ b/backend/plugins/jenkins/api/init.go
@@ -31,7 +31,7 @@ var scopeHelper *api.ScopeApiHelper[models.JenkinsConnection, models.JenkinsJob,
 var remoteHelper *api.RemoteApiHelper[models.JenkinsConnection, models.JenkinsJob, models.Job, models.Job]
 
 var basicRes context.BasicRes
-var scHelper *api.ScopeConfigHelper[models.JenkinsScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.JenkinsScopeConfig, *models.JenkinsScopeConfig]
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 
@@ -62,7 +62,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scHelper = api.NewScopeConfigHelper[models.JenkinsScopeConfig](
+	scHelper = api.NewScopeConfigHelper[models.JenkinsScopeConfig, *models.JenkinsScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/jenkins/models/scope_config.go b/backend/plugins/jenkins/models/scope_config.go
index 35dbf3705..03e6c20b1 100644
--- a/backend/plugins/jenkins/models/scope_config.go
+++ b/backend/plugins/jenkins/models/scope_config.go
@@ -32,3 +32,8 @@ type JenkinsScopeConfig struct {
 func (t JenkinsScopeConfig) TableName() string {
 	return "_tool_jenkins_scope_configs"
 }
+
+func (t *JenkinsScopeConfig) SetConnectionId(c *JenkinsScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
diff --git a/backend/plugins/jira/api/init.go b/backend/plugins/jira/api/init.go
index ebb7b15fa..663742edf 100644
--- a/backend/plugins/jira/api/init.go
+++ b/backend/plugins/jira/api/init.go
@@ -31,7 +31,7 @@ var connectionHelper *api.ConnectionApiHelper
 var scopeHelper *api.ScopeApiHelper[models.JiraConnection, models.JiraBoard, models.JiraScopeConfig]
 var remoteHelper *api.RemoteApiHelper[models.JiraConnection, models.JiraBoard, apiv2models.Board, api.NoRemoteGroupResponse]
 var basicRes context.BasicRes
-var scHelper *api.ScopeConfigHelper[models.JiraScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.JiraScopeConfig, *models.JiraScopeConfig]
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 
@@ -63,7 +63,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scHelper = api.NewScopeConfigHelper[models.JiraScopeConfig](
+	scHelper = api.NewScopeConfigHelper[models.JiraScopeConfig, *models.JiraScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/jira/models/scope_config.go b/backend/plugins/jira/models/scope_config.go
index c8b0d18d0..a8143bee8 100644
--- a/backend/plugins/jira/models/scope_config.go
+++ b/backend/plugins/jira/models/scope_config.go
@@ -52,6 +52,11 @@ type JiraScopeConfig struct {
 	ApplicationType            string                 `mapstructure:"applicationType,omitempty" json:"applicationType" gorm:"type:varchar(255)"`
 }
 
+func (r *JiraScopeConfig) SetConnectionId(c *JiraScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
+
 func (r *JiraScopeConfig) Validate() errors.Error {
 	var err error
 	if r.RemotelinkCommitShaPattern != "" {
diff --git a/backend/plugins/tapd/api/init.go b/backend/plugins/tapd/api/init.go
index ec2024de1..774f8d370 100644
--- a/backend/plugins/tapd/api/init.go
+++ b/backend/plugins/tapd/api/init.go
@@ -30,7 +30,7 @@ var connectionHelper *api.ConnectionApiHelper
 var basicRes context.BasicRes
 var scopeHelper *api.ScopeApiHelper[models.TapdConnection, models.TapdWorkspace, models.TapdScopeConfig]
 var remoteHelper *api.RemoteApiHelper[models.TapdConnection, models.TapdWorkspace, models.TapdWorkspace, api.BaseRemoteGroupResponse]
-var scHelper *api.ScopeConfigHelper[models.TapdScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.TapdScopeConfig, *models.TapdScopeConfig]
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 
@@ -61,7 +61,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		vld,
 		connectionHelper,
 	)
-	scHelper = api.NewScopeConfigHelper[models.TapdScopeConfig](
+	scHelper = api.NewScopeConfigHelper[models.TapdScopeConfig, *models.TapdScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/tapd/models/scope_config.go b/backend/plugins/tapd/models/scope_config.go
index a5931ed1c..8f1b9027b 100644
--- a/backend/plugins/tapd/models/scope_config.go
+++ b/backend/plugins/tapd/models/scope_config.go
@@ -32,3 +32,8 @@ type TapdScopeConfig struct {
 func (t TapdScopeConfig) TableName() string {
 	return "_tool_tapd_scope_configs"
 }
+
+func (t *TapdScopeConfig) SetConnectionId(c *TapdScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
diff --git a/backend/plugins/trello/api/init.go b/backend/plugins/trello/api/init.go
index 223c5272a..08f295035 100644
--- a/backend/plugins/trello/api/init.go
+++ b/backend/plugins/trello/api/init.go
@@ -29,7 +29,7 @@ var vld *validator.Validate
 var connectionHelper *api.ConnectionApiHelper
 var scopeHelper *api.ScopeApiHelper[models.TrelloConnection, models.TrelloBoard, models.TrelloScopeConfig]
 var basicRes context.BasicRes
-var scHelper *api.ScopeConfigHelper[models.TrelloScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.TrelloScopeConfig, *models.TrelloScopeConfig]
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 	basicRes = br
@@ -53,7 +53,7 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 		params,
 		nil,
 	)
-	scHelper = api.NewScopeConfigHelper[models.TrelloScopeConfig](
+	scHelper = api.NewScopeConfigHelper[models.TrelloScopeConfig, *models.TrelloScopeConfig](
 		basicRes,
 		vld,
 		p.Name(),
diff --git a/backend/plugins/trello/models/scope_config.go b/backend/plugins/trello/models/scope_config.go
index 07885cc90..51b94ef1f 100644
--- a/backend/plugins/trello/models/scope_config.go
+++ b/backend/plugins/trello/models/scope_config.go
@@ -30,3 +30,8 @@ type TrelloScopeConfig struct {
 func (TrelloScopeConfig) TableName() string {
 	return "_tool_trello_scope_configs"
 }
+
+func (t *TrelloScopeConfig) SetConnectionId(c *TrelloScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}
diff --git a/backend/plugins/zentao/api/init.go b/backend/plugins/zentao/api/init.go
index 72d1e1027..3b14327c9 100644
--- a/backend/plugins/zentao/api/init.go
+++ b/backend/plugins/zentao/api/init.go
@@ -38,7 +38,7 @@ var projectScopeHelper *api.ScopeApiHelper[models.ZentaoConnection, models.Zenta
 
 var projectRemoteHelper *api.RemoteApiHelper[models.ZentaoConnection, models.ZentaoProject, models.ZentaoProject, api.BaseRemoteGroupResponse]
 var basicRes context.BasicRes
-var scHelper *api.ScopeConfigHelper[models.ZentaoScopeConfig]
+var scHelper *api.ScopeConfigHelper[models.ZentaoScopeConfig, *models.ZentaoScopeConfig]
 
 func Init(br context.BasicRes, p plugin.PluginMeta) {
 
@@ -64,5 +64,5 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
 	)
 
 	projectRemoteHelper = api.NewRemoteHelper[models.ZentaoConnection, models.ZentaoProject, models.ZentaoProject, api.BaseRemoteGroupResponse](basicRes, vld, connectionHelper)
-	scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig](basicRes, vld, p.Name())
+	scHelper = api.NewScopeConfigHelper[models.ZentaoScopeConfig, *models.ZentaoScopeConfig](basicRes, vld, p.Name())
 }
diff --git a/backend/plugins/zentao/models/scope_config.go b/backend/plugins/zentao/models/scope_config.go
index 201b6b086..71cd2937e 100644
--- a/backend/plugins/zentao/models/scope_config.go
+++ b/backend/plugins/zentao/models/scope_config.go
@@ -34,3 +34,8 @@ type ZentaoScopeConfig struct {
 func (t ZentaoScopeConfig) TableName() string {
 	return "_tool_zentao_scope_configs"
 }
+
+func (t *ZentaoScopeConfig) SetConnectionId(c *ZentaoScopeConfig, connectionId uint64) {
+	c.ConnectionId = connectionId
+	c.ScopeConfig.ConnectionId = connectionId
+}