Skip to content

Commit

Permalink
Merge pull request #4156 from nickmango/bug/docsign-lint-fixes
Browse files Browse the repository at this point in the history
[#4002]Feature/Docsign intgeration Lint
  • Loading branch information
nickmango authored Oct 23, 2023
2 parents 95b4d98 + 48a4ee5 commit 3a0698c
Showing 1 changed file with 72 additions and 39 deletions.
111 changes: 72 additions & 39 deletions cla-backend-go/v2/sign/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (s *service) populateSignURL(ctx context.Context,
authorityOrSignatoryName, authorityOrSignatoryEmail string,
sendAsEmail bool,
claManagerName, claManagerEmail string,
defaultValues map[string]interface{}, preferredEmail string) error {
defaultValues map[string]interface{}, preferredEmail string) error {

f := logrus.Fields{
"functionName": "sign.populateSignURL",
Expand All @@ -663,8 +663,8 @@ func (s *service) populateSignURL(ctx context.Context,
log.WithFields(f).Debugf("signatureReferenceType: %s", signatureReferenceType)
log.WithFields(f).Debugf("processing signing request...")

userSignatureName := Unknown
userSignatureEmail := Unknown
var userSignatureName string
var userSignatureEmail string
var document v1Models.ClaGroupDocument
var project *v1Models.ClaGroup
var companyModel *v1Models.Company
Expand All @@ -673,45 +673,21 @@ func (s *service) populateSignURL(ctx context.Context,
var emailBody string
var emailSubject string

if signatureReferenceType == utils.SignatureReferenceTypeCompany {
companyModel, err = s.companyRepo.GetCompany(ctx, latestSignature.SignatureReferenceID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to lookup company by ID: %s", latestSignature.SignatureReferenceID)
return err
}
if companyModel == nil {
log.WithFields(f).WithError(err).Warnf("unable to lookup company by ID: %s", latestSignature.SignatureReferenceID)
return errors.New("no CLA manager lookup error")
}
userSignatureName = claManagerName
userSignatureEmail = claManagerEmail
} else if signatureReferenceType == utils.SignatureReferenceTypeUser {
if !sendAsEmail {
userModel, userErr := s.userService.GetUser(latestSignature.SignatureReferenceID)
if userErr != nil {
log.WithFields(f).WithError(userErr).Warnf("unable to lookup user by ID: %s", latestSignature.SignatureReferenceID)
return userErr
}
log.WithFields(f).Debugf("loaded user : %+v", userModel)

if userModel == nil {
log.WithFields(f).WithError(userErr).Warnf("unable to lookup user by ID: %s", latestSignature.SignatureReferenceID)
msg := fmt.Sprintf("No user lookup error for user ID: %s", latestSignature.SignatureReferenceID)
return errors.New(msg)
}
// companyModel, userSignatureName, userSignatureEmail, shouldReturn, returnValue := newFunction(ctx, signatureReferenceType, companyModel, err, s, latestSignature, f, userSignatureName, claManagerName, userSignatureEmail, claManagerEmail, sendAsEmail, preferredEmail)
// if shouldReturn {
// return returnValue
// }

if userModel.Username != "" {
userSignatureName = userModel.Username
}
if getUserEmail(userModel, preferredEmail) != "" {
userSignatureEmail = getUserEmail(userModel, preferredEmail)
}
}
} else {
log.WithFields(f).Warnf("unknown signature reference type: %s", signatureReferenceType)
return errors.New("unknown signature reference type")
// populate user details
userDetails, err := s.populateUserDetails(ctx, signatureReferenceType, latestSignature, claManagerName, claManagerEmail, sendAsEmail, preferredEmail)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to populate user details for signatureReferenceType: %s", signatureReferenceType)
return err
}

userSignatureName = userDetails.userSignatureName
userSignatureEmail = userDetails.userSignatureEmail

// Get the document template to sign
log.WithFields(f).Debugf("getting document template to sign...")
project, err = s.projectRepo.GetCLAGroupByID(ctx, latestSignature.ProjectID, DontLoadRepoDetails)
Expand Down Expand Up @@ -994,6 +970,63 @@ func (s *service) populateSignURL(ctx context.Context,
return nil
}

type UserSignDetails struct {
userSignatureName string
userSignatureEmail string
}

func (s *service) populateUserDetails(ctx context.Context, signatureReferenceType string, latestSignature *v1Models.Signature, claManagerName, claManagerEmail string, sendAsEmail bool, preferredEmail string) (*UserSignDetails, error) {
f := logrus.Fields{
"functionName": "sign.populateUserDetails",
}
log.WithFields(f).Debugf("populating user details...")
userSignDetails := &UserSignDetails{
userSignatureName: Unknown,
userSignatureEmail: Unknown,
}

if signatureReferenceType == utils.SignatureReferenceTypeCompany {
companyModel, err := s.companyRepo.GetCompany(ctx, latestSignature.SignatureReferenceID)
if err != nil {
log.WithFields(f).WithError(err).Warnf("unable to lookup company by ID: %s", latestSignature.SignatureReferenceID)
return nil, err
}
if companyModel == nil {
log.WithFields(f).WithError(err).Warnf("unable to lookup company by ID: %s", latestSignature.SignatureReferenceID)
return nil, errors.New("no CLA manager lookup error")
}
userSignDetails.userSignatureEmail = claManagerEmail
userSignDetails.userSignatureName = claManagerName

} else if signatureReferenceType == utils.SignatureReferenceTypeUser {
if !sendAsEmail {
userModel, userErr := s.userService.GetUser(latestSignature.SignatureReferenceID)
if userErr != nil {
log.WithFields(f).WithError(userErr).Warnf("unable to lookup user by ID: %s", latestSignature.SignatureReferenceID)
return nil, userErr
}
log.WithFields(f).Debugf("loaded user : %+v", userModel)

if userModel == nil {
log.WithFields(f).WithError(userErr).Warnf("unable to lookup user by ID: %s", latestSignature.SignatureReferenceID)
msg := fmt.Sprintf("No user lookup error for user ID: %s", latestSignature.SignatureReferenceID)
return nil, errors.New(msg)
}

if userModel.Username != "" {
userSignDetails.userSignatureName = userModel.Username
}
if getUserEmail(userModel, preferredEmail) != "" {
userSignDetails.userSignatureEmail = getUserEmail(userModel, preferredEmail)
}
}
} else {
log.WithFields(f).Warnf("unknown signature reference type: %s", signatureReferenceType)
return nil, errors.New("unknown signature reference type")
}
return userSignDetails, nil
}

func (s *service) getDocumentResource(urlString string) ([]byte, error) {

// validate the URL
Expand Down

0 comments on commit 3a0698c

Please sign in to comment.