Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/Docusign Golang Integration #4162

Merged
merged 1 commit into from
Nov 9, 2023
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
2 changes: 1 addition & 1 deletion cla-backend-go/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func server(localMode bool) http.Handler {
v2Company.Configure(v2API, v2CompanyService, v1ProjectClaGroupRepo, configFile.LFXPortalURL, configFile.CorporateConsoleV1URL)
cla_manager.Configure(api, v1ClaManagerService, v1CompanyService, v1ProjectService, usersService, v1SignaturesService, eventsService, emailTemplateService)
v2ClaManager.Configure(v2API, v2ClaManagerService, v1CompanyService, configFile.LFXPortalURL, configFile.CorporateConsoleV2URL, v1ProjectClaGroupRepo, userRepo)
sign.Configure(v2API, v2SignService)
sign.Configure(v2API, v2SignService, usersService)
cla_groups.Configure(v2API, v2ClaGroupService, v1ProjectService, v1ProjectClaGroupRepo, eventsService)
v2GithubActivity.Configure(v2API, v2GithubActivityService)

Expand Down
1 change: 1 addition & 0 deletions cla-backend-go/project/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func BuildCLAGroupDocumentModels(dbDocumentModels []models2.DBProjectDocumentMod
DocumentMajorVersion: dbDocumentModel.DocumentMajorVersion,
DocumentMinorVersion: dbDocumentModel.DocumentMinorVersion,
DocumentCreationDate: dbDocumentModel.DocumentCreationDate,
DocumentTabs: dbDocumentModel.DocumentTabs,
})
}

Expand Down
25 changes: 15 additions & 10 deletions cla-backend-go/project/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

package models

import (
v1Models "github.com/communitybridge/easycla/cla-backend-go/gen/v1/models"
)

