Skip to content

Commit

Permalink
update api of org signature
Browse files Browse the repository at this point in the history
  • Loading branch information
zengchen1024 committed Jan 10, 2021
1 parent aab5e2d commit a39455f
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 273 deletions.
2 changes: 1 addition & 1 deletion controllers/corporation-pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ func (this *CorporationPDFController) Preview() {
Info: dbmodels.TypeSigningInfo(value),
}

pdf.GetPDFGenerator().GenPDFForCorporationSigning(orgCLA, &signing, cla)
pdf.GetPDFGenerator().GenPDFForCorporationSigning("", orgCLA, &signing, cla)
// TODO: not finished
}
5 changes: 4 additions & 1 deletion controllers/corporation-signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (this *CorporationSigningController) Post() {

this.sendSuccessResp("sign successfully")

worker.GetEmailWorker().GenCLAPDFForCorporationAndSendIt(orgCLA, &info.CorporationSigning, cla)
worker.GetEmailWorker().GenCLAPDFForCorporationAndSendIt(
genOrgSignatureFilePath(orgCLAID, cla.Language),
orgCLA, &info.CorporationSigning, cla)
}

// @Title ResendCorpSigningEmail
Expand Down Expand Up @@ -126,6 +128,7 @@ func (this *CorporationSigningController) ResendCorpSigningEmail() {
this.sendSuccessResp("resend email successfully")

worker.GetEmailWorker().GenCLAPDFForCorporationAndSendIt(
genOrgSignatureFilePath(linkID, cla.Language),
orgCLA, (*models.CorporationSigning)(signingInfo), cla,
)

Expand Down
126 changes: 16 additions & 110 deletions controllers/org-signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package controllers

import (
"fmt"
"io/ioutil"

"github.com/opensourceways/app-cla-server/conf"
"github.com/opensourceways/app-cla-server/models"
"github.com/opensourceways/app-cla-server/pdf"
"github.com/opensourceways/app-cla-server/util"
)
Expand All @@ -15,138 +12,47 @@ type OrgSignatureController struct {
}

func (this *OrgSignatureController) Prepare() {
apiPrepare(&this.Controller, []string{PermissionOwnerOfOrg})
}

// @Title Post
// @Description upload org signature
// @Param org_cla_id path string true "org cla id"
// @router /:org_cla_id [post]
func (this *OrgSignatureController) Post() {
var statusCode = 0
var errCode = ""
var reason error
var body interface{}

defer func() {
sendResponse(&this.Controller, statusCode, errCode, reason, body, "upload org signature")
}()

orgCLAID, err := fetchStringParameter(&this.Controller, ":org_cla_id")
if err != nil {
reason = err
errCode = util.ErrInvalidParameter
statusCode = 400
return
}

var orgCLA *models.OrgCLA
orgCLA, statusCode, errCode, reason = canAccessOrgCLA(&this.Controller, orgCLAID)
if reason != nil {
return
}
if isNotCorpCLA(orgCLA) {
reason = fmt.Errorf("no need upload org signature for individual signing")
errCode = util.ErrInvalidParameter
statusCode = 400
return
}

f, _, err := this.GetFile("signature_page")
if err != nil {
reason = err
errCode = util.ErrInvalidParameter
statusCode = 400
return
}

defer f.Close()

data, err := ioutil.ReadAll(f)
if err != nil {
reason = err
return
}

if len(data) > (200 << 10) {
reason = fmt.Errorf("big pdf file")
errCode = util.ErrInvalidParameter
statusCode = 400
return
}

err = models.UploadOrgSignature(orgCLAID, data)
if err != nil {
reason = err
return
}

body = "upload pdf of signature page successfully"
}

func (this *OrgSignatureController) downloadPDF(fileName string, pdf *[]byte) *failedApiResult {
dir := util.GenFilePath(conf.AppConfig.PDFOutDir, "tmp")
name := fmt.Sprintf("%s_*.pdf", fileName)

f, err := ioutil.TempFile(dir, name)
if err != nil {
return newFailedApiResult(500, util.ErrSystemError, err)
}

_, err = f.Write(*pdf)
if err != nil {
return newFailedApiResult(500, util.ErrSystemError, err)
}

downloadFile(&this.Controller, f.Name())
return nil
this.apiPrepare(PermissionOwnerOfOrg)
}

// @Title Get
// @Description download org signature
// @Param org_cla_id path string true "org cla id"
// @router /:org_cla_id [get]
// @router /:link_id/:language [get]
func (this *OrgSignatureController) Get() {
rs := func(statusCode int, errCode string, reason error) {
sendResponse(&this.Controller, statusCode, errCode, reason, nil, "download org signature")
}
action := "download org signature"
linkID := this.GetString(":link_id")
claLang := this.GetString(":language")

orgCLAID, err := fetchStringParameter(&this.Controller, ":org_cla_id")
if err != nil {
rs(400, util.ErrInvalidParameter, err)
pl, fr := this.tokenPayloadBasedOnCodePlatform()
if fr != nil {
this.sendFailedResultAsResp(fr, action)
return
}

_, statusCode, errCode, reason := canAccessOrgCLA(&this.Controller, orgCLAID)
if reason != nil {
rs(statusCode, errCode, reason)
if fr := pl.isOwnerOfLink(linkID); fr != nil {
this.sendFailedResultAsResp(fr, action)
return
}

pdf, err := models.DownloadOrgSignature(orgCLAID)
if err != nil {
rs(0, "", err)
path := genOrgSignatureFilePath(linkID, claLang)
if util.IsFileNotExist(path) {
this.sendFailedResponse(400, errFileNotExists, fmt.Errorf(errFileNotExists), action)
return
}

if fr := this.downloadPDF(orgCLAID, &pdf); fr != nil {
rs(fr.statusCode, fr.errCode, fr.reason)
}

this.downloadFile(path)
}

// @Title BlankSignature
// @Description get blank pdf of org signature
// @Param language path string true "The language which the signature applies to"
// @router /blank/:language [get]
func (this *OrgSignatureController) BlankSignature() {
sendResp := this.newFuncForSendingFailedResp("download blank signature")

lang := this.GetString(":language")
path := pdf.GetPDFGenerator().GetBlankSignaturePath(lang)

path := pdf.GetPDFGenerator().GetBlankSignaturePath(lang)
if util.IsFileNotExist(path) {
sendResp(newFailedApiResult(400, errFileNotExists, fmt.Errorf(errFileNotExists)))
this.sendFailedResponse(400, errFileNotExists, fmt.Errorf(errFileNotExists), "download blank signature")
return
}

Expand Down
7 changes: 0 additions & 7 deletions dbmodels/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type IDB interface {
IIndividualSigning
ICLA
IVerificationCode
IPDF
}

type ICorporationSigning interface {
Expand Down Expand Up @@ -91,12 +90,6 @@ type IVerificationCode interface {
GetVerificationCode(opt *VerificationCode) IDBError
}

type IPDF interface {
UploadOrgSignature(orgCLAID string, pdf []byte) error
DownloadOrgSignature(orgCLAID string) ([]byte, error)
DownloadOrgSignatureByMd5(orgCLAID, md5sum string) ([]byte, error)
}

type ILink interface {
GetLinkID(orgRepo *OrgRepo) (string, IDBError)
CreateLink(info *LinkCreateOption) (string, IDBError)
Expand Down
17 changes: 0 additions & 17 deletions models/org-signature.go

This file was deleted.

95 changes: 0 additions & 95 deletions mongodb/org-signature.go

This file was deleted.

2 changes: 1 addition & 1 deletion pdf/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type IPDFGenerator interface {
LangSupported() map[string]bool
GetBlankSignaturePath(string) string

GenPDFForCorporationSigning(orgCLA *models.OrgCLA, signing *models.CorporationSigning, cla *models.CLA) (string, error)
GenPDFForCorporationSigning(string, *models.OrgCLA, *models.CorporationSigning, *models.CLA) (string, error)
}

var generator *pdfGenerator
Expand Down
Loading

0 comments on commit a39455f

Please sign in to comment.