Skip to content

Commit

Permalink
Merge pull request #4271 from nickmango/bug/add-ldap-group
Browse files Browse the repository at this point in the history
[#4240] Bug/LDAP Gerrit LDAP group addition
  • Loading branch information
nickmango committed Mar 14, 2024
2 parents 108b7b3 + e0599c3 commit 276cae1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
2 changes: 0 additions & 2 deletions cla-backend-go/gerrits/lf_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ func (lfg *LFGroup) AddUserToGroup(ctx context.Context, authUser *auth.User, cla
"claGroupID": claGroupID,
"groupName": groupName,
"userName": userName,
"authUserName": authUser.UserName,
"authUserEmail": authUser.Email,
}

log.WithFields(f).Debug("adding user to group...")
Expand Down
2 changes: 0 additions & 2 deletions cla-backend-go/gerrits/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,6 @@ func (s service) AddUserToGroup(ctx context.Context, authUser *auth.User, claGro
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
"claGroupID": claGroupID,
"userName": userName,
"authUserName": authUser.UserName,
"authUserEmail": authUser.Email,
}

log.WithFields(f).Debug("querying for CLA Group gerrits...")
Expand Down
37 changes: 33 additions & 4 deletions cla-backend-go/v2/sign/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,16 @@ func (s *service) SignedIndividualCallbackGerrit(ctx context.Context, payload []
return err
}

// send email to user
log.WithFields(f).Debugf("sending email to user... ")
log.WithFields(f).Debugf("getting claGroupID: %s", signature.ProjectID)

claGroup, err := s.claGroupService.GetCLAGroup(ctx, signature.ProjectID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to lookup CLA Group by ID: %s", signature.ProjectID)
return err
}

log.WithFields(f).Debugf("claGroup: %+s found", claGroup.ProjectID)

subject := fmt.Sprintf("EasyCLA: Individual CLA Signed for %s", claGroup.ProjectName)
pdfLink := fmt.Sprintf("%s/v3/signatures/%s/%s/icla/pdf", s.ClaV1ApiURL, signature.ProjectID, signature.SignatureReferenceID)
emailParams := emails.DocumentSignedTemplateParams{
Expand All @@ -957,7 +959,7 @@ func (s *service) SignedIndividualCallbackGerrit(ctx context.Context, payload []

recipients := []string{utils.GetBestEmail(claUser)}

body, err := emails.RenderDocumentSignedTemplate(s.emailTemplateService, claGroup.Version, claGroup.ProjectID, emailParams)
body, err := emails.RenderDocumentSignedTemplate(s.emailTemplateService, claGroup.Version, claGroup.ProjectExternalID, emailParams)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to render document signed template for project version: %s, project ID: %s", claGroup.Version, claGroup.ProjectID)
return err
Expand Down Expand Up @@ -1004,13 +1006,15 @@ func (s *service) SignedIndividualCallbackGerrit(ctx context.Context, payload []
})

// Add User to Gerrit Group
log.WithFields(f).Debugf("adding user to ldap group...")
if claUser.LfUsername != "" {
log.WithFields(f).Debugf("adding user to gerrit group: %s", claUser.LfUsername)
err = s.gerritService.AddUserToGroup(ctx, nil, signature.ProjectID, claUser.LfUsername, utils.ClaTypeICLA)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to add user to gerrit group")
return err
}
} else {
log.WithFields(f).Warnf("user LF username is empty")
}

} else {
Expand Down Expand Up @@ -1188,6 +1192,31 @@ func (s *service) SignedCorporateCallback(ctx context.Context, payload []byte, c
CompanySFID: companyModel.CompanyExternalID,
})

// Check if project is a gerrit instance
var gerrits []*v1Models.Gerrit
gerritList, err := s.gerritService.GetClaGroupGerrits(ctx, projectID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to get gerrit instances for project: %s", projectID)
gerrits = []*v1Models.Gerrit{}
} else {
log.WithFields(f).Debugf("gerrit instances found for project: %s", projectID)
gerrits = gerritList.List
}

// Add User to Gerrit Group
if len(gerrits) > 0 {
if user.LfUsername != "" {
log.WithFields(f).Debugf("adding user to gerrit group: %s", user.LfUsername)
err = s.gerritService.AddUserToGroup(ctx, nil, projectID, user.LfUsername, utils.ClaTypeCCLA)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to add user to gerrit group")
return err
}
} else {
log.WithFields(f).Warnf("user LF username is empty")
}
}

return nil

}
Expand Down

0 comments on commit 276cae1

Please sign in to comment.