From 313724b541865988b825cebc9ff2185162a044ea Mon Sep 17 00:00:00 2001 From: abeizn Date: Thu, 13 Jul 2023 15:59:24 +0800 Subject: [PATCH 1/2] feat: allow Data Scope search when creating a Blueprint in the user flow --- backend/helpers/pluginhelper/api/scope_db_helper.go | 7 ++++++- backend/plugins/bamboo/api/scope.go | 1 + backend/plugins/bitbucket/api/scope.go | 1 + backend/plugins/github/api/scope.go | 1 + backend/plugins/gitlab/api/scope.go | 1 + backend/plugins/jenkins/api/scope.go | 1 + backend/plugins/jira/api/scope.go | 1 + backend/plugins/pagerduty/api/scope.go | 1 + backend/plugins/sonarqube/api/scope.go | 1 + backend/plugins/tapd/api/scope.go | 1 + backend/plugins/trello/api/scope.go | 1 + backend/plugins/zentao/api/project_scope.go | 1 + 12 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/helpers/pluginhelper/api/scope_db_helper.go b/backend/helpers/pluginhelper/api/scope_db_helper.go index c5ba22e5065..8ff929ce06f 100644 --- a/backend/helpers/pluginhelper/api/scope_db_helper.go +++ b/backend/helpers/pluginhelper/api/scope_db_helper.go @@ -113,9 +113,14 @@ func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) GetScopeAndConfig(connectionI } func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) ListScopes(input *plugin.ApiResourceInput, connectionId uint64) ([]*Scope, errors.Error) { + searchTerm := input.Query.Get("searchTerm") + query := dal.Where("connection_id = ?", connectionId) + if searchTerm != "" { + query = dal.Where(fmt.Sprintf("connection_id = ? AND ? LIKE %s", s.params.RawScopeParamName), connectionId, searchTerm) + } limit, offset := GetLimitOffset(input.Query, "pageSize", "page") var scopes []*Scope - err := s.db.All(&scopes, dal.Where("connection_id = ?", connectionId), dal.Limit(limit), dal.Offset(offset)) + err := s.db.All(&scopes, query, dal.Limit(limit), dal.Offset(offset)) return scopes, err } diff --git a/backend/plugins/bamboo/api/scope.go b/backend/plugins/bamboo/api/scope.go index 62172865c11..beffd29fa32 100644 --- a/backend/plugins/bamboo/api/scope.go +++ b/backend/plugins/bamboo/api/scope.go @@ -67,6 +67,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Bamboo projects // @Tags plugins/bamboo // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" // @Success 200 {object} []ScopeRes // @Failure 400 {object} shared.ApiBody "Bad Request" diff --git a/backend/plugins/bitbucket/api/scope.go b/backend/plugins/bitbucket/api/scope.go index 1639fa96a63..1ba10804ef5 100644 --- a/backend/plugins/bitbucket/api/scope.go +++ b/backend/plugins/bitbucket/api/scope.go @@ -70,6 +70,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get repos // @Tags plugins/bitbucket // @Param connectionId path int true "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/github/api/scope.go b/backend/plugins/github/api/scope.go index 8ca575a1179..8df469f7d53 100644 --- a/backend/plugins/github/api/scope.go +++ b/backend/plugins/github/api/scope.go @@ -67,6 +67,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Github repos // @Tags plugins/github // @Param connectionId path int true "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/gitlab/api/scope.go b/backend/plugins/gitlab/api/scope.go index 705ca6c2ef8..42ceb761063 100644 --- a/backend/plugins/gitlab/api/scope.go +++ b/backend/plugins/gitlab/api/scope.go @@ -67,6 +67,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Gitlab projects // @Tags plugins/gitlab // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" // @Success 200 {object} []ScopeRes // @Failure 400 {object} shared.ApiBody "Bad Request" diff --git a/backend/plugins/jenkins/api/scope.go b/backend/plugins/jenkins/api/scope.go index f1165bb1ee0..21e07c8f343 100644 --- a/backend/plugins/jenkins/api/scope.go +++ b/backend/plugins/jenkins/api/scope.go @@ -70,6 +70,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Jenkins jobs // @Tags plugins/jenkins // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/jira/api/scope.go b/backend/plugins/jira/api/scope.go index b76893bfa0d..d1ad1e68716 100644 --- a/backend/plugins/jira/api/scope.go +++ b/backend/plugins/jira/api/scope.go @@ -45,6 +45,7 @@ type ScopeReq api.ScopeReq[models.JiraBoard] // @Tags plugins/jira // @Accept application/json // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param scope body ScopeReq true "json" // @Success 200 {object} []models.JiraBoard // @Failure 400 {object} shared.ApiBody "Bad Request" diff --git a/backend/plugins/pagerduty/api/scope.go b/backend/plugins/pagerduty/api/scope.go index 871de3d650e..b9c8dfce9e8 100644 --- a/backend/plugins/pagerduty/api/scope.go +++ b/backend/plugins/pagerduty/api/scope.go @@ -67,6 +67,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get PagerDuty repos // @Tags plugins/pagerduty // @Param connectionId path int true "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/sonarqube/api/scope.go b/backend/plugins/sonarqube/api/scope.go index e31f36ddd1c..4b0e11f7481 100644 --- a/backend/plugins/sonarqube/api/scope.go +++ b/backend/plugins/sonarqube/api/scope.go @@ -66,6 +66,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Sonarqube projects // @Tags plugins/sonarqube // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/tapd/api/scope.go b/backend/plugins/tapd/api/scope.go index 54da0d3f8f8..67319411323 100644 --- a/backend/plugins/tapd/api/scope.go +++ b/backend/plugins/tapd/api/scope.go @@ -69,6 +69,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get tapd jobs // @Tags plugins/tapd // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" diff --git a/backend/plugins/trello/api/scope.go b/backend/plugins/trello/api/scope.go index 94aa605de57..83876f51dd3 100644 --- a/backend/plugins/trello/api/scope.go +++ b/backend/plugins/trello/api/scope.go @@ -66,6 +66,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err // @Description get Trello boards // @Tags plugins/trello // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param pageSize query int false "page size, default 50" // @Param page query int false "page size, default 1" // @Success 200 {object} []models.TrelloBoard diff --git a/backend/plugins/zentao/api/project_scope.go b/backend/plugins/zentao/api/project_scope.go index 24e9703f6a2..a82e95652d9 100644 --- a/backend/plugins/zentao/api/project_scope.go +++ b/backend/plugins/zentao/api/project_scope.go @@ -67,6 +67,7 @@ func UpdateProjectScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp // @Description get Gitlab projects // @Tags plugins/gitlab // @Param connectionId path int false "connection ID" +// @Param searchTerm query string false "search term for scope name" // @Param blueprints query bool false "also return blueprints using these scopes as part of the payload" // @Success 200 {object} []ProjectScopeRes // @Failure 400 {object} shared.ApiBody "Bad Request" From 37093db702bd97bee0462eb1bfa52d69575fe44f Mon Sep 17 00:00:00 2001 From: abeizn Date: Thu, 13 Jul 2023 18:41:18 +0800 Subject: [PATCH 2/2] fix: sql usage --- backend/helpers/pluginhelper/api/scope_db_helper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/helpers/pluginhelper/api/scope_db_helper.go b/backend/helpers/pluginhelper/api/scope_db_helper.go index 8ff929ce06f..d5613367343 100644 --- a/backend/helpers/pluginhelper/api/scope_db_helper.go +++ b/backend/helpers/pluginhelper/api/scope_db_helper.go @@ -116,7 +116,8 @@ func (s *ScopeDatabaseHelperImpl[Conn, Scope, Tr]) ListScopes(input *plugin.ApiR searchTerm := input.Query.Get("searchTerm") query := dal.Where("connection_id = ?", connectionId) if searchTerm != "" { - query = dal.Where(fmt.Sprintf("connection_id = ? AND ? LIKE %s", s.params.RawScopeParamName), connectionId, searchTerm) + query = dal.Where(fmt.Sprintf("connection_id = ? AND %s LIKE ?", s.params.RawScopeParamName), connectionId, "%"+searchTerm+"%") + } limit, offset := GetLimitOffset(input.Query, "pageSize", "page") var scopes []*Scope