Skip to content

Commit

Permalink
fix(api): take care of integration model requirements for region check (
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Nov 22, 2021
1 parent 3641057 commit 4421b59
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
6 changes: 4 additions & 2 deletions engine/api/environment_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ func (api *API) importNewEnvironmentHandler() service.Handler {
vars := mux.Vars(r)
key := vars[permProjectKey]

proj, err := project.Load(ctx, api.mustDB(), key, project.LoadOptions.Default,
project.LoadOptions.WithGroups, project.LoadOptions.WithPermission)
proj, err := project.Load(ctx, api.mustDB(), key,
project.LoadOptions.Default,
project.LoadOptions.WithGroups,
)
if err != nil {
return sdk.WrapError(err, "cannot load %s", key)
}
Expand Down
25 changes: 10 additions & 15 deletions engine/api/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (api *API) getProjectsHandler_FilterByRepo(ctx context.Context, w http.Resp
}

opts := []project.LoadOptionFunc{
project.LoadOptions.WithPermission,
project.LoadOptions.WithApplications,
project.LoadOptions.WithWorkflows,
}
Expand Down Expand Up @@ -139,10 +138,7 @@ func (api *API) getProjectsHandler() service.Handler {
}
}

opts := []project.LoadOptionFunc{
project.LoadOptions.WithPermission,
}

var opts []project.LoadOptionFunc
if withIcon {
opts = append(opts, project.LoadOptions.WithIcon)
}
Expand Down Expand Up @@ -273,7 +269,6 @@ func (api *API) getProjectHandler() service.Handler {
withEnvironments := service.FormBool(r, "withEnvironments")
withEnvironmentNames := service.FormBool(r, "withEnvironmentNames")
withGroups := service.FormBool(r, "withGroups")
withPermission := service.FormBool(r, "withPermission")
withKeys := service.FormBool(r, "withKeys")
withWorkflows := service.FormBool(r, "withWorkflows")
withWorkflowNames := service.FormBool(r, "withWorkflowNames")
Expand Down Expand Up @@ -308,9 +303,6 @@ func (api *API) getProjectHandler() service.Handler {
if withGroups {
opts = append(opts, project.LoadOptions.WithGroups)
}
if withPermission {
opts = append(opts, project.LoadOptions.WithPermission)
}
if withKeys {
opts = append(opts, project.LoadOptions.WithKeys)
}
Expand Down Expand Up @@ -432,12 +424,16 @@ func (api *API) putProjectLabelsHandler() service.Handler {
return sdk.WithStack(err)
}

p, errP := project.Load(ctx, db, key,
project.LoadOptions.WithLabels, project.LoadOptions.WithWorkflowNames, project.LoadOptions.WithVariables,
p, err := project.Load(ctx, db, key,
project.LoadOptions.WithLabels,
project.LoadOptions.WithWorkflowNames,
project.LoadOptions.WithVariables,
project.LoadOptions.WithFavorites(getAPIConsumer(ctx).AuthentifiedUser.ID),
project.LoadOptions.WithKeys, project.LoadOptions.WithPermission, project.LoadOptions.WithIntegrations)
if errP != nil {
return sdk.WrapError(errP, "putProjectLabelsHandler> Cannot load project updated from db")
project.LoadOptions.WithKeys,
project.LoadOptions.WithIntegrations,
)
if err != nil {
return sdk.WrapError(err, "cannot load project updated from db")
}

p.Permissions.Readable = true
Expand Down Expand Up @@ -605,7 +601,6 @@ func (api *API) postProjectHandler() service.Handler {
project.LoadOptions.WithWorkflowNames,
project.LoadOptions.WithFavorites(consumer.AuthentifiedUser.ID),
project.LoadOptions.WithKeys,
project.LoadOptions.WithPermission,
project.LoadOptions.WithIntegrations,
project.LoadOptions.WithVariables,
)
Expand Down
1 change: 0 additions & 1 deletion engine/api/project/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var LoadOptions = struct {
WithEnvironments LoadOptionFunc
WithEnvironmentNames LoadOptionFunc
WithGroups LoadOptionFunc
WithPermission LoadOptionFunc
WithApplicationVariables LoadOptionFunc
WithApplicationKeys LoadOptionFunc
WithApplicationWithDeploymentStrategies LoadOptionFunc
Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow/execute_node_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ jobLoop:
}

if exist := featureflipping.Exists(ctx, gorpmapping.Mapper, db, sdk.FeatureRegion); exist {
if err := checkJobRegion(ctx, db, wr.Workflow.ProjectKey, wr.Workflow.Name, *job); err != nil {
if err := checkJobRegion(ctx, db, wr.Workflow.ProjectKey, wr.Workflow.Name, jobRequirements); err != nil {
spawnErrs.Append(sdk.ErrRegionNotAllowed)
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine/api/workflow/run_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func CheckRegion(ctx context.Context, db gorp.SqlExecutor, wf sdk.Workflow) erro
for _, p := range wf.Pipelines {
for _, s := range p.Stages {
for _, j := range s.Jobs {
if err := checkJobRegion(ctx, db, wf.ProjectKey, wf.Name, j); err != nil {
if err := checkJobRegion(ctx, db, wf.ProjectKey, wf.Name, j.Action.Requirements); err != nil {
return err
}
}
Expand All @@ -213,8 +213,8 @@ func CheckRegion(ctx context.Context, db gorp.SqlExecutor, wf sdk.Workflow) erro
return nil
}

func checkJobRegion(ctx context.Context, db gorp.SqlExecutor, projKey, wName string, j sdk.Job) error {
for _, req := range j.Action.Requirements {
func checkJobRegion(ctx context.Context, db gorp.SqlExecutor, projKey, wName string, jobRequirements sdk.RequirementList) error {
for _, req := range jobRequirements {
if req.Type != sdk.RegionRequirement {
continue
}
Expand Down
6 changes: 2 additions & 4 deletions ui/src/app/service/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ export class ProjectService {

if (Array.isArray(opts) && opts.length) {
opts = opts.concat([
new LoadOpts('withGroups', 'groups'),
new LoadOpts('withPermission', 'permission')
new LoadOpts('withGroups', 'groups')
]);
} else {
opts = [
new LoadOpts('withGroups', 'groups'),
new LoadOpts('withPermission', 'permission')
new LoadOpts('withGroups', 'groups')
];
}
opts.push(new LoadOpts('withFeatures', 'features'));
Expand Down

0 comments on commit 4421b59

Please sign in to comment.