Skip to content

Commit

Permalink
Updated Create CLA Group Logic (#3811)
Browse files Browse the repository at this point in the history
  • Loading branch information
dealako authored Feb 24, 2023
1 parent cd0b874 commit 64c80ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cla-backend-go/v2/cla_groups/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (s *service) validateEnrollProjectsInput(ctx context.Context, foundationSFI
projectTree := buildProjectNode(foundationProjectSummary)
log.WithFields(f).Debugf("projectTree: %+v", projectTree)

invalidSiblingProjects := []string{}
var invalidSiblingProjects []string
// Check to see if CLAGroup at ProjectLevel has no siblings
if projectLevel {
log.WithFields(f).Debugf("checking to see if CLAGroup at ProjectLevel has no siblings...")
Expand Down
16 changes: 12 additions & 4 deletions cla-backend-go/v2/cla_groups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1037,8 +1037,16 @@ func (s *service) EnrollProjectsInClaGroup(ctx context.Context, request *EnrollP
"projectSFIDList": strings.Join(request.ProjectSFIDList, ","),
}

// We have two options - ask the UI to strip out any LF parent projects or we do it here
// In the interest of time, we'll do it here
psc := v2ProjectService.GetClient()
updatedProjectSFIDList := psc.RemoveLinuxFoundationParentsFromProjectList(request.ProjectSFIDList)
if len(updatedProjectSFIDList) != len(request.ProjectSFIDList) {
log.WithFields(f).Debugf("removed %d linux foundation parent projects from project list", len(request.ProjectSFIDList)-len(updatedProjectSFIDList))
}

log.WithFields(f).Debug("validating enroll project input")
err := s.validateEnrollProjectsInput(ctx, request.FoundationSFID, request.ProjectSFIDList, request.ProjectLevel, request.CLAGroupProjects)
err := s.validateEnrollProjectsInput(ctx, request.FoundationSFID, updatedProjectSFIDList, request.ProjectLevel, request.CLAGroupProjects)
if err != nil {
return &utils.EnrollValidationError{
Type: "enroll",
Expand Down Expand Up @@ -1066,7 +1074,7 @@ func (s *service) EnrollProjectsInClaGroup(ctx context.Context, request *EnrollP
log.WithFields(f).WithError(enrollErr).Warn("enrolling projects in CLA Group failed")
errorList = append(errorList, enrollErr)
}
}(ctx, request.AuthUser, request.CLAGroupID, request.FoundationSFID, request.ProjectSFIDList)
}(ctx, request.AuthUser, request.CLAGroupID, request.FoundationSFID, updatedProjectSFIDList)

// Separate go routine for enabling the CLA Service in the project service
go func(c context.Context, claGroupID string, projSFIDList []string) {
Expand All @@ -1078,14 +1086,14 @@ func (s *service) EnrollProjectsInClaGroup(ctx context.Context, request *EnrollP
log.WithFields(f).WithError(errEnableCLA).Warn("enabling CLA service in platform project service failed")
errorList = append(errorList, errEnableCLA)
}
}(ctx, request.CLAGroupID, request.ProjectSFIDList)
}(ctx, request.CLAGroupID, updatedProjectSFIDList)

// Wait until all go routines are done
wg.Wait()
if len(errorList) > 0 {
return &utils.EnrollError{
Type: "enroll",
Message: fmt.Sprintf("encountered %d errors when enrolling and disabling CLA service for %d projects", len(errorList), len(request.ProjectSFIDList)),
Message: fmt.Sprintf("encountered %d errors when enrolling and disabling CLA service for %d projects", len(errorList), len(updatedProjectSFIDList)),
Err: errorList[0],
}
}
Expand Down
12 changes: 12 additions & 0 deletions cla-backend-go/v2/project-service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,15 @@ func (pmm *Client) IsAnyProjectTheRootParent(sliceProjectSFID []string) bool {

return retVal
}

// RemoveLinuxFoundationParentsFromProjectList removes any Linux Foundation root/parent projects from the list
func (pmm *Client) RemoveLinuxFoundationParentsFromProjectList(projectList []string) []string {
var filteredProjectList []string
for _, projectSFID := range projectList {
// If not one of our Linux Foundation root/parent projects, then add it to the list
if isTLF, err := pmm.IsTheLinuxFoundation(projectSFID); !isTLF && err == nil {
filteredProjectList = append(filteredProjectList, projectSFID)
}
}
return filteredProjectList
}

0 comments on commit 64c80ed

Please sign in to comment.