259 lines
9.0 KiB
Go
259 lines
9.0 KiB
Go
package trust_v1
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.76
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/getprobo/probo/pkg/coredata"
|
|
"github.com/getprobo/probo/pkg/gid"
|
|
"github.com/getprobo/probo/pkg/page"
|
|
"github.com/getprobo/probo/pkg/server/api/trust/v1/schema"
|
|
"github.com/getprobo/probo/pkg/server/api/trust/v1/types"
|
|
)
|
|
|
|
// Framework is the resolver for the framework field.
|
|
func (r *auditResolver) Framework(ctx context.Context, obj *types.Audit) (*types.Framework, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
audit, err := trust.Audits.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load audit: %w", err)
|
|
}
|
|
|
|
framework, err := trust.Frameworks.Get(ctx, audit.FrameworkID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load framework: %w", err)
|
|
}
|
|
|
|
return types.NewFramework(framework), nil
|
|
}
|
|
|
|
// Report is the resolver for the report field.
|
|
func (r *auditResolver) Report(ctx context.Context, obj *types.Audit) (*types.Report, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
audit, err := trust.Audits.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load audit: %w", err)
|
|
}
|
|
|
|
if audit.ReportID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
report, err := trust.Reports.Get(ctx, *audit.ReportID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load report: %w", err)
|
|
}
|
|
|
|
return types.NewReport(report), nil
|
|
}
|
|
|
|
// ReportURL is the resolver for the reportUrl field.
|
|
func (r *auditResolver) ReportURL(ctx context.Context, obj *types.Audit) (*string, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
audit, err := trust.Audits.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load audit: %w", err)
|
|
}
|
|
|
|
if audit.ReportID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
url, err := trust.Audits.GenerateReportURL(ctx, obj.ID, 15*time.Minute)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot generate report URL: %w", err)
|
|
}
|
|
|
|
return url, nil
|
|
}
|
|
|
|
// Versions is the resolver for the versions field.
|
|
func (r *documentResolver) Versions(ctx context.Context, obj *types.Document, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.DocumentVersionConnection, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
pageOrderBy := page.OrderBy[coredata.DocumentVersionOrderField]{
|
|
Field: coredata.DocumentVersionOrderFieldCreatedAt,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
// For the public trust API, only return published versions
|
|
page, err := trust.Documents.ListVersions(ctx, obj.ID, cursor)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot list document versions: %w", err)
|
|
}
|
|
|
|
// Filter to only published versions and create edges directly
|
|
publishedEdges := make([]*types.DocumentVersionEdge, 0)
|
|
for _, version := range page.Data {
|
|
if version.Status == coredata.DocumentStatusPublished {
|
|
edge := &types.DocumentVersionEdge{
|
|
Cursor: version.CursorKey(pageOrderBy.Field),
|
|
Node: types.NewDocumentVersion(version),
|
|
}
|
|
publishedEdges = append(publishedEdges, edge)
|
|
}
|
|
}
|
|
|
|
return &types.DocumentVersionConnection{
|
|
Edges: publishedEdges,
|
|
PageInfo: types.NewPageInfo(page),
|
|
}, nil
|
|
}
|
|
|
|
// ExportDocumentVersionPDF is the resolver for the exportDocumentVersionPDF field.
|
|
func (r *mutationResolver) ExportDocumentVersionPDF(ctx context.Context, input types.ExportDocumentVersionPDFInput) (*types.ExportDocumentVersionPDFPayload, error) {
|
|
trust := r.trustCenterSvc.WithTenant(input.DocumentVersionID.TenantID())
|
|
|
|
pdf, err := trust.Documents.ExportPDF(ctx, input.DocumentVersionID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot export document version PDF: %w", err)
|
|
}
|
|
|
|
return &types.ExportDocumentVersionPDFPayload{
|
|
Data: fmt.Sprintf("data:application/pdf;base64,%s", base64.StdEncoding.EncodeToString(pdf)),
|
|
}, nil
|
|
}
|
|
|
|
// LogoURL is the resolver for the logoUrl field.
|
|
func (r *organizationResolver) LogoURL(ctx context.Context, obj *types.Organization) (*string, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
return trust.Organizations.GenerateLogoURL(ctx, obj.ID, 1*time.Hour)
|
|
}
|
|
|
|
// TrustCenterBySlug is the resolver for the trustCenterBySlug field.
|
|
func (r *queryResolver) TrustCenterBySlug(ctx context.Context, slug string) (*types.TrustCenter, error) {
|
|
trust := r.trustCenterSvc.WithTenant(gid.NewTenantID())
|
|
|
|
trustCenter, err := trust.TrustCenters.GetBySlug(ctx, slug)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
if !trustCenter.Active {
|
|
return nil, nil
|
|
}
|
|
|
|
result := types.NewTrustCenter(trustCenter)
|
|
|
|
orgTrust := r.trustCenterSvc.WithTenant(trustCenter.TenantID)
|
|
org, err := orgTrust.Organizations.Get(ctx, trustCenter.OrganizationID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot get organization: %w", err)
|
|
}
|
|
|
|
result.Organization = types.NewOrganization(org)
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// DownloadURL is the resolver for the downloadUrl field.
|
|
func (r *reportResolver) DownloadURL(ctx context.Context, obj *types.Report) (*string, error) {
|
|
trust := r.TrustService(ctx, obj.ID.TenantID())
|
|
|
|
url, err := trust.Reports.GenerateDownloadURL(ctx, obj.ID, 5*time.Minute)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot generate download URL: %w", err)
|
|
}
|
|
|
|
return url, nil
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *trustCenterResolver) Organization(ctx context.Context, obj *types.TrustCenter) (*types.Organization, error) {
|
|
return obj.Organization, nil
|
|
}
|
|
|
|
// Documents is the resolver for the documents field.
|
|
func (r *trustCenterResolver) Documents(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.DocumentConnection, error) {
|
|
trust := r.trustCenterSvc.WithTenant(obj.Organization.ID.TenantID())
|
|
|
|
pageOrderBy := page.OrderBy[coredata.DocumentOrderField]{
|
|
Field: coredata.DocumentOrderFieldTitle,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
documentPage, err := trust.Documents.ListForOrganizationId(ctx, obj.Organization.ID, cursor)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot list public documents: %w", err)
|
|
}
|
|
|
|
return types.NewDocumentConnection(documentPage), nil
|
|
}
|
|
|
|
// Audits is the resolver for the audits field.
|
|
func (r *trustCenterResolver) Audits(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.AuditConnection, error) {
|
|
trust := r.trustCenterSvc.WithTenant(obj.Organization.ID.TenantID())
|
|
|
|
pageOrderBy := page.OrderBy[coredata.AuditOrderField]{
|
|
Field: coredata.AuditOrderFieldValidFrom,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
auditPage, err := trust.Audits.ListForOrganizationId(ctx, obj.Organization.ID, cursor)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot list public audits: %w", err)
|
|
}
|
|
|
|
return types.NewAuditConnection(auditPage), nil
|
|
}
|
|
|
|
// Vendors is the resolver for the vendors field.
|
|
func (r *trustCenterResolver) Vendors(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.VendorConnection, error) {
|
|
trust := r.trustCenterSvc.WithTenant(obj.Organization.ID.TenantID())
|
|
|
|
pageOrderBy := page.OrderBy[coredata.VendorOrderField]{
|
|
Field: coredata.VendorOrderFieldName,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
vendorPage, err := trust.Vendors.ListForOrganizationId(ctx, obj.Organization.ID, cursor)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot list public vendors: %w", err)
|
|
}
|
|
|
|
return types.NewVendorConnection(vendorPage), nil
|
|
}
|
|
|
|
// Audit returns schema.AuditResolver implementation.
|
|
func (r *Resolver) Audit() schema.AuditResolver { return &auditResolver{r} }
|
|
|
|
// Document returns schema.DocumentResolver implementation.
|
|
func (r *Resolver) Document() schema.DocumentResolver { return &documentResolver{r} }
|
|
|
|
// Mutation returns schema.MutationResolver implementation.
|
|
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
|
|
|
// Organization returns schema.OrganizationResolver implementation.
|
|
func (r *Resolver) Organization() schema.OrganizationResolver { return &organizationResolver{r} }
|
|
|
|
// Query returns schema.QueryResolver implementation.
|
|
func (r *Resolver) Query() schema.QueryResolver { return &queryResolver{r} }
|
|
|
|
// Report returns schema.ReportResolver implementation.
|
|
func (r *Resolver) Report() schema.ReportResolver { return &reportResolver{r} }
|
|
|
|
// TrustCenter returns schema.TrustCenterResolver implementation.
|
|
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
|
|
|
type auditResolver struct{ *Resolver }
|
|
type documentResolver struct{ *Resolver }
|
|
type mutationResolver struct{ *Resolver }
|
|
type organizationResolver struct{ *Resolver }
|
|
type queryResolver struct{ *Resolver }
|
|
type reportResolver struct{ *Resolver }
|
|
type trustCenterResolver struct{ *Resolver }
|