Trust GraphQL and MCP still exposed presigned URL strings for trust-center logos while console and connect already serve stable File.downloadUrl paths. Phase 1 migrates the seven public logo fields on trust GraphQL and the trust-center file references on MCP to the shared File type; trust GraphQL NDA stays on fileUrl for a follow-up. Trust resolvers load public files through filemanager and map them with types.NewFile. The trust app Relay queries and components now read logo.downloadUrl. MCP specification, resolvers, and helpers are updated in sync, including NDA on MCP where callers already have file access. filemanager is split into focused files and its URL surface is narrowed to GenerateFileURL(file) for stable app URLs and GeneratePresignedURL for S3 redirects. GetPublicFile remains the DB entry point when only a file ID is known. Add trust and MCP e2e coverage for public logo download URLs. Signed-off-by: Ludovic Vielle <ludovic@probo.com>
1280 lines
43 KiB
Go
1280 lines
43 KiB
Go
package console_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.90
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/vikstrous/dataloadgen"
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/iam"
|
|
"go.probo.inc/probo/pkg/page"
|
|
"go.probo.inc/probo/pkg/probo"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/dataloader"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/schema"
|
|
"go.probo.inc/probo/pkg/server/api/console/v1/types"
|
|
"go.probo.inc/probo/pkg/server/gqlutils"
|
|
"go.probo.inc/probo/pkg/validator"
|
|
)
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *complianceExternalURLResolver) Permission(ctx context.Context, obj *types.ComplianceExternalURL, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// Framework is the resolver for the framework field.
|
|
func (r *complianceFrameworkResolver) Framework(ctx context.Context, obj *types.ComplianceFramework) (*types.Framework, error) {
|
|
if _, err := r.authorize(ctx, obj.FrameworkID, probo.ActionFrameworkGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
loaders := dataloader.FromContext(ctx)
|
|
|
|
framework, err := loaders.Framework.Load(ctx, obj.FrameworkID)
|
|
if err != nil {
|
|
if errors.Is(err, dataloadgen.ErrNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot load framework", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewFramework(framework), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *customDomainResolver) Permission(ctx context.Context, obj *types.CustomDomain, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// UpdateTrustCenter is the resolver for the updateTrustCenter field.
|
|
func (r *mutationResolver) UpdateTrustCenter(ctx context.Context, input types.UpdateTrustCenterInput) (*types.UpdateTrustCenterPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.probo.TrustCenters.Update(
|
|
ctx, scope,
|
|
&probo.UpdateTrustCenterRequest{
|
|
ID: input.TrustCenterID,
|
|
Active: input.Active,
|
|
SearchEngineIndexing: input.SearchEngineIndexing,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update trust center", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateTrustCenterPayload{
|
|
TrustCenter: types.NewTrustCenter(trustCenter),
|
|
}, nil
|
|
}
|
|
|
|
// UploadTrustCenterNda is the resolver for the uploadTrustCenterNDA field.
|
|
func (r *mutationResolver) UploadTrustCenterNda(ctx context.Context, input types.UploadTrustCenterNDAInput) (*types.UploadTrustCenterNDAPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterNonDisclosureAgreementUpload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.probo.TrustCenters.UploadNDA(
|
|
ctx, scope,
|
|
&probo.UploadTrustCenterNDARequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
File: input.File.File,
|
|
FileName: input.FileName,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot upload trust center NDA", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UploadTrustCenterNDAPayload{
|
|
TrustCenter: types.NewTrustCenter(trustCenter),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteTrustCenterNda is the resolver for the deleteTrustCenterNDA field.
|
|
func (r *mutationResolver) DeleteTrustCenterNda(ctx context.Context, input types.DeleteTrustCenterNDAInput) (*types.DeleteTrustCenterNDAPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterNonDisclosureAgreementDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.probo.TrustCenters.DeleteNDA(ctx, scope, input.TrustCenterID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete trust center NDA", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteTrustCenterNDAPayload{
|
|
TrustCenter: types.NewTrustCenter(trustCenter),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterBrand is the resolver for the updateTrustCenterBrand field.
|
|
func (r *mutationResolver) UpdateTrustCenterBrand(ctx context.Context, input types.UpdateTrustCenterBrandInput) (*types.UpdateTrustCenterBrandPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req := &probo.UpdateTrustCenterBrandRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
}
|
|
|
|
if input.LogoFile.IsSet() {
|
|
logoFile := input.LogoFile.Value()
|
|
if logoFile == nil {
|
|
var nilFile *probo.FileUpload
|
|
|
|
req.LogoFile = &nilFile
|
|
} else {
|
|
fileUpload := &probo.FileUpload{
|
|
Content: logoFile.File,
|
|
Filename: logoFile.Filename,
|
|
Size: logoFile.Size,
|
|
ContentType: logoFile.ContentType,
|
|
}
|
|
req.LogoFile = &fileUpload
|
|
}
|
|
}
|
|
|
|
if input.DarkLogoFile.IsSet() {
|
|
darkLogoFile := input.DarkLogoFile.Value()
|
|
if darkLogoFile == nil {
|
|
var nilFile *probo.FileUpload
|
|
|
|
req.DarkLogoFile = &nilFile
|
|
} else {
|
|
fileUpload := &probo.FileUpload{
|
|
Content: darkLogoFile.File,
|
|
Filename: darkLogoFile.Filename,
|
|
Size: darkLogoFile.Size,
|
|
ContentType: darkLogoFile.ContentType,
|
|
}
|
|
req.DarkLogoFile = &fileUpload
|
|
}
|
|
}
|
|
|
|
trustCenter, _, err := r.probo.TrustCenters.UpdateTrustCenterBrand(ctx, scope, req)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update trust center brand", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateTrustCenterBrandPayload{
|
|
TrustCenter: types.NewTrustCenter(trustCenter),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterAccess is the resolver for the updateTrustCenterAccess field.
|
|
func (r *mutationResolver) UpdateTrustCenterAccess(ctx context.Context, input types.UpdateTrustCenterAccessInput) (*types.UpdateTrustCenterAccessPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterAccessUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var (
|
|
documentAccesses []probo.UpdateTrustCenterDocumentAccessRequest
|
|
reportAccesses []probo.UpdateTrustCenterDocumentAccessRequest
|
|
fileAccesses []probo.UpdateTrustCenterDocumentAccessRequest
|
|
)
|
|
|
|
for _, documentAccess := range input.Documents {
|
|
documentAccesses = append(documentAccesses, probo.UpdateTrustCenterDocumentAccessRequest{
|
|
ID: documentAccess.ID,
|
|
Status: documentAccess.Status,
|
|
})
|
|
}
|
|
|
|
for _, reportAccess := range input.Reports {
|
|
reportAccesses = append(reportAccesses, probo.UpdateTrustCenterDocumentAccessRequest{
|
|
ID: reportAccess.ID,
|
|
Status: reportAccess.Status,
|
|
})
|
|
}
|
|
|
|
for _, fileAccess := range input.TrustCenterFiles {
|
|
fileAccesses = append(fileAccesses, probo.UpdateTrustCenterDocumentAccessRequest{
|
|
ID: fileAccess.ID,
|
|
Status: fileAccess.Status,
|
|
})
|
|
}
|
|
|
|
access, err := r.probo.TrustCenterAccesses.Update(
|
|
ctx, scope,
|
|
&probo.UpdateTrustCenterAccessRequest{
|
|
ID: input.ID,
|
|
DocumentAccesses: documentAccesses,
|
|
ReportAccesses: reportAccesses,
|
|
TrustCenterFileAccesses: fileAccesses,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update trust center access", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateTrustCenterAccessPayload{
|
|
TrustCenterAccess: types.NewTrustCenterAccess(access),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteTrustCenterAccess is the resolver for the deleteTrustCenterAccess field.
|
|
func (r *mutationResolver) DeleteTrustCenterAccess(ctx context.Context, input types.DeleteTrustCenterAccessInput) (*types.DeleteTrustCenterAccessPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterAccessDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.probo.TrustCenterAccesses.Delete(ctx, scope, input.ID); err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete trust center access", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteTrustCenterAccessPayload{
|
|
DeletedTrustCenterAccessID: input.ID,
|
|
}, nil
|
|
}
|
|
|
|
// CreateTrustCenterReference is the resolver for the createTrustCenterReference field.
|
|
func (r *mutationResolver) CreateTrustCenterReference(ctx context.Context, input types.CreateTrustCenterReferenceInput) (*types.CreateTrustCenterReferencePayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterReferenceCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reference, err := r.probo.TrustCenterReferences.Create(
|
|
ctx, scope,
|
|
&probo.CreateTrustCenterReferenceRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
Name: input.Name,
|
|
Description: input.Description,
|
|
WebsiteURL: input.WebsiteURL,
|
|
LogoFile: probo.File{
|
|
Content: input.LogoFile.File,
|
|
Filename: input.LogoFile.Filename,
|
|
Size: input.LogoFile.Size,
|
|
ContentType: input.LogoFile.ContentType,
|
|
},
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create trust center reference", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateTrustCenterReferencePayload{
|
|
TrustCenterReferenceEdge: types.NewTrustCenterReferenceEdge(reference, coredata.TrustCenterReferenceOrderFieldRank),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterReference is the resolver for the updateTrustCenterReference field.
|
|
func (r *mutationResolver) UpdateTrustCenterReference(ctx context.Context, input types.UpdateTrustCenterReferenceInput) (*types.UpdateTrustCenterReferencePayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterReferenceUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req := &probo.UpdateTrustCenterReferenceRequest{
|
|
ID: input.ID,
|
|
Name: input.Name,
|
|
Description: gqlutils.UnwrapOmittable(input.Description),
|
|
WebsiteURL: input.WebsiteURL,
|
|
Rank: input.Rank,
|
|
}
|
|
|
|
if input.LogoFile != nil {
|
|
req.LogoFile = &probo.File{
|
|
Content: input.LogoFile.File,
|
|
Filename: input.LogoFile.Filename,
|
|
Size: input.LogoFile.Size,
|
|
ContentType: input.LogoFile.ContentType,
|
|
}
|
|
}
|
|
|
|
reference, err := r.probo.TrustCenterReferences.Update(ctx, scope, req)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update trust center reference", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateTrustCenterReferencePayload{
|
|
TrustCenterReference: types.NewTrustCenterReference(reference),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteTrustCenterReference is the resolver for the deleteTrustCenterReference field.
|
|
func (r *mutationResolver) DeleteTrustCenterReference(ctx context.Context, input types.DeleteTrustCenterReferenceInput) (*types.DeleteTrustCenterReferencePayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterReferenceDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.probo.TrustCenterReferences.Delete(ctx, scope, input.ID); err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete trust center reference", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteTrustCenterReferencePayload{
|
|
DeletedTrustCenterReferenceID: input.ID,
|
|
}, nil
|
|
}
|
|
|
|
// CreateComplianceFramework is the resolver for the createComplianceFramework field.
|
|
func (r *mutationResolver) CreateComplianceFramework(ctx context.Context, input types.CreateComplianceFrameworkInput) (*types.CreateComplianceFrameworkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionComplianceFrameworkCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cf, err := r.probo.ComplianceFrameworks.Create(
|
|
ctx, scope,
|
|
&probo.CreateComplianceFrameworkRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
FrameworkID: input.FrameworkID,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create compliance framework", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateComplianceFrameworkPayload{
|
|
ComplianceFrameworkEdge: types.NewComplianceFrameworkEdge(cf, coredata.ComplianceFrameworkOrderFieldRank),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateComplianceFramework is the resolver for the updateComplianceFramework field.
|
|
func (r *mutationResolver) UpdateComplianceFramework(ctx context.Context, input types.UpdateComplianceFrameworkInput) (*types.UpdateComplianceFrameworkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionComplianceFrameworkUpdateRank)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cf, err := r.probo.ComplianceFrameworks.Update(ctx, scope, &probo.UpdateComplianceFrameworkRequest{
|
|
ID: input.ID,
|
|
Rank: input.Rank,
|
|
})
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update compliance framework", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateComplianceFrameworkPayload{
|
|
ComplianceFramework: types.NewComplianceFramework(cf),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteComplianceFramework is the resolver for the deleteComplianceFramework field.
|
|
func (r *mutationResolver) DeleteComplianceFramework(ctx context.Context, input types.DeleteComplianceFrameworkInput) (*types.DeleteComplianceFrameworkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionComplianceFrameworkDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.probo.ComplianceFrameworks.Delete(
|
|
ctx, scope,
|
|
&probo.DeleteComplianceFrameworkRequest{
|
|
ID: input.ID,
|
|
},
|
|
); err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot delete compliance framework", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteComplianceFrameworkPayload{
|
|
DeletedComplianceFrameworkID: input.ID,
|
|
}, nil
|
|
}
|
|
|
|
// CreateComplianceExternalURL is the resolver for the createComplianceExternalURL field.
|
|
func (r *mutationResolver) CreateComplianceExternalURL(ctx context.Context, input types.CreateComplianceExternalURLInput) (*types.CreateComplianceExternalURLPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, probo.ActionComplianceExternalURLCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
item, err := r.probo.ComplianceExternalURLs.Create(
|
|
ctx, scope,
|
|
&probo.CreateComplianceExternalURLRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
Name: input.Name,
|
|
URL: input.URL,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create compliance external URL", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateComplianceExternalURLPayload{
|
|
ComplianceExternalURLEdge: types.NewComplianceExternalURLEdge(item, coredata.ComplianceExternalURLOrderFieldRank),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateComplianceExternalURL is the resolver for the updateComplianceExternalURL field.
|
|
func (r *mutationResolver) UpdateComplianceExternalURL(ctx context.Context, input types.UpdateComplianceExternalURLInput) (*types.UpdateComplianceExternalURLPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionComplianceExternalURLUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
item, err := r.probo.ComplianceExternalURLs.Update(ctx, scope, &probo.UpdateComplianceExternalURLRequest{
|
|
ID: input.ID,
|
|
Name: input.Name,
|
|
URL: input.URL,
|
|
Rank: input.Rank,
|
|
})
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update compliance external URL", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateComplianceExternalURLPayload{
|
|
ComplianceExternalURL: types.NewComplianceExternalURL(item),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteComplianceExternalURL is the resolver for the deleteComplianceExternalURL field.
|
|
func (r *mutationResolver) DeleteComplianceExternalURL(ctx context.Context, input types.DeleteComplianceExternalURLInput) (*types.DeleteComplianceExternalURLPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionComplianceExternalURLDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.probo.ComplianceExternalURLs.Delete(ctx, scope, &probo.DeleteComplianceExternalURLRequest{ID: input.ID}); err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot delete compliance external URL", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteComplianceExternalURLPayload{
|
|
DeletedComplianceExternalURLID: input.ID,
|
|
}, nil
|
|
}
|
|
|
|
// CreateTrustCenterFile is the resolver for the createTrustCenterFile field.
|
|
func (r *mutationResolver) CreateTrustCenterFile(ctx context.Context, input types.CreateTrustCenterFileInput) (*types.CreateTrustCenterFilePayload, error) {
|
|
scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionTrustCenterFileCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.probo.TrustCenterFiles.Create(
|
|
ctx, scope,
|
|
&probo.CreateTrustCenterFileRequest{
|
|
OrganizationID: input.OrganizationID,
|
|
Name: input.Name,
|
|
Category: input.Category,
|
|
File: probo.File{
|
|
Content: input.File.File,
|
|
Filename: input.File.Filename,
|
|
Size: input.File.Size,
|
|
ContentType: input.File.ContentType,
|
|
},
|
|
TrustCenterVisibility: input.TrustCenterVisibility,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create trust center file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateTrustCenterFilePayload{
|
|
TrustCenterFileEdge: types.NewTrustCenterFileEdge(file, coredata.TrustCenterFileOrderFieldCreatedAt),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterFile is the resolver for the updateTrustCenterFile field.
|
|
func (r *mutationResolver) UpdateTrustCenterFile(ctx context.Context, input types.UpdateTrustCenterFileInput) (*types.UpdateTrustCenterFilePayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.probo.TrustCenterFiles.Update(
|
|
ctx, scope,
|
|
&probo.UpdateTrustCenterFileRequest{
|
|
ID: input.ID,
|
|
Name: input.Name,
|
|
Category: input.Category,
|
|
TrustCenterVisibility: input.TrustCenterVisibility,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot update trust center file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateTrustCenterFilePayload{
|
|
TrustCenterFile: types.NewTrustCenterFile(file),
|
|
}, nil
|
|
}
|
|
|
|
// GetTrustCenterFile is the resolver for the getTrustCenterFile field.
|
|
func (r *mutationResolver) GetTrustCenterFile(ctx context.Context, input types.GetTrustCenterFileInput) (*types.GetTrustCenterFilePayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.probo.TrustCenterFiles.Get(ctx, scope, input.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get trust center file", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.GetTrustCenterFilePayload{
|
|
TrustCenterFile: types.NewTrustCenterFile(file),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteTrustCenterFile is the resolver for the deleteTrustCenterFile field.
|
|
func (r *mutationResolver) DeleteTrustCenterFile(ctx context.Context, input types.DeleteTrustCenterFileInput) (*types.DeleteTrustCenterFilePayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.probo.TrustCenterFiles.Delete(ctx, scope, input.ID); err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete trust center file", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteTrustCenterFilePayload{
|
|
DeletedTrustCenterFileID: input.ID,
|
|
}, nil
|
|
}
|
|
|
|
// CreateCustomDomain is the resolver for the createCustomDomain field.
|
|
func (r *mutationResolver) CreateCustomDomain(ctx context.Context, input types.CreateCustomDomainInput) (*types.CreateCustomDomainPayload, error) {
|
|
scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionCustomDomainCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
domain, err := r.probo.CustomDomains.CreateCustomDomain(
|
|
ctx, scope,
|
|
probo.CreateCustomDomainRequest{
|
|
OrganizationID: input.OrganizationID,
|
|
Domain: input.Domain,
|
|
},
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create custom domain", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateCustomDomainPayload{
|
|
CustomDomain: types.NewCustomDomain(domain, r.customDomainCname),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteCustomDomain is the resolver for the deleteCustomDomain field.
|
|
func (r *mutationResolver) DeleteCustomDomain(ctx context.Context, input types.DeleteCustomDomainInput) (*types.DeleteCustomDomainPayload, error) {
|
|
scope, err := r.authorize(ctx, input.OrganizationID, probo.ActionCustomDomainDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// TODO Drop this wierd logic
|
|
// Get the current custom domain ID before deleting
|
|
domain, err := r.probo.CustomDomains.GetOrganizationCustomDomain(ctx, scope, input.OrganizationID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get custom domain", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if domain == nil {
|
|
return nil, fmt.Errorf("organization has no custom domain")
|
|
}
|
|
|
|
deletedDomainID := domain.ID
|
|
|
|
if err := r.probo.CustomDomains.DeleteCustomDomain(ctx, scope, input.OrganizationID); err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot delete custom domain", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteCustomDomainPayload{
|
|
DeletedCustomDomainID: deletedDomainID,
|
|
}, nil
|
|
}
|
|
|
|
// Logo is the resolver for the logo field.
|
|
func (r *trustCenterResolver) Logo(ctx context.Context, obj *types.TrustCenter) (*types.File, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.Logo == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.Logo.ID)
|
|
}
|
|
|
|
// DarkLogo is the resolver for the darkLogo field.
|
|
func (r *trustCenterResolver) DarkLogo(ctx context.Context, obj *types.TrustCenter) (*types.File, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.DarkLogo == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.DarkLogo.ID)
|
|
}
|
|
|
|
// Nda is the resolver for the nda field.
|
|
func (r *trustCenterResolver) Nda(ctx context.Context, obj *types.TrustCenter) (*types.File, error) {
|
|
hasPermission, err := r.Resolver.Permission(ctx, obj, probo.ActionTrustCenterGetNda)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot authorize", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if !hasPermission || obj.Nda == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.Nda.ID)
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *trustCenterResolver) Organization(ctx context.Context, obj *types.TrustCenter) (*types.Organization, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, err := r.probo.TrustCenters.Get(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
organization, err := r.probo.Organizations.Get(ctx, scope, trustCenter.OrganizationID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get organization", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewOrganization(organization), nil
|
|
}
|
|
|
|
// Accesses is the resolver for the accesses field.
|
|
func (r *trustCenterResolver) Accesses(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.TrustCenterAccessOrderField]) (*types.TrustCenterAccessConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.TrustCenterAccessOrderField]{
|
|
Field: coredata.TrustCenterAccessOrderFieldCreatedAt,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.TrustCenterAccessOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.probo.TrustCenterAccesses.ListForTrustCenterID(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list trust center accesses", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewTrustCenterAccessConnection(result), nil
|
|
}
|
|
|
|
// References is the resolver for the references field.
|
|
func (r *trustCenterResolver) References(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.TrustCenterReferenceOrderField]) (*types.TrustCenterReferenceConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterReferenceList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.TrustCenterReferenceOrderField]{
|
|
Field: coredata.TrustCenterReferenceOrderFieldRank,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.TrustCenterReferenceOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.probo.TrustCenterReferences.ListForTrustCenterID(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list trust center references", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewTrustCenterReferenceConnection(result, obj.ID), nil
|
|
}
|
|
|
|
// ComplianceFrameworks is the resolver for the complianceFrameworks field.
|
|
func (r *trustCenterResolver) ComplianceFrameworks(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.ComplianceFrameworkOrderField]) (*types.ComplianceFrameworkConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionComplianceFrameworkList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.ComplianceFrameworkOrderField]{
|
|
Field: coredata.ComplianceFrameworkOrderFieldRank,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.ComplianceFrameworkOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.probo.ComplianceFrameworks.ListWithHiddenForTrustCenterID(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list compliance frameworks", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewComplianceFrameworkConnection(result), nil
|
|
}
|
|
|
|
// ExternalUrls is the resolver for the externalUrls field.
|
|
func (r *trustCenterResolver) ExternalUrls(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.ComplianceExternalURLOrderField]) (*types.ComplianceExternalURLConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionComplianceExternalURLList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.ComplianceExternalURLOrderField]{
|
|
Field: coredata.ComplianceExternalURLOrderFieldRank,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.ComplianceExternalURLOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.probo.ComplianceExternalURLs.List(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list compliance external URLs", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewComplianceExternalURLConnection(result), nil
|
|
}
|
|
|
|
// MailingList is the resolver for the mailingList field.
|
|
func (r *trustCenterResolver) MailingList(ctx context.Context, obj *types.TrustCenter) (*types.MailingList, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionMailingListSubscriberList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.MailingList != nil {
|
|
return obj.MailingList, nil
|
|
}
|
|
|
|
ml, err := r.probo.TrustCenters.GetMailingList(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get mailing list for trust center", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if ml == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return types.NewMailingList(ml), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *trustCenterResolver) Permission(ctx context.Context, obj *types.TrustCenter, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// NdaSignature is the resolver for the ndaSignature field.
|
|
func (r *trustCenterAccessResolver) NdaSignature(ctx context.Context, obj *types.TrustCenterAccess) (*types.ElectronicSignature, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
access, err := r.probo.TrustCenterAccesses.Get(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot load trust center access: %w", err)
|
|
}
|
|
|
|
if access.ElectronicSignatureID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
sig, err := r.esign.GetSignatureByID(ctx, *access.ElectronicSignatureID)
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return types.NewElectronicSignature(sig), nil
|
|
}
|
|
|
|
// PendingRequestCount is the resolver for the pendingRequestCount field.
|
|
func (r *trustCenterAccessResolver) PendingRequestCount(ctx context.Context, obj *types.TrustCenterAccess) (int, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.probo.TrustCenterAccesses.CountPendingRequestDocumentAccesses(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count pending request document accesses", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// ActiveCount is the resolver for the activeCount field.
|
|
func (r *trustCenterAccessResolver) ActiveCount(ctx context.Context, obj *types.TrustCenterAccess) (int, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.probo.TrustCenterAccesses.CountActiveDocumentAccesses(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count active document accesses", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// Profile is the resolver for the profile field.
|
|
func (r *trustCenterAccessResolver) Profile(ctx context.Context, obj *types.TrustCenterAccess) (*types.Profile, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, iam.ActionMembershipProfileGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
profile, err := r.iam.OrganizationService.GetProfileForIdentityAndOrganization(ctx, obj.IdentityID, obj.OrganizationID)
|
|
if err != nil {
|
|
if _, ok := errors.AsType[*iam.ErrProfileNotFound](err); ok {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get profile", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewProfile(profile), nil
|
|
}
|
|
|
|
// AvailableDocumentAccesses is the resolver for the availableDocumentAccesses field.
|
|
func (r *trustCenterAccessResolver) AvailableDocumentAccesses(ctx context.Context, obj *types.TrustCenterAccess, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.TrustCenterDocumentAccessOrderField]) (*types.TrustCenterDocumentAccessConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.TrustCenterDocumentAccessOrderField]{
|
|
Field: coredata.TrustCenterDocumentAccessOrderFieldCreatedAt,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.TrustCenterDocumentAccessOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.probo.TrustCenterAccesses.ListAvailableDocumentAccesses(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list trust center document accesses", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewTrustCenterDocumentAccessConnection(result, obj, obj.ID), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *trustCenterAccessResolver) Permission(ctx context.Context, obj *types.TrustCenterAccess, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// Document is the resolver for the document field.
|
|
func (r *trustCenterDocumentAccessResolver) Document(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.Document, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionDocumentGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.DocumentID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
document, err := r.probo.Documents.Get(ctx, scope, *obj.DocumentID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot load document", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewDocument(document), nil
|
|
}
|
|
|
|
// ReportFile is the resolver for the reportFile field.
|
|
func (r *trustCenterDocumentAccessResolver) ReportFile(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.File, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, probo.ActionFileGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.ReportFile == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
loaders := dataloader.FromContext(ctx)
|
|
|
|
file, err := loaders.File.Load(ctx, obj.ReportFile.ID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) || errors.Is(err, dataloadgen.ErrNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot load report file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewFile(file, r.fileManager), nil
|
|
}
|
|
|
|
// Audit is the resolver for the audit field.
|
|
func (r *trustCenterDocumentAccessResolver) Audit(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.Audit, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionAuditGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.ReportFileID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
audit, err := r.probo.Audits.GetByReportFileID(ctx, scope, *obj.ReportFileID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, nil
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot load audit for report file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewAudit(audit), nil
|
|
}
|
|
|
|
// TrustCenterFile is the resolver for the trustCenterFile field.
|
|
func (r *trustCenterDocumentAccessResolver) TrustCenterFile(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.TrustCenterFile, error) {
|
|
scope, err := r.authorize(ctx, obj.TrustCenterAccessID, probo.ActionTrustCenterFileGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.TrustCenterFileID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
trustCenterFile, err := r.probo.TrustCenterFiles.Get(ctx, scope, *obj.TrustCenterFileID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot load trust center file", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewTrustCenterFile(trustCenterFile), nil
|
|
}
|
|
|
|
// TotalCount is the resolver for the totalCount field.
|
|
func (r *trustCenterDocumentAccessConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterDocumentAccessConnection) (int, error) {
|
|
scope, err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterDocumentAccessList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.probo.TrustCenterAccesses.CountDocumentAccesses(ctx, scope, obj.ParentID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count trust center document accesses", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// File is the resolver for the file field.
|
|
func (r *trustCenterFileResolver) File(ctx context.Context, obj *types.TrustCenterFile) (*types.File, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterFileGetFileUrl); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.File.ID)
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *trustCenterFileResolver) Organization(ctx context.Context, obj *types.TrustCenterFile) (*types.Organization, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenterFile, err := r.probo.TrustCenterFiles.Get(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get trust center file", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
organization, err := r.probo.Organizations.Get(ctx, scope, trustCenterFile.OrganizationID)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFound(ctx, err)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get organization", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewOrganization(organization), nil
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *trustCenterFileResolver) Permission(ctx context.Context, obj *types.TrustCenterFile, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// TotalCount is the resolver for the totalCount field.
|
|
func (r *trustCenterFileConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterFileConnection) (int, error) {
|
|
scope, err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterFileList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.probo.TrustCenterFiles.CountForOrganizationID(ctx, scope, obj.ParentID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count trust center files", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// Logo is the resolver for the logo field.
|
|
func (r *trustCenterReferenceResolver) Logo(ctx context.Context, obj *types.TrustCenterReference) (*types.File, error) {
|
|
if _, err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterReferenceGetLogoUrl); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.Logo.ID)
|
|
}
|
|
|
|
// Permission is the resolver for the permission field.
|
|
func (r *trustCenterReferenceResolver) Permission(ctx context.Context, obj *types.TrustCenterReference, action string) (bool, error) {
|
|
return r.Resolver.Permission(ctx, obj, action)
|
|
}
|
|
|
|
// TotalCount is the resolver for the totalCount field.
|
|
func (r *trustCenterReferenceConnectionResolver) TotalCount(ctx context.Context, obj *types.TrustCenterReferenceConnection) (int, error) {
|
|
scope, err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterReferenceList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.probo.TrustCenterReferences.CountForTrustCenterID(ctx, scope, obj.ParentID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot count trust center references", log.Error(err))
|
|
return 0, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return count, nil
|
|
}
|
|
|
|
// ComplianceExternalURL returns schema.ComplianceExternalURLResolver implementation.
|
|
func (r *Resolver) ComplianceExternalURL() schema.ComplianceExternalURLResolver {
|
|
return &complianceExternalURLResolver{r}
|
|
}
|
|
|
|
// ComplianceFramework returns schema.ComplianceFrameworkResolver implementation.
|
|
func (r *Resolver) ComplianceFramework() schema.ComplianceFrameworkResolver {
|
|
return &complianceFrameworkResolver{r}
|
|
}
|
|
|
|
// CustomDomain returns schema.CustomDomainResolver implementation.
|
|
func (r *Resolver) CustomDomain() schema.CustomDomainResolver { return &customDomainResolver{r} }
|
|
|
|
// TrustCenter returns schema.TrustCenterResolver implementation.
|
|
func (r *Resolver) TrustCenter() schema.TrustCenterResolver { return &trustCenterResolver{r} }
|
|
|
|
// TrustCenterAccess returns schema.TrustCenterAccessResolver implementation.
|
|
func (r *Resolver) TrustCenterAccess() schema.TrustCenterAccessResolver {
|
|
return &trustCenterAccessResolver{r}
|
|
}
|
|
|
|
// TrustCenterDocumentAccess returns schema.TrustCenterDocumentAccessResolver implementation.
|
|
func (r *Resolver) TrustCenterDocumentAccess() schema.TrustCenterDocumentAccessResolver {
|
|
return &trustCenterDocumentAccessResolver{r}
|
|
}
|
|
|
|
// TrustCenterDocumentAccessConnection returns schema.TrustCenterDocumentAccessConnectionResolver implementation.
|
|
func (r *Resolver) TrustCenterDocumentAccessConnection() schema.TrustCenterDocumentAccessConnectionResolver {
|
|
return &trustCenterDocumentAccessConnectionResolver{r}
|
|
}
|
|
|
|
// TrustCenterFile returns schema.TrustCenterFileResolver implementation.
|
|
func (r *Resolver) TrustCenterFile() schema.TrustCenterFileResolver {
|
|
return &trustCenterFileResolver{r}
|
|
}
|
|
|
|
// TrustCenterFileConnection returns schema.TrustCenterFileConnectionResolver implementation.
|
|
func (r *Resolver) TrustCenterFileConnection() schema.TrustCenterFileConnectionResolver {
|
|
return &trustCenterFileConnectionResolver{r}
|
|
}
|
|
|
|
// TrustCenterReference returns schema.TrustCenterReferenceResolver implementation.
|
|
func (r *Resolver) TrustCenterReference() schema.TrustCenterReferenceResolver {
|
|
return &trustCenterReferenceResolver{r}
|
|
}
|
|
|
|
// TrustCenterReferenceConnection returns schema.TrustCenterReferenceConnectionResolver implementation.
|
|
func (r *Resolver) TrustCenterReferenceConnection() schema.TrustCenterReferenceConnectionResolver {
|
|
return &trustCenterReferenceConnectionResolver{r}
|
|
}
|
|
|
|
type complianceExternalURLResolver struct{ *Resolver }
|
|
type complianceFrameworkResolver struct{ *Resolver }
|
|
type customDomainResolver struct{ *Resolver }
|
|
type trustCenterResolver struct{ *Resolver }
|
|
type trustCenterAccessResolver struct{ *Resolver }
|
|
type trustCenterDocumentAccessResolver struct{ *Resolver }
|
|
type trustCenterDocumentAccessConnectionResolver struct{ *Resolver }
|
|
type trustCenterFileResolver struct{ *Resolver }
|
|
type trustCenterFileConnectionResolver struct{ *Resolver }
|
|
type trustCenterReferenceResolver struct{ *Resolver }
|
|
type trustCenterReferenceConnectionResolver struct{ *Resolver }
|