Skip to content

Commit

Permalink
Merge pull request #4215 from nickmango/bug/icla-dupe
Browse files Browse the repository at this point in the history
Bug/ICLA Duplicates
  • Loading branch information
nickmango authored Jan 15, 2024
2 parents 651c62b + 8efe3dd commit 1c5d595
Showing 1 changed file with 49 additions and 37 deletions.
86 changes: 49 additions & 37 deletions cla-backend-go/v2/sign/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ func (s *service) RequestIndividualSignature(ctx context.Context, input *models.
log.WithFields(f).WithError(err).Warnf("unable to get signature callback url for user: %s", *input.UserID)
return nil, err
}

} else if strings.ToLower(input.ReturnURLType) == utils.GitLabLower {
callBackURL, err = s.getIndividualSignatureCallbackURLGitlab(ctx, *input.UserID, activeSignatureMetadata)
if err != nil {
Expand All @@ -859,6 +860,29 @@ func (s *service) RequestIndividualSignature(ctx context.Context, input *models.
log.WithFields(f).Debugf("signature callback url: %s", callBackURL)
log.WithFields(f).Debugf("latest signature: %+v", latestSignature)

var acl string
if strings.ToLower(input.ReturnURLType) == utils.GitHubType {
acl = fmt.Sprintf("%s:%s", strings.ToLower(input.ReturnURLType), user.GithubID)
} else if strings.ToLower(input.ReturnURLType) == "gitlab" {
acl = fmt.Sprintf("%s:%s", strings.ToLower(input.ReturnURLType), user.GitlabID)
}

log.WithFields(f).Debugf("acl: %s", acl)

majorVersion, err := strconv.Atoi(latestDocument.DocumentMajorVersion)

if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to convert document major version to int: %s", latestDocument.DocumentMajorVersion)
return nil, err
}

minorVersion, err := strconv.Atoi(latestDocument.DocumentMinorVersion)

if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to convert document minor version to int: %s", latestDocument.DocumentMinorVersion)
return nil, err
}

if latestSignature != nil {
log.WithFields(f).Debugf("comparing latest signature document version: %s to latest document version: %s", latestSignature.SignatureDocumentMajorVersion, latestDocument.DocumentMajorVersion)
if latestDocument.DocumentMajorVersion == latestSignature.SignatureDocumentMajorVersion {
Expand All @@ -869,20 +893,26 @@ func (s *service) RequestIndividualSignature(ctx context.Context, input *models.
log.WithFields(f).Debugf("regenerating signing URL for user: %s", *input.UserID)
_, currentTime := utils.CurrentTime()
itemSignature := signatures.ItemSignature{
SignatureID: latestSignature.SignatureID,
DateModified: currentTime,
SignatureReferenceType: latestSignature.SignatureReferenceType,
SignatureEnvelopeID: latestSignature.SignatureEnvelopeID,
SignatureType: latestSignature.SignatureType,
SignatureReferenceID: latestSignature.SignatureReferenceID,
SignatureProjectID: latestSignature.ProjectID,
SignatureApproved: latestSignature.SignatureApproved,
SignatureSigned: latestSignature.SignatureSigned,
SignatureReferenceName: latestSignature.SignatureReferenceName,
SignatureReferenceNameLower: latestSignature.SignatureReferenceNameLower,
SignedOn: latestSignature.SignedOn,
SignatureID: latestSignature.SignatureID,
DateModified: currentTime,
SignatureReferenceType: latestSignature.SignatureReferenceType,
SignatureEnvelopeID: latestSignature.SignatureEnvelopeID,
SignatureType: latestSignature.SignatureType,
SignatureReferenceID: latestSignature.SignatureReferenceID,
SignatureProjectID: latestSignature.ProjectID,
SignatureApproved: latestSignature.SignatureApproved,
SignatureSigned: latestSignature.SignatureSigned,
SignatureReferenceName: latestSignature.SignatureReferenceName,
SignatureReferenceNameLower: latestSignature.SignatureReferenceNameLower,
SignedOn: latestSignature.SignedOn,
SignatureReturnURL: string(input.ReturnURL),
SignatureReturnURLType: input.ReturnURLType,
SignatureCallbackURL: latestSignature.SignatureCallbackURL,
SignatureACL: []string{acl},
SignatureDocumentMajorVersion: majorVersion,
SignatureDocumentMinorVersion: minorVersion,
}
signURL, signErr := s.populateSignURL(ctx, &itemSignature, callBackURL, "", "", false, "", "", defaultValues, preferredEmail)
signURL, signErr := s.populateSignURL(ctx, &itemSignature, latestSignature.SignatureCallbackURL, "", "", false, "", "", defaultValues, preferredEmail)
if signErr != nil {
log.WithFields(f).WithError(err).Warnf("unable to populate sign url for user: %s", *input.UserID)
return nil, signErr
Expand Down Expand Up @@ -917,7 +947,6 @@ func (s *service) RequestIndividualSignature(ctx context.Context, input *models.
ProjectID: *input.ProjectID,
}, nil
}

}

// 6. Get latest document
Expand All @@ -938,28 +967,6 @@ func (s *service) RequestIndividualSignature(ctx context.Context, input *models.
log.WithFields(f).Debugf("creating new signature object...")
signatureID := uuid.Must(uuid.NewV4()).String()
_, currentTime := utils.CurrentTime()
var acl string
if strings.ToLower(input.ReturnURLType) == utils.GitHubType {
acl = fmt.Sprintf("%s:%s", strings.ToLower(input.ReturnURLType), user.GithubID)
} else if strings.ToLower(input.ReturnURLType) == "gitlab" {
acl = fmt.Sprintf("%s:%s", strings.ToLower(input.ReturnURLType), user.GitlabID)
}

log.WithFields(f).Debugf("acl: %s", acl)

majorVersion, err := strconv.Atoi(document.DocumentMajorVersion)

if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to convert document major version to int: %s", document.DocumentMajorVersion)
return nil, err
}

minorVersion, err := strconv.Atoi(document.DocumentMinorVersion)

if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to convert document minor version to int: %s", document.DocumentMinorVersion)
return nil, err
}

itemSignature := signatures.ItemSignature{
SignatureID: signatureID,
Expand Down Expand Up @@ -1092,20 +1099,25 @@ func (s *service) getIndividualSignatureCallbackURL(ctx context.Context, userID
return "", err
}

log.WithFields(f).Debugf("found repository ID: %s", repositoryID)

if found, ok := metadata["pull_request_id"].(string); ok {
pullRequestID = found
} else {
log.WithFields(f).WithError(err).Warnf("unable to get pull request ID for user: %s", userID)
return "", err
}

log.WithFields(f).Debugf("found pull request ID: %s", pullRequestID)

// Get installation ID through a helper function
log.WithFields(f).Debugf("getting repository...")
githubRepository, err := s.repositoryService.GetRepositoryByExternalID(ctx, repositoryID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to get installation ID for repository ID: %s", repositoryID)
return "", err
}

// Get github organization
log.WithFields(f).Debugf("getting github organization...")
githubOrg, err := s.githubOrgService.GetGitHubOrganizationByName(ctx, githubRepository.RepositoryOrganizationName)
Expand All @@ -1121,7 +1133,7 @@ func (s *service) getIndividualSignatureCallbackURL(ctx context.Context, userID
return "", err
}

// s.ClaV4ApiURL = "https://67c8-102-217-56-29.ngrok-free.app"
// s.ClaV4ApiURL = "https://dc35-41-210-154-131.ngrok-free.app"

callbackURL := fmt.Sprintf("%s/v4/signed/individual/%d/%s/%s", s.ClaV4ApiURL, installationId, repositoryID, pullRequestID)

Expand Down

0 comments on commit 1c5d595

Please sign in to comment.