Add company name and logo to documents

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-10-08 16:04:27 +02:00
parent 9bdecdf232
commit d757c9604b
23 changed files with 1391 additions and 203 deletions

View File

@@ -141,6 +141,7 @@ func (s *DocumentService) exportPDFData(
document := &coredata.Document{}
version := &coredata.DocumentVersion{}
owner := &coredata.People{}
organization := &coredata.Organization{}
err := s.svc.pg.WithConn(
ctx,
@@ -161,6 +162,10 @@ func (s *DocumentService) exportPDFData(
return fmt.Errorf("cannot load document owner: %w", err)
}
if err := organization.LoadByID(ctx, conn, s.svc.scope, document.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err)
}
return nil
},
)
@@ -177,13 +182,28 @@ func (s *DocumentService) exportPDFData(
classification = docgen.ClassificationSecret
}
horizontalLogoBase64 := ""
if organization.HorizontalLogoFileID != nil {
fileRecord := &coredata.File{}
fileErr := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
return fileRecord.LoadByID(ctx, conn, s.svc.scope, *organization.HorizontalLogoFileID)
})
if fileErr == nil {
base64Data, mimeType, logoErr := s.svc.fileManager.GetFileBase64(ctx, fileRecord)
if logoErr == nil {
horizontalLogoBase64 = fmt.Sprintf("data:%s;base64,%s", mimeType, base64Data)
}
}
}
docData := docgen.DocumentData{
Title: version.Title,
Content: version.Content,
Version: version.VersionNumber,
Classification: classification,
Approver: owner.FullName,
PublishedAt: version.PublishedAt,
Title: version.Title,
Content: version.Content,
Version: version.VersionNumber,
Classification: classification,
Approver: owner.FullName,
PublishedAt: version.PublishedAt,
CompanyHorizontalLogoBase64: horizontalLogoBase64,
}
htmlContent, err := docgen.RenderHTML(docData)

View File

@@ -71,19 +71,30 @@ func (s OrganizationService) GenerateLogoURL(
return nil, fmt.Errorf("cannot get organization: %w", err)
}
if organization.LogoObjectKey == "" {
if organization.LogoFileID == nil {
return nil, nil
}
file := &coredata.File{}
err = s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return file.LoadByID(ctx, conn, s.svc.scope, *organization.LogoFileID)
},
)
if err != nil {
return nil, fmt.Errorf("cannot load file: %w", err)
}
presignClient := s3.NewPresignClient(s.svc.s3)
encodedFilename := url.QueryEscape(organization.Name)
encodedFilename := url.QueryEscape(file.FileName)
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
encodedFilename, encodedFilename)
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(s.svc.bucket),
Key: aws.String(organization.LogoObjectKey),
Key: aws.String(file.FileKey),
ResponseCacheControl: aws.String("max-age=3600, public"),
ResponseContentDisposition: aws.String(contentDisposition),
}, func(opts *s3.PresignOptions) {

View File

@@ -18,6 +18,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/getprobo/probo/pkg/coredata"
"github.com/getprobo/probo/pkg/crypto/cipher"
"github.com/getprobo/probo/pkg/filemanager"
"github.com/getprobo/probo/pkg/gid"
"github.com/getprobo/probo/pkg/html2pdf"
"github.com/getprobo/probo/pkg/probo"
@@ -35,27 +36,29 @@ type (
tokenSecret string
usrmgr *usrmgr.Service
html2pdfConverter *html2pdf.Converter
fileManager *filemanager.Service
}
TenantService struct {
pg *pg.Client
s3 *s3.Client
bucket string
scope coredata.Scoper
proboSvc *probo.Service
encryptionKey cipher.EncryptionKey
tokenSecret string
usrmgr *usrmgr.Service
html2pdfConverter *html2pdf.Converter
TrustCenters *TrustCenterService
Documents *DocumentService
Audits *AuditService
Vendors *VendorService
Frameworks *FrameworkService
TrustCenterAccesses *TrustCenterAccessService
pg *pg.Client
s3 *s3.Client
bucket string
scope coredata.Scoper
proboSvc *probo.Service
encryptionKey cipher.EncryptionKey
tokenSecret string
usrmgr *usrmgr.Service
html2pdfConverter *html2pdf.Converter
fileManager *filemanager.Service
TrustCenters *TrustCenterService
Documents *DocumentService
Audits *AuditService
Vendors *VendorService
Frameworks *FrameworkService
TrustCenterAccesses *TrustCenterAccessService
TrustCenterReferences *TrustCenterReferenceService
Reports *ReportService
Organizations *OrganizationService
Reports *ReportService
Organizations *OrganizationService
}
)
@@ -67,6 +70,7 @@ func NewService(
tokenSecret string,
usrmgr *usrmgr.Service,
html2pdfConverter *html2pdf.Converter,
fileManagerService *filemanager.Service,
) *Service {
return &Service{
pg: pgClient,
@@ -76,6 +80,7 @@ func NewService(
tokenSecret: tokenSecret,
usrmgr: usrmgr,
html2pdfConverter: html2pdfConverter,
fileManager: fileManagerService,
}
}
@@ -90,6 +95,7 @@ func (s *Service) WithTenant(tenantID gid.TenantID) *TenantService {
tokenSecret: s.tokenSecret,
usrmgr: s.usrmgr,
html2pdfConverter: s.html2pdfConverter,
fileManager: s.fileManager,
}
tenantService.TrustCenters = &TrustCenterService{svc: tenantService}