Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): workflow search add ascode filter #6299

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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