Skip to content

Commit 6da544f

Browse files
authored
fix: ci patch rbac for branch update (#5759)
1 parent 8a61bac commit 6da544f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24-
"github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
2524
"golang.org/x/exp/maps"
2625
"io"
2726
"net/http"
@@ -496,19 +495,13 @@ func (handler *PipelineConfigRestHandlerImpl) getCdPipelinesForCIPatchRbac(patch
496495
// find the workflow in which we are patching and use the workflow id to fetch all the workflow mappings using the workflow.
497496
// get cd pipeline ids from those workflows and fetch the cd pipelines.
498497

499-
// get the ciPipeline
500-
switchFromPipelineId, switchFromType := patchRequest.SwitchSourceInfo()
501-
502-
// in app workflow mapping all the build source types are 'CI_PIPELINE' type, except external -> WEBHOOK.
503-
componentType := appWorkflow.CIPIPELINE
504-
if switchFromType == CiPipeline.EXTERNAL {
505-
componentType = appWorkflow.WEBHOOK
506-
}
498+
// get the ciPipeline patch source info
499+
componentId, componentType := patchRequest.PatchSourceInfo()
507500

508501
// the appWorkflowId can be taken from patchRequest.AppWorkflowId but doing this can make 2 sources of truth to find the workflow
509-
sourceAppWorkflowMapping, err := handler.appWorkflowService.FindWFMappingByComponent(componentType, switchFromPipelineId)
502+
sourceAppWorkflowMapping, err := handler.appWorkflowService.FindWFMappingByComponent(componentType, componentId)
510503
if err != nil {
511-
handler.Logger.Errorw("error in finding the appWorkflowMapping using componentId and componentType", "componentType", componentType, "componentId", switchFromPipelineId, "err", err)
504+
handler.Logger.Errorw("error in finding the appWorkflowMapping using componentId and componentType", "componentType", componentType, "componentId", componentId, "err", err)
512505
return nil, err
513506
}
514507

pkg/bean/app.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,24 @@ func (ciPatchRequest CiPatchRequest) SwitchSourceInfo() (int, CiPipeline2.Pipeli
315315
return switchFromPipelineId, switchFromType
316316
}
317317

318+
// PatchSourceInfo returns the CI component ID and component Type, which is being patched
319+
func (ciPatchRequest CiPatchRequest) PatchSourceInfo() (int, string) {
320+
// in app workflow mapping all the build source types are 'CI_PIPELINE' type, except external -> WEBHOOK.
321+
componentType := appWorkflow.CIPIPELINE
322+
var componentId int
323+
// initialize componentId with ciPipeline id
324+
if ciPatchRequest.CiPipeline != nil {
325+
componentId = ciPatchRequest.CiPipeline.Id
326+
}
327+
if ciPatchRequest.SwitchFromExternalCiPipelineId != 0 {
328+
componentType = appWorkflow.WEBHOOK
329+
componentId = ciPatchRequest.SwitchFromExternalCiPipelineId
330+
} else if ciPatchRequest.SwitchFromCiPipelineId != 0 {
331+
componentId = ciPatchRequest.SwitchFromCiPipelineId
332+
}
333+
return componentId, componentType
334+
}
335+
318336
func (ciPatchRequest CiPatchRequest) IsSwitchCiPipelineRequest() bool {
319337
return (ciPatchRequest.SwitchFromCiPipelineId != 0 || ciPatchRequest.SwitchFromExternalCiPipelineId != 0)
320338
}

0 commit comments

Comments
 (0)