Skip to content

Commit

Permalink
feat(api): workflow search add ascode filter (#6299)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Sep 22, 2022
1 parent f9d2ee9 commit d8b83bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 0 additions & 2 deletions engine/api/auth_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ func initBuiltinConsumersFromStartupConfig(ctx context.Context, tx gorpmapper.Sq
scopes = sdk.NewAuthConsumerScopeDetails(sdk.AuthConsumerScopeService, sdk.AuthConsumerScopeRunExecution)
case StartupConfigConsumerTypeCDNStorageCDS:
scopes = sdk.NewAuthConsumerScopeDetails(sdk.AuthConsumerScopeProject, sdk.AuthConsumerScopeRun)
case StartupConfigConsumerTypeVCS:
scopes = sdk.NewAuthConsumerScopeDetails(sdk.AuthConsumerScopeService, sdk.AuthConsumerScopeProject, sdk.AuthConsumerScopeRun)
case StartupConfigConsumerTypeRepositories:
scopes = sdk.NewAuthConsumerScopeDetails(sdk.AuthConsumerScopeService, sdk.AuthConsumerScopeProject, sdk.AuthConsumerScopeRun)
default:
Expand Down
1 change: 1 addition & 0 deletions engine/api/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ func (api *API) getSearchWorkflowHandler() service.Handler {
dao.Filters.WorkflowName = FormString(r, "name")
dao.Filters.VCSServer = FormString(r, "vcs")
dao.Filters.ApplicationRepository = FormString(r, "repository")
dao.Filters.AsCode = service.FormBool(r, "ascode")
dao.Loaders.WithRuns = service.FormInt(r, "runs")
dao.Loaders.WithFavoritesForUserID = getAPIConsumer(ctx).AuthentifiedUserID

Expand Down
20 changes: 13 additions & 7 deletions engine/api/workflow/factory_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workflow
import (
"context"
"fmt"
"strings"
"time"

"github.com/go-gorp/gorp"
Expand Down Expand Up @@ -72,6 +73,7 @@ type LoadAllWorkflowsOptionsFilters struct {
GroupIDs []int64
WorkflowIDs []int64
DisableFilterDeletedWorkflow bool
AsCode bool
}

type LoadAllWorkflowsOptionsLoaders struct {
Expand Down Expand Up @@ -169,17 +171,21 @@ func (dao WorkflowDAO) Query() gorpmapping.Query {
args = append(args, pq.Int64Array(dao.Filters.WorkflowIDs))
}

queryFilters := make([]string, 0, len(filters))
for i, f := range filters {
if i == 0 {
queryString += " WHERE "
} else {
queryString += " AND "
}
queryString += fmt.Sprintf(f, i+1)
queryFilters = append(queryFilters, fmt.Sprintf(f, i+1))
}

if !dao.Filters.DisableFilterDeletedWorkflow {
queryString += " AND workflow.to_delete = false"
queryFilters = append(queryFilters, "workflow.to_delete = false")
}

if dao.Filters.AsCode {
queryFilters = append(queryFilters, "workflow.from_repository <> ''")
}

if len(queryFilters) > 0 {
queryString += "WHERE " + strings.Join(queryFilters, " AND ")
}

var order = " ORDER BY selected_workflow.projectkey, selected_workflow.workflow_name "
Expand Down

0 comments on commit d8b83bd

Please sign in to comment.