Skip to content
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
11 changes: 10 additions & 1 deletion cla-backend-go/cla_manager/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ func sendRequestAccessEmailToCLAManagers(emailSvc emails.EmailTemplateService, e
// subject string, body string, recipients []string
subject := fmt.Sprintf("EasyCLA: New CLA Manager Access Request for %s on %s", companyName, projectName)
recipients := []string{emailParams.RecipientAddress}
emailParams.CLAGroupID = claGroupModel.ProjectID
emailParams.CLAGroupName = claGroupModel.ProjectName
body, err := emails.RenderRequestAccessToCLAManagersTemplate(
emailSvc, claGroupModel.Version, claGroupModel.ProjectExternalID, emailParams)
if err != nil {
Expand All @@ -960,6 +962,8 @@ func sendRequestApprovedEmailToCLAManagers(emailSvc emails.EmailTemplateService,
// subject string, body string, recipients []string
subject := fmt.Sprintf("EasyCLA: CLA Manager Access Approval Notice for %s", projectName)
recipients := []string{emailParams.RecipientAddress}
emailParams.CLAGroupID = claGroupModel.ProjectID
emailParams.CLAGroupName = claGroupModel.ProjectName
body, err := emails.RenderRequestApprovedToCLAManagersTemplate(emailSvc, claGroupModel.Version, claGroupModel.ProjectExternalID, emailParams)
if err != nil {
log.Warnf("rendering email template : %s failed : %v", emails.RequestApprovedToCLAManagersTemplateName, err)
Expand All @@ -979,6 +983,8 @@ func sendRequestApprovedEmailToRequester(emailSvc emails.EmailTemplateService, e
// subject string, body string, recipients []string
subject := fmt.Sprintf("EasyCLA: New CLA Manager Access Approved for %s", projectName)
recipients := []string{emailParams.RecipientAddress}
emailParams.CLAGroupID = claGroupModel.ProjectID
emailParams.CLAGroupName = claGroupModel.ProjectName
body, err := emails.RenderRequestApprovedToRequesterTemplate(emailSvc, claGroupModel.Version, claGroupModel.ProjectExternalID, emailParams)
if err != nil {
log.Warnf("email template : %s failed rendering : %s", emails.RequestApprovedToRequesterTemplateName, err)
Expand All @@ -998,6 +1004,8 @@ func sendRequestDeniedEmailToCLAManagers(emailSvc emails.EmailTemplateService, e
// subject string, body string, recipients []string
subject := fmt.Sprintf("EasyCLA: CLA Manager Access Denied Notice for %s", projectName)
recipients := []string{emailParams.RecipientAddress}
emailParams.CLAGroupID = claGroupModel.ProjectID
emailParams.CLAGroupName = claGroupModel.ProjectName
body, err := emails.RenderRequestDeniedToCLAManagersTemplate(emailSvc, claGroupModel.Version, claGroupModel.ProjectExternalID, emailParams)

if err != nil {
Expand All @@ -1020,7 +1028,8 @@ func sendRequestDeniedEmailToRequester(emailSvc emails.EmailTemplateService, ema
subject := fmt.Sprintf("EasyCLA: New CLA Manager Access Denied for %s", projectName)
recipients := []string{emailParams.RecipientAddress}
body, err := emails.RenderRequestDeniedToRequesterTemplate(emailSvc, claGroupModel.Version, claGroupModel.ProjectExternalID, emails.RequestDeniedToRequesterTemplateParams{
CommonEmailParams: emailParams,
CommonEmailParams: emailParams,
CLAGroupTemplateParams: emails.CLAGroupTemplateParams{CLAGroupID: claGroupModel.ProjectID, CLAGroupName: claGroupModel.ProjectName},
})
if err != nil {
log.Warnf("email template rendering %s failed : %v", emails.RequestDeniedToRequesterTemplateName, err)
Expand Down
3 changes: 2 additions & 1 deletion cla-backend-go/cla_manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ func (s service) sendClaManagerAddedEmailToUser(emailSvc emails.EmailTemplateSer
subject := fmt.Sprintf("EasyCLA: Added as CLA Manager for Project :%s", claGroupModel.ProjectName)
recipients := []string{emailParams.RecipientAddress}
body, err := emails.RenderClaManagerAddedEToUserTemplate(emailSvc, claGroupModel.Version, projectSFID, emails.ClaManagerAddedEToUserTemplateParams{
CommonEmailParams: emailParams,
CommonEmailParams: emailParams,
CLAGroupTemplateParams: emails.CLAGroupTemplateParams{CLAGroupID: claGroupModel.ProjectID, CLAGroupName: claGroupModel.ProjectName},
})
if err != nil {
log.Warnf("email template render : %s failed : %v", emails.ClaManagerAddedEToUserTemplateName, err)
Expand Down
1 change: 1 addition & 0 deletions cla-backend-go/cmd/org_import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Safety rules:
its deletion: managers never lose access. ACS keeps a user's organization scope roles in one organization, so such a grant (`contact`)
cannot be copied while it exists on the old id: it is created on the new id right after the old grants are deleted, and a user who holds an
organization role in a third organization keeps that one - the grant is then listed in `dropped_grants.csv`.
A grant of a user who no longer exists on the platform cannot be created anywhere: it is deleted with the others and listed there too.
- On an Account that existed before the rewrite or is shared (`matched`, or an old id under a collapse decision) only `cla-manager`, `cla-manager-designee`,
`cla-signatory`, `contributor` and `contact` are copied; every other role (`company-admin`, `viewer`) is deleted with the old id and listed in
`dropped_grants.csv`; the journal keeps the list by grant id, so a resumed run still reports it. An Account created for one group alone (`created`)
Expand Down
4 changes: 4 additions & 0 deletions cla-backend-go/cmd/refresh_stored_username_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type stubUsersService struct {
updates map[string]interface{}
}

func (s *stubUsersService) AddUserEmails(string, []string) (*models.User, error) {
panic("unexpected AddUserEmails call")
}

func (s *stubUsersService) UpdateUser(userID string, updates map[string]interface{}) (*models.User, error) {
s.called = true
s.calledWith = userID
Expand Down
53 changes: 53 additions & 0 deletions cla-backend-go/company/resolve_company_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type resolveHTTP struct {
searchBody string
mu sync.Mutex
calls []string
searches []string
}

// snapshot of the recorded calls, taken under the lock RoundTrip appends with
Expand All @@ -63,6 +64,9 @@ func (h *resolveHTTP) RoundTrip(r *http.Request) (*http.Response, error) {
case r.URL.Host == resolveAuthHost && r.URL.Path == "/oauth/token":
response.Body = io.NopCloser(strings.NewReader(`{"access_token":"unit-test-token","token_type":"Bearer","expires_in":3600}`))
case r.URL.Host == resolvePlatformHost && r.URL.Path == "/organization-service/v1/orgs/search":
h.mu.Lock()
h.searches = append(h.searches, "offset="+r.URL.Query().Get("offset")+" pageSize="+r.URL.Query().Get("pageSize"))
h.mu.Unlock()
response.Body = io.NopCloser(strings.NewReader(h.searchBody))
case r.URL.Host == resolvePlatformHost && strings.HasPrefix(r.URL.Path, "/organization-service/v1/orgs/"):
body, ok := h.orgs[strings.TrimPrefix(r.URL.Path, "/organization-service/v1/orgs/")]
Expand Down Expand Up @@ -385,6 +389,55 @@ func TestSearchOrganizationByNameBoundsParallelLookups(t *testing.T) {
assert.LessOrEqual(t, int(peak.Load()), limit)
}

func TestSearchOrganizationByNameStopsAtTheResultLimit(t *testing.T) {
const limit = 1000
rows := make([]string, 0, limit)
for i := 0; i < limit; i++ {
rows = append(rows, fmt.Sprintf(`{"ID":"001QP%013d","Name":"Acme %04d","Link":"https://acme%d.invalid"}`, i, i, i))
}
transport := setupResolveHTTP(t, nil, `{"Data":[`+strings.Join(rows, ",")+`],"Metadata":{"TotalSize":2500,"Offset":0,"PageSize":1000}}`)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
repo := mock_company.NewMockIRepository(ctrl)
repo.EXPECT().GetCompanyByExternalID(gomock.Any(), gomock.Any()).Times(limit).DoAndReturn(func(_ context.Context, id string) (*models.Company, error) {
return nil, &utils.CompanyNotFound{CompanySFID: id}
})
repo.EXPECT().GetCompanyByName(gomock.Any(), "Acme").Return(nil, nil)

result, err := newResolveService(repo).SearchOrganizationByName(context.Background(), "Acme", "", false, "")

require.NoError(t, err)
assert.Len(t, result.List, limit)
transport.mu.Lock()
defer transport.mu.Unlock()
assert.Equal(t, []string{"offset=0 pageSize=1000"}, transport.searches, "a broad search reads one page of the organization service")
}

func TestSearchOrganizationByNameReadsTheAccountOfANewCompanyBeyondTheLimit(t *testing.T) {
const (
newSFID = "001QP00001AbCdEfGH"
newCompanyID = "5d2c4f1a-7b3e-4c9d-8a6f-1e2d3c4b5a69"
)
setupResolveHTTP(t, map[string]string{newSFID: `{"ID":"` + newSFID + `","Name":"Acme New","Link":"https://acmenew.invalid","SalesforceB2BAccountID":"b2b-new"}`},
`{"Data":[{"ID":"`+resolveSFID+`","Name":"Acme Corp","Link":"https://acme.invalid"}],"Metadata":{"TotalSize":2500,"Offset":0,"PageSize":1000}}`)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
repo := mock_company.NewMockIRepository(ctrl)
repo.EXPECT().GetCompanyByExternalID(gomock.Any(), resolveSFID).Return(nil, &utils.CompanyNotFound{CompanySFID: resolveSFID})
repo.EXPECT().GetCompanyByName(gomock.Any(), "Acme New").Return(&models.Company{CompanyID: newCompanyID, CompanyExternalID: newSFID, CompanyName: "Acme New", Created: strfmt.DateTime(time.Now().Add(-5 * time.Minute))}, nil)
repo.EXPECT().IsCCLAEnabledForCompany(gomock.Any(), newCompanyID).Return(false, nil)

result, err := newResolveService(repo).SearchOrganizationByName(context.Background(), "Acme New", "", false, "")

require.NoError(t, err)
require.Len(t, result.List, 2)
added := result.List[1]
assert.Equal(t, newSFID, added.OrganizationID)
assert.Equal(t, "https://acmenew.invalid", added.OrganizationWebsite, "the row of a cut search carries what the organization service knows")
require.NotNil(t, added.HasB2bAccount)
assert.True(t, *added.HasB2bAccount)
}

func TestSearchOrganizationByNameAddsNewCompanyNotListed(t *testing.T) {
const (
newSFID = "001QP00001AbCdEfGH"
Expand Down
17 changes: 14 additions & 3 deletions cla-backend-go/company/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ func (s service) GetCompanyBySigningEntityName(ctx context.Context, signingEntit
// searchLookupConcurrency keeps the company lookups of one organization search within the Lambda's file descriptors
const searchLookupConcurrency = 32

// searchResultLimit is the most organizations one organization search fetches and looks up
const searchResultLimit = 1000

func (s service) SearchOrganizationByName(ctx context.Context, orgName string, websiteName string, includeSigningEntityName bool, filter string) (*models.OrgList, error) {
f := logrus.Fields{
"functionName": "company.service.SearchOrganizationByName",
Expand All @@ -777,11 +780,14 @@ func (s service) SearchOrganizationByName(ctx context.Context, orgName string, w

osc := organization_service.GetClient()
log.WithFields(f).Debug("Searching organizations by name and website...")
orgs, err := osc.SearchOrganization(ctx, orgName, websiteName, filter)
orgs, more, err := osc.SearchOrganizationPage(ctx, orgName, websiteName, filter, searchResultLimit)
if err != nil {
log.WithFields(f).WithError(err).Warn("problem searching organizations by name and website")
return nil, err
}
if more {
log.WithFields(f).Warnf("the search matches more than %d organizations - only the first %d are returned", searchResultLimit, searchResultLimit)
}

resultsChannel := make(chan *models.Org, len(orgs))
var wg sync.WaitGroup
Expand Down Expand Up @@ -859,7 +865,7 @@ func (s service) SearchOrganizationByName(ctx context.Context, orgName string, w
result.List = append(result.List, orgResult)
}
if websiteName == "" && filter == "" {
if added := s.newCompanyNotListed(ctx, orgName, includeSigningEntityName, orgs); added != nil {
if added := s.newCompanyNotListed(ctx, orgName, includeSigningEntityName, orgs, more); added != nil {
result.List = append(result.List, added)
}
}
Expand All @@ -882,7 +888,7 @@ func (s service) SearchOrganizationByName(ctx context.Context, orgName string, w
const newCompanyWindow = 24 * time.Hour

// newCompanyNotListed returns the company created under exactly this name while the organization service does not list its account yet
func (s service) newCompanyNotListed(ctx context.Context, orgName string, includeSigningEntityName bool, listed []*orgServiceModels.Organization) *models.Org {
func (s service) newCompanyNotListed(ctx context.Context, orgName string, includeSigningEntityName bool, listed []*orgServiceModels.Organization, cut bool) *models.Org {
f := logrus.Fields{
"functionName": "company.service.newCompanyNotListed",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
Expand Down Expand Up @@ -914,6 +920,11 @@ func (s service) newCompanyNotListed(ctx context.Context, orgName string, includ
}
upstream = org
}
if upstream == nil && cut {
if org, orgErr := organization_service.GetClient().GetOrganization(ctx, company.CompanyExternalID); orgErr == nil {
upstream = org
Comment on lines +924 to +925
}
}
cclaEnabled, err := s.IsCCLAEnabledForCompany(ctx, company.CompanyID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem checking if ccla is enabled for company: %s", company.CompanyID)
Expand Down
12 changes: 6 additions & 6 deletions cla-backend-go/emails/cla_manager_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func RenderRequestAccessToCLAManagersTemplate(svc EmailTemplateService, claGroup
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, RequestAccessToCLAManagersTemplateName, RequestAccessToCLAManagersTemplate, params)
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func RenderRequestApprovedToCLAManagersTemplate(svc EmailTemplateService, claGro
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, RequestApprovedToCLAManagersTemplateName, RequestApprovedToCLAManagersTemplate, params)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func RenderRequestApprovedToRequesterTemplate(svc EmailTemplateService, claGroup
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, RequestApprovedToRequesterTemplateName, RequestApprovedToRequesterTemplate, params)
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func RenderRequestDeniedToCLAManagersTemplate(svc EmailTemplateService, claGroup
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, RequestDeniedToCLAManagersTemplateName, RequestDeniedToCLAManagersTemplate, params)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func RenderRequestDeniedToRequesterTemplate(svc EmailTemplateService, claGroupMo
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, RequestDeniedToRequesterTemplateName, RequestDeniedToRequesterTemplate, params)
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func RenderClaManagerAddedEToUserTemplate(svc EmailTemplateService, claGroupMode
if err != nil {
return "", err
}
params.CLAGroupTemplateParams = claGroupParams
params.CLAGroupTemplateParams = claGroupParams.forCLAGroup(params.CLAGroupTemplateParams)

return RenderTemplate(claGroupModelVersion, ClaManagerAddedEToUserTemplateName, ClaManagerAddedEToUserTemplate, params)
}
Expand Down
32 changes: 32 additions & 0 deletions cla-backend-go/emails/org_lens_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,35 @@ func TestContactClaManagerEmailLinksToOrgLens(t *testing.T) {
assert.Contains(t, console, "log into the EasyCLA Corporate Console")
assert.NotContains(t, console, "Organization lens")
}

func TestCLAManagerEmailsKeepTheCLAGroupOfTheSender(t *testing.T) {
const own = "00000000-0000-4000-8000-00000000000a"
svc := &documentSignedTemplateServiceStub{projectParams: lensTestCLAGroup(lensTestBase)}
ownPage := lensTestBase + "/org/" + lensTestCompany + "/easycla/" + own
group := CLAGroupTemplateParams{CLAGroupID: own, CLAGroupName: "Own Group"}
renders := map[string]func() (string, error){
"request access": func() (string, error) {
return RenderRequestAccessToCLAManagersTemplate(svc, utils.V2, "a0P000000000001AAA", RequestAccessToCLAManagersTemplateParams{CommonEmailParams: lensTestCommon(), CLAGroupTemplateParams: group})
},
"request approved to requester": func() (string, error) {
return RenderRequestApprovedToRequesterTemplate(svc, utils.V2, "a0P000000000001AAA", RequestApprovedToRequesterTemplateParams{CommonEmailParams: lensTestCommon(), CLAGroupTemplateParams: group})
},
"CLA manager added": func() (string, error) {
return RenderClaManagerAddedEToUserTemplate(svc, utils.V2, "a0P000000000001AAA", ClaManagerAddedEToUserTemplateParams{CommonEmailParams: lensTestCommon(), CLAGroupTemplateParams: group})
},
}
for name, render := range renders {
t.Run(name, func(t *testing.T) {
body, err := render()
assert.NoError(t, err)
assert.Contains(t, body, `<a href="`+ownPage+`" target="_blank">Own Group in the Organization lens</a>`, "the link and its name are the CLA Group of the request")
assert.NotContains(t, body, lensTestCLAGroupID, "the CLA Group of the project lookup is not used for the link")
assert.NotContains(t, body, "Example Group", "the name of another CLA Group is not shown")
})
}
t.Run("a sender that names no CLA Group keeps the lookup", func(t *testing.T) {
body, err := RenderRequestAccessToCLAManagersTemplate(svc, utils.V2, "a0P000000000001AAA", RequestAccessToCLAManagersTemplateParams{CommonEmailParams: lensTestCommon()})
assert.NoError(t, err)
assert.Contains(t, body, `<a href="`+lensTestPage+`"`)
})
}
11 changes: 11 additions & 0 deletions cla-backend-go/emails/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ func (claParams CLAGroupTemplateParams) OrgLensURL(companySFID string) string {
return utils.OrgLensURL(claParams.OrgLensBase, companySFID, claParams.CLAGroupID)
}

// forCLAGroup keeps the CLA Group the sender named: the project lookup can answer with another CLA Group of the same foundation
func (claParams CLAGroupTemplateParams) forCLAGroup(sender CLAGroupTemplateParams) CLAGroupTemplateParams {
if sender.CLAGroupID != "" {
claParams.CLAGroupID = sender.CLAGroupID
if sender.CLAGroupName != "" {
claParams.CLAGroupName = sender.CLAGroupName
Comment on lines +92 to +95
}
}
return claParams
}

// GetProjectNameOrFoundation returns if the foundationName is set it gets back
// the foundation Name otherwise the ProjectName is returned
func (claParams CLAGroupTemplateParams) GetProjectNameOrFoundation() string {
Expand Down
Loading
Loading