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

[#LFX3038] Feature/Project Heirachy #2685

Merged
merged 1 commit into from
Feb 19, 2021
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
1 change: 1 addition & 0 deletions cla-backend-go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ github.com/communitybridge/easycla v1.0.107 h1:dktHAji1yJ1nMEu54z4paPWOM4Q7A9rry
github.com/communitybridge/easycla v1.0.117 h1:o+rdmcNgZeMQ/N8HV/d5apNIBrkYH7eyM9UUYnEzewo=
github.com/communitybridge/easycla v1.0.118 h1:8yrsOQ+ENUFi4RFl1krRlIxc51lzZNutidR+yy2HwW0=
github.com/communitybridge/easycla v1.0.123 h1:Lh5i/9aajrTYItxNpVCmi9T1yyIfnQIOk0tC2Wtslvk=
github.com/communitybridge/easycla v1.0.133 h1:aJulQGLLRISCMsZcCP4aIE8xGtHoBNm/EmA00n3NYVA=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down
37 changes: 26 additions & 11 deletions cla-backend-go/v2/cla_groups/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,19 @@ func (s *service) validateEnrollProjectsInput(ctx context.Context, foundationSFI
return err
}

// Let's check the foundation provided - does it have a parent? Only allowed parent is TLF
if foundationProjectDetails.Parent != "" && !isLFParent {
log.WithFields(f).Warnf("input validation failure - foundation_sfid of %s has a parent other than %s or %s which is: %s",
foundationSFID, utils.TheLinuxFoundation, utils.LFProjectsLLC, foundationProjectDetails.Parent)
return fmt.Errorf("bad request: input validation failure - foundation_sfid of %s has a parent other than %s or %s which is: %s",
foundationSFID, utils.TheLinuxFoundation, utils.LFProjectsLLC, foundationProjectDetails.Parent)
for _, projectSFID := range projectSFIDList {
projectDetails, projErr := psc.GetProject(projectSFID)
if projErr != nil {
return err
}

if foundationProjectDetails.Parent != "" && (!isLFParent && (foundationProjectDetails.ProjectType == utils.ProjectTypeProjectGroup && projectDetails.ProjectType != utils.ProjectTypeProjectGroup)) {
msg := fmt.Sprintf("input validation failure - foundationSFID: %s , foundationType: %s , projectSFID: %s , projectType: %s ",
foundationProjectDetails.Parent, foundationProjectDetails.ProjectType, projectSFID, projectDetails.ProjectType)
log.WithFields(f).Warnf(msg)
return fmt.Errorf(msg)
}

}

// Comment out the below as we want to support stand-alone projects
Expand Down Expand Up @@ -308,11 +315,19 @@ func (s *service) validateUnenrollProjectsInput(ctx context.Context, foundationS
return err
}

if foundationProjectDetails.Parent != "" && !isLFParent {
log.WithFields(f).Warnf("input validation failure - foundation_sfid of %s has a parent other than %s or %s which is: %s",
foundationSFID, utils.TheLinuxFoundation, utils.LFProjectsLLC, foundationProjectDetails.Parent)
return fmt.Errorf("bad request: input validation failure - foundation_sfid of %s has a parent other than %s or %s which is: %s",
foundationSFID, utils.TheLinuxFoundation, utils.LFProjectsLLC, foundationProjectDetails.Parent)
for _, projectSFID := range projectSFIDList {
projectDetails, projErr := psc.GetProject(projectSFID)
if projErr != nil {
return err
}

if foundationProjectDetails.Parent != "" && (!isLFParent && (foundationProjectDetails.ProjectType == utils.ProjectTypeProjectGroup && projectDetails.ProjectType != utils.ProjectTypeProjectGroup)) {
msg := fmt.Sprintf("input validation failure - foundationSFID: %s , foundationType: %s , projectSFID: %s , projectType: %s ",
foundationProjectDetails.Parent, foundationProjectDetails.ProjectType, projectSFID, projectDetails.ProjectType)
log.WithFields(f).Warnf(msg)
return fmt.Errorf(msg)
}

}

// Comment out the below as we want to support stand-alone projects
Expand Down
26 changes: 23 additions & 3 deletions cla-backend-go/v2/cla_groups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/communitybridge/easycla/cla-backend-go/projects_cla_groups"
v1Template "github.com/communitybridge/easycla/cla-backend-go/template"
v2ProjectService "github.com/communitybridge/easycla/cla-backend-go/v2/project-service"
v2ProjectServiceModels "github.com/communitybridge/easycla/cla-backend-go/v2/project-service/models"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -340,7 +341,7 @@ func (s *service) UpdateCLAGroup(ctx context.Context, claGroupModel *v1Models.Cl
}

// ListClaGroupsForFoundationOrProject returns the CLA Group list for the specified foundation ID
func (s *service) ListClaGroupsForFoundationOrProject(ctx context.Context, projectOrFoundationSFID string) (*models.ClaGroupListSummary, error) {
func (s *service) ListClaGroupsForFoundationOrProject(ctx context.Context, projectOrFoundationSFID string) (*models.ClaGroupListSummary, error) { // nolint
f := logrus.Fields{
"functionName": "ListClaGroupsForFoundationOrProject",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
Expand All @@ -365,12 +366,31 @@ func (s *service) ListClaGroupsForFoundationOrProject(ctx context.Context, proje
return nil, &utils.SFProjectNotFound{ProjectSFID: projectOrFoundationSFID}
}

// Try and check if parent exists and projectType
var parentDetails *v2ProjectServiceModels.ProjectOutputDetailed
var parentDetailErr error

if sfProjectModelDetails.Parent != "" {
var parentSFID string
// Use utility function that considers TLF and LF Projects, LLC
parentSFID, parentDetailErr = v2ProjectService.GetClient().GetParentProject(projectOrFoundationSFID)
if parentDetailErr != nil {
return nil, parentDetailErr
}

// Get Parent
parentDetails, parentDetailErr = v2ProjectService.GetClient().GetProject(parentSFID)
if parentDetailErr != nil {
return nil, parentDetailErr
}
}

// Lookup the foundation name - need this if we were a project - need to lookup parent ID/Name
var foundationID = sfProjectModelDetails.ID
var foundationName = sfProjectModelDetails.Name

// If it's a project...
if sfProjectModelDetails.ProjectType == utils.ProjectTypeProject {
if sfProjectModelDetails.ProjectType == utils.ProjectTypeProject || (parentDetails != nil && (parentDetails.ProjectType == utils.ProjectTypeProjectGroup && sfProjectModelDetails.ProjectType == utils.ProjectTypeProjectGroup)) {
// Since this is a project and not a foundation, we'll want to set he parent foundation ID and name (which is
// our parent in this case)
log.WithFields(f).Debug("found 'project' in platform project service.")
Expand Down Expand Up @@ -413,7 +433,7 @@ func (s *service) ListClaGroupsForFoundationOrProject(ctx context.Context, proje
v1ClaGroups.Projects = append(v1ClaGroups.Projects, *v1CLAGroupData)
}

} else if sfProjectModelDetails.ProjectType == utils.ProjectTypeProjectGroup {
} else if parentDetails != nil && (parentDetails.ProjectType == utils.ProjectTypeProjectGroup && sfProjectModelDetails.ProjectType != utils.ProjectTypeProjectGroup) {
log.WithFields(f).Debug("found 'project group' in platform project service. Locating CLA Groups for foundation...")
projectCLAGroups, lookupErr := s.projectsClaGroupsRepo.GetProjectsIdsForFoundation(projectOrFoundationSFID)
if lookupErr != nil {
Expand Down