// DBProjectModel data model
type DBProjectModel struct {
DateCreated string `dynamodbav:"date_created"`
Expand All @@ -28,14 +32,15 @@ type DBProjectModel struct {

// DBProjectDocumentModel is a data model for the CLA Group Project documents
type DBProjectDocumentModel struct {
DocumentName string `dynamodbav:"document_name"`
DocumentFileID string `dynamodbav:"document_file_id"`
DocumentPreamble string `dynamodbav:"document_preamble"`
DocumentLegalEntityName string `dynamodbav:"document_legal_entity_name"`
DocumentAuthorName string `dynamodbav:"document_author_name"`
DocumentContentType string `dynamodbav:"document_content_type"`
DocumentS3URL string `dynamodbav:"document_s3_url"`
DocumentMajorVersion string `dynamodbav:"document_major_version"`
DocumentMinorVersion string `dynamodbav:"document_minor_version"`
DocumentCreationDate string `dynamodbav:"document_creation_date"`
DocumentName string `dynamodbav:"document_name"`
DocumentFileID string `dynamodbav:"document_file_id"`
DocumentPreamble string `dynamodbav:"document_preamble"`
DocumentLegalEntityName string `dynamodbav:"document_legal_entity_name"`
DocumentAuthorName string `dynamodbav:"document_author_name"`
DocumentContentType string `dynamodbav:"document_content_type"`
DocumentS3URL string `dynamodbav:"document_s3_url"`
DocumentMajorVersion string `dynamodbav:"document_major_version"`
DocumentMinorVersion string `dynamodbav:"document_minor_version"`
DocumentCreationDate string `dynamodbav:"document_creation_date"`
DocumentTabs []v1Models.DocumentTab `dynamodbav:"document_tabs"`
}
72 changes: 50 additions & 22 deletions cla-backend-go/signatures/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type SignatureRepository interface {
DeleteGithubOrganizationFromApprovalList(ctx context.Context, signatureID, githubOrganizationID string) ([]models.GithubOrg, error)
ValidateProjectRecord(ctx context.Context, signatureID, note string) error
InvalidateProjectRecord(ctx context.Context, signatureID, note string) error
CreateOrUpdateSignature(ctx context.Context, signature *models.Signature) (*models.Signature, error)
UpdateEnvelopeDetails(ctx context.Context, signatureID, envelopeID string, signURL *string) (*models.Signature, error)

GetSignature(ctx context.Context, signatureID string) (*models.Signature, error)
GetActivePullRequestMetadata(ctx context.Context, gitHubAuthorUsername, gitHubAuthorEmail string) (*ActivePullRequest, error)
Expand Down Expand Up @@ -447,37 +447,65 @@ func (repo repository) GetSignature(ctx context.Context, signatureID string) (*m
}

// CreateOrUpdateSignature either creates or updates the signature record
func (repo repository) CreateOrUpdateSignature(ctx context.Context, signature *models.Signature) (*models.Signature, error) {
func (repo repository) UpdateEnvelopeDetails(ctx context.Context, signatureID, envelopeID string, signURL *string) (*models.Signature, error) {
f := logrus.Fields{
"functionName": "v1.signatures.repository.CreateOrUpdateSignature",
"functionName": "v1.signatures.repository.UpdateEnvelopeDetails",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
"signatureID": signatureID,
"envelopeID": envelopeID,
}

// Check if we have an existing signature record
existingSignature, sigErr := repo.GetSignature(ctx, signature.SignatureID)
if sigErr != nil {
log.WithFields(f).Warnf("error retrieving signature by ID: %s, error: %v", signature.SignatureID, sigErr)
return nil, sigErr
log.WithFields(f).Debugf("setting envelope details....")

updateExpression := "SET signature_envelope_id = :envelopeId "
expressionAttributeValues := map[string]*dynamodb.AttributeValue{
":envelopeId": {
S: aws.String(envelopeID),
},
}

// If we have an existing signature record, we need to update it
if existingSignature != nil {
log.WithFields(f).Debugf("updating existing signature record for signature ID: %s", signature.SignatureID)
return repo.updateSignature(ctx, signature)
if signURL != nil {
updateExpression += ",signature_sign_url = :signUrl "
expressionAttributeValues[":signUrl"] = &dynamodb.AttributeValue{
S: aws.String(*signURL),
}
}

return nil, nil
}
// Create the update input
input := &dynamodb.UpdateItemInput{
TableName: aws.String(repo.signatureTableName),
Key: map[string]*dynamodb.AttributeValue{
"signature_id": {
S: aws.String(signatureID),
},
},
UpdateExpression: aws.String(updateExpression),
ExpressionAttributeValues: expressionAttributeValues,
ReturnValues: aws.String("ALL_NEW"),
}

// updateSignature updates the specified signature record
func (repo repository) updateSignature(ctx context.Context, signature *models.Signature) (*models.Signature, error) {
// f := logrus.Fields{
// "functionName": "v1.signatures.repository.updateSignature",
// utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
// }
// Update the record in the DynamoDB table
result, err := repo.dynamoDBClient.UpdateItem(input)
if err != nil {
log.WithFields(f).Errorf("Error updating signature record: %v", err)
return nil, err
}

// // Update the record in the database
return nil, nil
// Update the record in the DynamoDB table
var updatedItem ItemSignature

if err := dynamodbattribute.UnmarshalMap(result.Attributes, &updatedItem); err != nil {
log.WithFields(f).Errorf("Error unmarshalling updated item: %v", err)
return nil, err
}

log.WithFields(f).Debugf("updated signature record for: %s", signatureID)
return &models.Signature{
SignatureID: updatedItem.SignatureID,
SignatureSignURL: updatedItem.SignatureSignURL,
ProjectID: updatedItem.SignatureProjectID,
SignatureReferenceID: updatedItem.SignatureReferenceID,
}, nil
}

// GetIndividualSignature returns the signature record for the specified CLA Group and User
Expand Down
6 changes: 3 additions & 3 deletions cla-backend-go/signatures/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type SignatureService interface {

createOrGetEmployeeModels(ctx context.Context, claGroupModel *models.ClaGroup, companyModel *models.Company, corporateSignatureModel *models.Signature) ([]*models.User, error)
CreateOrUpdateEmployeeSignature(ctx context.Context, claGroupModel *models.ClaGroup, companyModel *models.Company, corporateSignatureModel *models.Signature) ([]*models.User, error)
CreateOrUpdateSignature(ctx context.Context, signature *models.Signature) (*models.Signature, error)
UpdateEnvelopeDetails(ctx context.Context, signatureID, envelopeID string, signURL *string) (*models.Signature, error)
handleGitHubStatusUpdate(ctx context.Context, employeeUserModel *models.User) error
}

Expand Down Expand Up @@ -143,8 +143,8 @@ func (s service) GetProjectSignatures(ctx context.Context, params signatures.Get
}

// CreateOrUpdateEmployeeSignature creates or updates the specified signature
func (s service) CreateOrUpdateSignature(ctx context.Context, signature *models.Signature) (*models.Signature, error) {
return s.repo.CreateOrUpdateSignature(ctx, signature)
func (s service) UpdateEnvelopeDetails(ctx context.Context, signatureID, envelopeID string, signURL *string) (*models.Signature, error) {
return s.repo.UpdateEnvelopeDetails(ctx, signatureID, envelopeID, signURL)
}

// CreateProjectSummaryReport generates a project summary report based on the specified input
Expand Down
2 changes: 2 additions & 0 deletions cla-backend-go/swagger/common/signature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ properties:
signatureSignURL:
type: string
description: the signature Document Sign URL
sigTypeSignedApprovedId:
type: string
signatureCallbackURL:
type: string
description: the signature callback URL
Expand Down
Loading
Loading