Skip to content

Commit

Permalink
Merge pull request #2533 from communitybridge/bug/invite-company-admin
Browse files Browse the repository at this point in the history
[#2527,#2529] Bug/Invite Company Admin
  • Loading branch information
wanyaland authored Jan 27, 2021
2 parents d66ddb4 + 8a32038 commit 4d181ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 49 deletions.
2 changes: 1 addition & 1 deletion cla-backend-go/v2/cla_manager/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func Configure(api *operations.EasyclaAPI, service Service, v1CompanyService v1C
// Note: anyone create assign a CLA manager designee...no permissions checks
log.WithFields(f).Debugf("processing create CLA Manager Desginee request")
utils.SetAuthUserProperties(authUser, params.XUSERNAME, params.XEMAIL)
claManagerDesignee, err := service.CreateCLAManagerDesignee(ctx, v1CompanyModel.CompanyExternalID, params.ProjectSFID, params.Body.UserEmail.String())
claManagerDesignee, err := service.CreateCLAManagerDesignee(ctx, params.CompanyID, params.ProjectSFID, params.Body.UserEmail.String())
if err != nil {
if err == ErrCLAManagerDesigneeConflict {
msg := fmt.Sprintf("Conflict assigning cla manager role for Project SFID: %s ", params.ProjectSFID)
Expand Down
50 changes: 2 additions & 48 deletions cla-backend-go/v2/cla_manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
v2OrgService "github.com/communitybridge/easycla/cla-backend-go/v2/organization-service"
v2ProjectService "github.com/communitybridge/easycla/cla-backend-go/v2/project-service"
v2UserService "github.com/communitybridge/easycla/cla-backend-go/v2/user-service"
v2UserModels "github.com/communitybridge/easycla/cla-backend-go/v2/user-service/models"
)

var (
Expand Down Expand Up @@ -979,7 +978,7 @@ func (s *service) InviteCompanyAdmin(ctx context.Context, contactAdmin bool, com
// check if claGroup is signed at foundation level
foundationSFID := projectCLAGroups[0].FoundationSFID
log.WithFields(f).Debugf("Create cla manager designee for foundation : %s ", foundationSFID)
claManagerDesignee, err := s.CreateCLAManagerDesignee(ctx, organization.ID, foundationSFID, userEmail)
claManagerDesignee, err := s.CreateCLAManagerDesignee(ctx, companyID, foundationSFID, userEmail)
if err != nil {
msg := fmt.Sprintf("Problem creating cla Manager Designee for user : %s, error: %+v ", userEmail, err)
log.WithFields(f).Warn(msg)
Expand All @@ -989,7 +988,7 @@ func (s *service) InviteCompanyAdmin(ctx context.Context, contactAdmin bool, com
} else {
for _, pcg := range projectCLAGroups {
log.WithFields(f).Debugf("Create cla manager designee for Project SFID: %s", pcg.ProjectSFID)
claManagerDesignee, err := s.CreateCLAManagerDesignee(ctx, organization.ID, pcg.ProjectSFID, userEmail)
claManagerDesignee, err := s.CreateCLAManagerDesignee(ctx, companyID, pcg.ProjectSFID, userEmail)
if err != nil {
msg := fmt.Sprintf("Problem creating cla Manager Designee for user : %s, error: %+v ", userEmail, err)
log.WithFields(f).Warn(msg)
Expand All @@ -998,10 +997,6 @@ func (s *service) InviteCompanyAdmin(ctx context.Context, contactAdmin bool, com
designeeScopes = append(designeeScopes, claManagerDesignee)
}
}
conversionErr := s.convertGHUserToContact(ctx, contributor)
if conversionErr != nil {
return nil, conversionErr
}

log.Debugf("Sending Email to CLA Manager Designee email: %s ", userEmail)

Expand Down Expand Up @@ -1440,47 +1435,6 @@ func buildErrorMessage(errPrefix string, claGroupID string, params cla_manager.C
errPrefix, params.CompanyID, claGroupID, *params.Body.FirstName, *params.Body.LastName, *params.Body.UserEmail, err)
}

func (s *service) convertGHUserToContact(ctx context.Context, contributor *v1User.User) error {
f := logrus.Fields{
"functionName": "cla_manager.service.convertGHUserToContact",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
}

userService := v2UserService.GetClient()
log.Infof("Checking if GH User: %s, GH ID: %s has LFID for contact conversion ", contributor.UserGithubUsername, contributor.UserGithubID)
var GHUserLF *v2UserModels.User
var GHUserErr error
if contributor.LFEmail != "" {
GHUserLF, GHUserErr = userService.SearchUserByEmail(contributor.LFEmail)
if GHUserErr != nil {
msg := fmt.Sprintf("GH UserEmail: %s has no LF Login ", contributor.LFEmail)
log.Warn(msg)
}

} else if contributor.LFUsername != "" {
GHUserLF, GHUserErr = userService.GetUserByUsername(contributor.LFUsername)
if GHUserErr != nil {
msg := fmt.Sprintf("GH Username: %s has no LF Login ", contributor.LFUsername)
log.Warn(msg)
}
}

if GHUserLF != nil {
// Convert user to contact
if GHUserLF.Type == utils.Lead {
// convert user to contact
log.WithFields(f).Debug("converting lead to contact")
err := userService.ConvertToContact(GHUserLF.ID)
if err != nil {
msg := fmt.Sprintf("converting lead to contact failed: %v", err)
log.WithFields(f).Warn(msg)
return err
}
}
}
return nil
}

func companyV1toV2(v1CompanyModel *v1Models.Company) *models.Company {
return &models.Company{
CompanyACL: v1CompanyModel.CompanyACL,
Expand Down

0 comments on commit 4d181ac

Please sign in to comment.