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

zhangliang2022 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 7974855b0 fix: GetBlueprintsBy* must take plugin name into account 
(#5504)
7974855b0 is described below

commit 7974855b06a88906ddbc374782485e228ddbfadf
Author: Keon Amini <[email protected]>
AuthorDate: Thu Jun 15 21:45:44 2023 -0500

    fix: GetBlueprintsBy* must take plugin name into account (#5504)
---
 backend/core/models/blueprint.go                          |  4 ++--
 backend/helpers/pluginhelper/api/scope_generic_helper.go  | 10 +++++-----
 backend/helpers/pluginhelper/services/blueprint_helper.go |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/backend/core/models/blueprint.go b/backend/core/models/blueprint.go
index 8f0b25d46..6bbc04ead 100644
--- a/backend/core/models/blueprint.go
+++ b/backend/core/models/blueprint.go
@@ -136,7 +136,7 @@ func (bp *Blueprint) UpdateSettings(settings 
*BlueprintSettings) errors.Error {
 }
 
 // GetScopes Gets all the scopes for a given connection for this blueprint. 
Returns an empty slice if none found.
-func (bp *Blueprint) GetScopes(connectionId uint64) 
([]*plugin.BlueprintScopeV200, errors.Error) {
+func (bp *Blueprint) GetScopes(connectionId uint64, pluginName string) 
([]*plugin.BlueprintScopeV200, errors.Error) {
        conns, err := bp.GetConnections()
        if err != nil {
                return nil, err
@@ -144,7 +144,7 @@ func (bp *Blueprint) GetScopes(connectionId uint64) 
([]*plugin.BlueprintScopeV20
        visited := map[string]any{}
        var result []*plugin.BlueprintScopeV200
        for _, conn := range conns {
-               if conn.ConnectionId != connectionId {
+               if conn.ConnectionId != connectionId || conn.Plugin != 
pluginName {
                        continue
                }
                for _, scope := range conn.Scopes {
diff --git a/backend/helpers/pluginhelper/api/scope_generic_helper.go 
b/backend/helpers/pluginhelper/api/scope_generic_helper.go
index c01e51432..904a72d55 100644
--- a/backend/helpers/pluginhelper/api/scope_generic_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_generic_helper.go
@@ -235,7 +235,7 @@ func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
GetScopes(input *plugin.ApiRes
                for id := range scopesById {
                        scopeIds = append(scopeIds, id)
                }
-               blueprintMap, err := 
gs.bpManager.GetBlueprintsByScopes(params.connectionId, scopeIds...)
+               blueprintMap, err := 
gs.bpManager.GetBlueprintsByScopes(params.connectionId, params.plugin, 
scopeIds...)
                if err != nil {
                        return nil, errors.Default.Wrap(err, fmt.Sprintf("error 
getting blueprints for scopes from connection %d", params.connectionId))
                }
@@ -277,7 +277,7 @@ func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
GetScope(input *plugin.ApiReso
        }
        scopeRes := apiScopes[0]
        if params.loadBlueprints {
-               blueprintMap, err := 
gs.bpManager.GetBlueprintsByScopes(params.connectionId, params.scopeId)
+               blueprintMap, err := 
gs.bpManager.GetBlueprintsByScopes(params.connectionId, params.plugin, 
params.scopeId)
                if err != nil {
                        return nil, errors.Default.Wrap(err, fmt.Sprintf("error 
getting blueprints for scope with scope ID %s", params.scopeId))
                }
@@ -319,7 +319,7 @@ func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
DeleteScope(input *plugin.ApiR
                if err != nil {
                        return errors.Default.Wrap(err, fmt.Sprintf("error 
deleting scope %s", params.scopeId))
                }
-               err = gs.updateBlueprints(params.connectionId, params.scopeId)
+               err = gs.updateBlueprints(params.connectionId, params.plugin, 
params.scopeId)
                if err != nil {
                        return err
                }
@@ -531,8 +531,8 @@ func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
validatePrimaryKeys(scopes []*
        return nil
 }
 
-func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
updateBlueprints(connectionId uint64, scopeId string) errors.Error {
-       blueprintsMap, err := gs.bpManager.GetBlueprintsByScopes(connectionId, 
scopeId)
+func (gs *GenericScopeApiHelper[Conn, Scope, Tr]) 
updateBlueprints(connectionId uint64, pluginName string, scopeId string) 
errors.Error {
+       blueprintsMap, err := gs.bpManager.GetBlueprintsByScopes(connectionId, 
pluginName, scopeId)
        if err != nil {
                return errors.Default.Wrap(err, fmt.Sprintf("error retrieving 
scope with scope ID %s", scopeId))
        }
diff --git a/backend/helpers/pluginhelper/services/blueprint_helper.go 
b/backend/helpers/pluginhelper/services/blueprint_helper.go
index 0ed7ba1a6..d88a98ce8 100644
--- a/backend/helpers/pluginhelper/services/blueprint_helper.go
+++ b/backend/helpers/pluginhelper/services/blueprint_helper.go
@@ -140,14 +140,14 @@ func (b *BlueprintManager) GetDbBlueprint(blueprintId 
uint64) (*models.Blueprint
 }
 
 // GetBlueprintsByScopes returns all blueprints that have these scopeIds and 
this connection Id
-func (b *BlueprintManager) GetBlueprintsByScopes(connectionId uint64, scopeIds 
...string) (map[string][]*models.Blueprint, errors.Error) {
+func (b *BlueprintManager) GetBlueprintsByScopes(connectionId uint64, 
pluginName string, scopeIds ...string) (map[string][]*models.Blueprint, 
errors.Error) {
        bps, _, err := b.GetDbBlueprints(&GetBlueprintQuery{})
        if err != nil {
                return nil, err
        }
        scopeMap := map[string][]*models.Blueprint{}
        for _, bp := range bps {
-               scopes, err := bp.GetScopes(connectionId)
+               scopes, err := bp.GetScopes(connectionId, pluginName)
                if err != nil {
                        return nil, err
                }

Reply via email to