Add document viewer with proper 404 handling for trust center

Move document download/view to a dedicated viewer page with PDF preview,
access request flow, and a proper 404 error boundary when documents are
not found. The backend now returns NOT_FOUND instead of INTERNAL for
missing documents and reports.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-16 19:02:51 +01:00
parent dc8e6d0817
commit 7ffb2d5e94
17 changed files with 750 additions and 137 deletions

View File

@@ -90,6 +90,7 @@ func (s *DocumentService) ExportPDFWithoutWatermark(
func (s DocumentService) Get(
ctx context.Context,
organizationID gid.GID,
documentID gid.GID,
) (*coredata.Document, error) {
document := &coredata.Document{}
@@ -110,6 +111,14 @@ func (s DocumentService) Get(
return nil, err
}
if document.OrganizationID != organizationID {
return nil, ErrDocumentNotFound
}
if document.TrustCenterVisibility == coredata.TrustCenterVisibilityNone {
return nil, ErrDocumentNotVisible
}
return document, nil
}

View File

@@ -23,5 +23,10 @@ var (
ErrUserNotFound = errors.New("user not found")
ErrUserInactive = errors.New("user inactive")
ErrDocumentAccessNotFound = errors.New("document access not found")
ErrNDAFileNotFound = errors.New("NDA file not found")
ErrNDAFileNotFound = errors.New("NDA file not found")
ErrDocumentNotFound = errors.New("document not found")
ErrDocumentNotVisible = errors.New("document not visible")
ErrReportNotFound = errors.New("report not found")
ErrTrustCenterFileNotFound = errors.New("trust center file not found")
ErrTrustCenterFileNotVisible = errors.New("trust center file not visible")
)

View File

@@ -33,6 +33,23 @@ type ReportService struct {
}
func (s ReportService) Get(
ctx context.Context,
organizationID gid.GID,
reportID gid.GID,
) (*coredata.Report, error) {
report, err := s.loadByID(ctx, reportID)
if err != nil {
return nil, err
}
if report.OrganizationID != organizationID {
return nil, ErrReportNotFound
}
return report, nil
}
func (s ReportService) loadByID(
ctx context.Context,
reportID gid.GID,
) (*coredata.Report, error) {
@@ -62,7 +79,7 @@ func (s ReportService) GenerateDownloadURL(
reportID gid.GID,
expiresIn time.Duration,
) (*string, error) {
report, err := s.Get(ctx, reportID)
report, err := s.loadByID(ctx, reportID)
if err != nil {
return nil, fmt.Errorf("cannot get report: %w", err)
}
@@ -114,7 +131,7 @@ func (s ReportService) exportPDFData(
ctx context.Context,
reportID gid.GID,
) ([]byte, error) {
report, err := s.Get(ctx, reportID)
report, err := s.loadByID(ctx, reportID)
if err != nil {
return nil, fmt.Errorf("cannot get report: %w", err)
}

View File

@@ -34,6 +34,7 @@ type TrustCenterFileService struct {
func (s *TrustCenterFileService) Get(
ctx context.Context,
organizationID gid.GID,
trustCenterFileID gid.GID,
) (*coredata.TrustCenterFile, error) {
trustCenterFile := &coredata.TrustCenterFile{}
@@ -54,6 +55,14 @@ func (s *TrustCenterFileService) Get(
return nil, err
}
if trustCenterFile.OrganizationID != organizationID {
return nil, ErrTrustCenterFileNotFound
}
if trustCenterFile.TrustCenterVisibility == coredata.TrustCenterVisibilityNone {
return nil, ErrTrustCenterFileNotVisible
}
return trustCenterFile, nil
}