Skip to content

Commit

Permalink
Feature/CCla callback
Browse files Browse the repository at this point in the history
- Completed ccla callback handler
- Resolved ccla docusign flow issues

Signed-off-by: Harold Wanyama <[email protected]>
  • Loading branch information
nickmango committed Dec 7, 2023
1 parent 1ef6255 commit 739d3f9
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 27 deletions.
21 changes: 21 additions & 0 deletions cla-backend-go/events/event_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,27 @@ type IndividualSignatureSignedEventData struct {
ProjectID string
}

type CorporateSignatureSignedEventData struct {
ProjectName string
CompanyName string
SignatoryName string
}

func (ed *CorporateSignatureSignedEventData) GetEventDetailsString(args *LogEventArgs) (string, bool) {
data := fmt.Sprintf("The signature was signed for the project %s and company %s by %s", args.ProjectName, ed.CompanyName, ed.SignatoryName)
if args.UserName != "" {
data = fmt.Sprintf("%s by the user %s", data, args.UserName)
}
data = fmt.Sprintf("%s.", data)
return data, true
}

func (ed *CorporateSignatureSignedEventData) GetEventSummaryString(args *LogEventArgs) (string, bool) {
data := fmt.Sprintf("The signature was signed for the project %s and company %s by %s", args.ProjectName, ed.CompanyName, ed.SignatoryName)
data = fmt.Sprintf("%s.", data)
return data, true
}

// GetEventDetailsString returns the details string for this event
func (ed *SignatureAutoCreateECLAUpdatedEventData) GetEventDetailsString(args *LogEventArgs) (string, bool) {

Expand Down
1 change: 1 addition & 0 deletions cla-backend-go/events/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ const (
SignatureAutoCreateECLAUpdated = "signature.auto_create_ecla.updated"

IndividualSignatureSigned = "individual.signature.signed"
CorporateSignatureSigned = "corporate.signature.signed"
)
4 changes: 4 additions & 0 deletions cla-backend-go/swagger/cla.v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,8 @@ paths:
description: Receives XML data when an individual signs a document in DocuSign linked to Gerrit.
operationId: iclaCallbackGerrit
security: [ ]
consumes:
- text/xml
parameters:
- $ref: "#/parameters/x-request-id"
- name: user_id
Expand All @@ -4245,6 +4247,8 @@ paths:
description: Receives XML data when a corporate entity signs a document in DocuSign associated with a specific project.
operationId: cclaCallback
security: [ ]
consumes:
- text/xml
parameters:
- $ref: "#/parameters/x-request-id"
- name: project_id
Expand Down
31 changes: 24 additions & 7 deletions cla-backend-go/v2/sign/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

var (
// payload is the payload for the docusign callback
iclaGitHubPayload []byte
iclaGitHubPayload []byte
cclaDocusignPayload []byte
)

// docusignMiddleware is used to get access to xml request body
Expand All @@ -53,6 +54,26 @@ func docusignMiddleware(next http.Handler) http.Handler {
})
}

func cclaDocusignMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
f := logrus.Fields{
"functionName": "v2.sign.handlers.cclaDocusignMiddleware",
}
var err error
log.WithFields(f).Debug("docusign middleware...")
cclaDocusignPayload, err = io.ReadAll(r.Body)
if err != nil {
log.Warnf("unable to read request body")
return
}
r.Body.Close()
r.Body = io.NopCloser(bytes.NewBuffer(cclaDocusignPayload))
log.WithFields(f).Debugf("docusign middleware...payload: %s", string(cclaDocusignPayload))
// call the next middleware
next.ServeHTTP(w, r)
})
}

// Configure API call
func Configure(api *operations.EasyclaAPI, service Service, userService users.Service) {
// Retrieve a list of available templates
Expand Down Expand Up @@ -224,21 +245,17 @@ func Configure(api *operations.EasyclaAPI, service Service, userService users.Se
"functionName": "v2.sign.handlers.SignCclaCallbackHandler",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
}
payload, marshalErr := json.Marshal(params.Body)
if marshalErr != nil {
log.WithFields(f).WithError(marshalErr).Warn("unable to marshal github callback body")
return sign.NewIclaCallbackGithubBadRequest()
}

log.WithFields(f).Debug("ccla callback")
err := service.SignedCorporateCallback(ctx, payload, params.CompanyID, params.ProjectID)
err := service.SignedCorporateCallback(ctx, cclaDocusignPayload, params.CompanyID, params.ProjectID)
if err != nil {
return sign.NewCclaCallbackBadRequest()
}
return sign.NewCclaCallbackOK()
})

api.AddMiddlewareFor("POST", "/signed/individual/{installation_id}/{github_repository_id}/{change_request_id}", docusignMiddleware)
api.AddMiddlewareFor("POST", "/signed/corporate/{project_id}/{company_id}", cclaDocusignMiddleware)
}

type codedResponse interface {
Expand Down
Loading

0 comments on commit 739d3f9

Please sign in to comment.