Skip to content

Commit

Permalink
Merge pull request #3927 from nickmango/bug/remove-duplicates-contribs
Browse files Browse the repository at this point in the history
[#3920] Bug/Duplicate signatures
  • Loading branch information
nickmango authored May 5, 2023
2 parents 031ed0d + cbc26ee commit 1f30de5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cla-backend-go/signatures/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,9 @@ func (repo repository) GetProjectCompanyEmployeeSignatures(ctx context.Context,
// Add to the signature response model to the list
sigs = append(sigs, signatureList...)

// remove duplicate values
sigs = removeDuplicates(sigs)

if results.LastEvaluatedKey["signature_id"] != nil {
lastEvaluatedKey = *results.LastEvaluatedKey["signature_id"].S
queryInput.ExclusiveStartKey = results.LastEvaluatedKey
Expand Down Expand Up @@ -1761,6 +1764,36 @@ func (repo repository) GetProjectCompanyEmployeeSignatures(ctx context.Context,
}, nil
}

func removeDuplicates(signatures []*models.Signature) []*models.Signature {
f := logrus.Fields{
"functionName": "v1.signatures.repository.removeDuplicates",
}

type SignatureCheck struct {
SignatureRef string
SignatureApproved bool
SignatureSigned bool
}

seen := make(map[SignatureCheck]bool)
result := []*models.Signature{}

for _, model := range signatures {
check := SignatureCheck{
SignatureRef: model.SignatureReferenceID,
SignatureApproved: model.SignatureApproved,
SignatureSigned: model.SignatureSigned,
}
if !seen[check] {
log.WithFields(f).Debugf("Signature : %+v does not exist", check)
seen[check] = true
result = append(result, model)
}
}

return result
}

func (repo repository) GetProjectCompanyEmployeeSignature(ctx context.Context, companyModel *models.Company, claGroupModel *models.ClaGroup, employeeUserModel *models.User) (*models.Signature, error) {
f := logrus.Fields{
"functionName": "v1.signatures.repository.GetProjectCompanyEmployeeSignature",
Expand Down

0 comments on commit 1f30de5

Please sign in to comment.