Skip to content

fix: ci patch rbac for branch update #5759

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

Merged
merged 1 commit into from
Aug 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
"golang.org/x/exp/maps"
"io"
"net/http"
Expand Down Expand Up @@ -496,19 +495,13 @@ func (handler *PipelineConfigRestHandlerImpl) getCdPipelinesForCIPatchRbac(patch
// find the workflow in which we are patching and use the workflow id to fetch all the workflow mappings using the workflow.
// get cd pipeline ids from those workflows and fetch the cd pipelines.

// get the ciPipeline
switchFromPipelineId, switchFromType := patchRequest.SwitchSourceInfo()

// in app workflow mapping all the build source types are 'CI_PIPELINE' type, except external -> WEBHOOK.
componentType := appWorkflow.CIPIPELINE
if switchFromType == CiPipeline.EXTERNAL {
componentType = appWorkflow.WEBHOOK
}
// get the ciPipeline patch source info
componentId, componentType := patchRequest.PatchSourceInfo()

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

Expand Down
18 changes: 18 additions & 0 deletions pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ func (ciPatchRequest CiPatchRequest) SwitchSourceInfo() (int, CiPipeline2.Pipeli
return switchFromPipelineId, switchFromType
}

// PatchSourceInfo returns the CI component ID and component Type, which is being patched
func (ciPatchRequest CiPatchRequest) PatchSourceInfo() (int, string) {
// in app workflow mapping all the build source types are 'CI_PIPELINE' type, except external -> WEBHOOK.
componentType := appWorkflow.CIPIPELINE
var componentId int
// initialize componentId with ciPipeline id
if ciPatchRequest.CiPipeline != nil {
componentId = ciPatchRequest.CiPipeline.Id
}
if ciPatchRequest.SwitchFromExternalCiPipelineId != 0 {
componentType = appWorkflow.WEBHOOK
componentId = ciPatchRequest.SwitchFromExternalCiPipelineId
} else if ciPatchRequest.SwitchFromCiPipelineId != 0 {
componentId = ciPatchRequest.SwitchFromCiPipelineId
}
return componentId, componentType
}

func (ciPatchRequest CiPatchRequest) IsSwitchCiPipelineRequest() bool {
return (ciPatchRequest.SwitchFromCiPipelineId != 0 || ciPatchRequest.SwitchFromExternalCiPipelineId != 0)
}
Expand Down
Loading