Skip to content

Commit

Permalink
[#2515] Feature/ Get Events Signing Entity Name
Browse files Browse the repository at this point in the history
- Factored in internal companyID based on signing entity name to fetch corresponding events

Signed-off-by: wanyaland <[email protected]>
  • Loading branch information
wanyaland committed Jan 26, 2021
1 parent 8742a10 commit 163b9bd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions cla-backend-go/events/mockrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func (repo *mockRepository) AddDataToEvent(eventID, foundationSFID, projectSFID,
panic("implement me")
}

func (repo *mockRepository) GetCompanyFoundationEvents(companySFID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *mockRepository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
panic("implement me")
}

func (repo *mockRepository) GetCompanyClaGroupEvents(companySFID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *mockRepository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
panic("implement me")
}

Expand Down
32 changes: 22 additions & 10 deletions cla-backend-go/events/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ type Repository interface {
SearchEvents(params *eventOps.SearchEventsParams, pageSize int64) (*models.EventList, error)
GetRecentEvents(pageSize int64) (*models.EventList, error)

GetCompanyFoundationEvents(companySFID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetFoundationEvents(foundationSFID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetClaGroupEvents(claGroupID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
Expand Down Expand Up @@ -308,7 +308,7 @@ func (repo *repository) SearchEvents(params *eventOps.SearchEventsParams, pageSi
}

// queryEventsTable queries events table on index
func (repo *repository) queryEventsTable(indexName string, condition expression.KeyConditionBuilder, nextKey *string, pageSize *int64, all bool, searchTerm *string) (*models.EventList, error) {
func (repo *repository) queryEventsTable(indexName string, condition expression.KeyConditionBuilder, filter *expression.ConditionBuilder, nextKey *string, pageSize *int64, all bool, searchTerm *string) (*models.EventList, error) {
f := logrus.Fields{
"functionName": "events.queryEventsTable",
"indexName": indexName,
Expand All @@ -320,10 +320,14 @@ func (repo *repository) queryEventsTable(indexName string, condition expression.

log.WithFields(f).Debug("querying events table")
builder := expression.NewBuilder() // .WithProjection(buildProjection())

// The table we're interested in
tableName := fmt.Sprintf("cla-%s-events", repo.stage)

builder = builder.WithKeyCondition(condition)
if filter != nil {
builder = builder.WithFilter(*filter)
}
// Use the nice builder to create the expression
expr, err := builder.Build()
if err != nil {
Expand Down Expand Up @@ -464,37 +468,45 @@ func buildNextKey(indexName string, event *models.Event) (string, error) {
}

// GetCompanyFoundationEvents returns the list of events for foundation and company
func (repo *repository) GetCompanyFoundationEvents(companySFID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *repository) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
key := fmt.Sprintf("%s#%s", companySFID, foundationSFID)
keyCondition := expression.Key("company_sfid_foundation_sfid").Equal(expression.Value(key))
return repo.queryEventsTable(CompanySFIDFoundationSFIDEpochIndex, keyCondition, nextKey, paramPageSize, all, nil)
var filter expression.ConditionBuilder
if companyID != "" {
filter = expression.Name("company_id").Equal(expression.Value(companyID))
}
return repo.queryEventsTable(CompanySFIDFoundationSFIDEpochIndex, keyCondition, &filter, nextKey, paramPageSize, all, nil)
}

// GetCompanyClaGroupEvents returns the list of events for cla group and the company
func (repo *repository) GetCompanyClaGroupEvents(companySFID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
func (repo *repository) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
key := fmt.Sprintf("%s#%s", companySFID, claGroupID)
keyCondition := expression.Key("company_sfid_project_id").Equal(expression.Value(key))
return repo.queryEventsTable(CompanySFIDProjectIDEpochIndex, keyCondition, nextKey, paramPageSize, all, nil)
var filter expression.ConditionBuilder
if companyID != "" {
filter = expression.Name("company_id").Equal(expression.Value(companyID))
}
return repo.queryEventsTable(CompanySFIDProjectIDEpochIndex, keyCondition, &filter, nextKey, paramPageSize, all, nil)
}

// GetCompanyEvents returns the list of events for given company id and event types
func (repo *repository) GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
keyCondition := expression.Key("company_id").Equal(expression.Value(companyID)).And(
expression.Key("event_type").Equal(expression.Value(eventType)))

return repo.queryEventsTable(CompanyIDEventTypeIndex, keyCondition, nextKey, paramPageSize, all, nil)
return repo.queryEventsTable(CompanyIDEventTypeIndex, keyCondition, nil, nextKey, paramPageSize, all, nil)
}

// GetFoundationEvents returns the list of foundation events
func (repo *repository) GetFoundationEvents(foundationSFID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error) {
keyCondition := expression.Key("event_foundation_sfid").Equal(expression.Value(foundationSFID))
return repo.queryEventsTable(EventFoundationSFIDEpochIndex, keyCondition, nextKey, paramPageSize, all, searchTerm)
return repo.queryEventsTable(EventFoundationSFIDEpochIndex, keyCondition, nil, nextKey, paramPageSize, all, searchTerm)
}

// GetClaGroupEvents returns the list of cla-group events
func (repo *repository) GetClaGroupEvents(claGroupID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error) {
keyCondition := expression.Key("event_project_id").Equal(expression.Value(claGroupID))
return repo.queryEventsTable(EventProjectIDEpochIndex, keyCondition, nextKey, paramPageSize, all, searchTerm)
return repo.queryEventsTable(EventProjectIDEpochIndex, keyCondition, nil, nextKey, paramPageSize, all, searchTerm)
}

// toString encodes the map as a string
Expand Down
12 changes: 6 additions & 6 deletions cla-backend-go/events/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Service interface {

GetFoundationEvents(foundationSFID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetClaGroupEvents(claGroupID string, nextKey *string, paramPageSize *int64, all bool, searchTerm *string) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error)
}

Expand Down Expand Up @@ -91,13 +91,13 @@ func (s *service) GetClaGroupEvents(projectSFDC string, nextKey *string, paramPa
}

// GetCompanyFoundationEvents returns list of events for company and foundation
func (s *service) GetCompanyFoundationEvents(companySFID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyFoundationEvents(companySFID, foundationSFID, nextKey, paramPageSize, all)
func (s *service) GetCompanyFoundationEvents(companySFID, companyID, foundationSFID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyFoundationEvents(companySFID, companyID, foundationSFID, nextKey, paramPageSize, all)
}

// GetCompanyClaGroupEvents returns list of events for company and cla group
func (s *service) GetCompanyClaGroupEvents(companySFID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyClaGroupEvents(companySFID, claGroupID, nextKey, paramPageSize, all)
func (s *service) GetCompanyClaGroupEvents(companySFID, companyID, claGroupID string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
return s.repo.GetCompanyClaGroupEvents(companySFID, companyID, claGroupID, nextKey, paramPageSize, all)
}

func (s *service) GetCompanyEvents(companyID, eventType string, nextKey *string, paramPageSize *int64, all bool) (*models.EventList, error) {
Expand Down
4 changes: 2 additions & 2 deletions cla-backend-go/swagger/cla.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ paths:
tags:
- events

/company/{companySFID}/project/{projectSFID}/events:
/company/{companyID}/project/{projectSFID}/events:
get:
summary: Get recent events of company and project
description: Returns list of events of company and project
Expand All @@ -1080,7 +1080,7 @@ paths:
- $ref: "#/parameters/x-email"
- $ref: '#/parameters/pageSize'
- $ref: '#/parameters/path-projectSFID'
- $ref: '#/parameters/path-companySFID'
- $ref: '#/parameters/path-companyID'
- $ref: '#/parameters/nextKey'
- $ref: '#/parameters/returnAllEvents'
produces:
Expand Down
17 changes: 12 additions & 5 deletions cla-backend-go/v2/events/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,20 @@ func Configure(api *operations.EasyclaAPI, service v1Events.Service, v1CompanyRe
"authUserName": authUser.UserName,
"authUserEmail": authUser.Email,
"projectSFID": params.ProjectSFID,
"companySFID": params.CompanySFID,
"companyID": params.CompanyID,
}
if !utils.IsUserAuthorizedForOrganization(authUser, params.CompanySFID, utils.ALLOW_ADMIN_SCOPE) {

v1Company, compErr := v1CompanyRepo.GetCompany(ctx, params.CompanyID)
if compErr != nil {
log.WithFields(f).Warnf("unable to fetch company by ID:%s ", params.CompanyID)
return events.NewGetCompanyProjectEventsBadRequest().WithPayload(errorResponse(reqID, compErr))
}

if !utils.IsUserAuthorizedForOrganization(authUser, v1Company.CompanyExternalID, utils.ALLOW_ADMIN_SCOPE) {
return events.NewGetCompanyProjectEventsForbidden().WithPayload(&models.ErrorResponse{
Code: "403",
Message: fmt.Sprintf("EasyCLA - 403 Forbidden - user %s does not have access to GetCompanyProject Events with Organization scope of %s",
authUser.UserName, params.CompanySFID),
authUser.UserName, v1Company.CompanyExternalID),
XRequestID: reqID,
})
}
Expand All @@ -300,7 +307,7 @@ func Configure(api *operations.EasyclaAPI, service v1Events.Service, v1CompanyRe

var result *v1Models.EventList
if projectDetails.ProjectType == utils.ProjectTypeProjectGroup {
result, err = service.GetCompanyFoundationEvents(params.CompanySFID, params.ProjectSFID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
result, err = service.GetCompanyFoundationEvents(v1Company.CompanyExternalID, params.CompanyID, params.ProjectSFID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
} else {
pm, perr := projectsClaGroupsRepo.GetClaGroupIDForProject(params.ProjectSFID)
if perr != nil {
Expand All @@ -314,7 +321,7 @@ func Configure(api *operations.EasyclaAPI, service v1Events.Service, v1CompanyRe
log.WithFields(f).WithError(perr).Warnf("problem determining CLA Group for project SFID: %s", params.ProjectSFID)
return events.NewGetCompanyProjectEventsInternalServerError().WithPayload(errorResponse(reqID, perr))
}
result, err = service.GetCompanyClaGroupEvents(params.CompanySFID, pm.ClaGroupID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
result, err = service.GetCompanyClaGroupEvents(v1Company.CompanyExternalID, params.CompanyID, pm.ClaGroupID, params.NextKey, params.PageSize, aws.BoolValue(params.ReturnAllEvents))
}
if err != nil {
log.WithFields(f).WithError(err).Warn("problem loading events")
Expand Down

0 comments on commit 163b9bd

Please sign in to comment.