Rewire the console and visitor resolvers onto the management and visitor services with compliance-portal authorization. Rename the GraphQL and MCP ComplianceExternalURL type to ComplianceCustomLink, expose trust center profile fields, default and custom domains, public URL, and the managed flag, and drop the profile fields from the organization surface. Signed-off-by: Bryan Frimin <bryan@probo.com>
1353 lines
46 KiB
Go
1353 lines
46 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.93
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/vikstrous/dataloadgen"
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/complianceportal"
|
|
"go.probo.inc/probo/pkg/complianceportal/management"
|
|
"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/resourcealias"
|
|
"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 *complianceCustomLinkResolver) Permission(ctx context.Context, obj *types.ComplianceCustomLink, 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, complianceportal.ActionCompliancePortalUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.management.Update(
|
|
ctx, scope,
|
|
&management.UpdateRequest{
|
|
ID: input.TrustCenterID,
|
|
Active: input.Active,
|
|
SearchEngineIndexing: input.SearchEngineIndexing,
|
|
Description: gqlutils.UnwrapOmittable(input.Description),
|
|
WebsiteURL: gqlutils.UnwrapOmittable(input.WebsiteURL),
|
|
Email: gqlutils.UnwrapOmittable(input.Email),
|
|
HeadquarterAddress: gqlutils.UnwrapOmittable(input.HeadquarterAddress),
|
|
},
|
|
)
|
|
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, complianceportal.ActionCompliancePortalNonDisclosureAgreementUpload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.management.UploadNDA(
|
|
ctx, scope,
|
|
&management.UploadNDARequest{
|
|
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, complianceportal.ActionCompliancePortalNonDisclosureAgreementDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
trustCenter, _, err := r.management.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, complianceportal.ActionCompliancePortalUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req := &management.UpdateBrandRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
}
|
|
|
|
if input.LogoFile.IsSet() {
|
|
logoFile := input.LogoFile.Value()
|
|
if logoFile == nil {
|
|
var nilFile *management.FileUpload
|
|
|
|
req.LogoFile = &nilFile
|
|
} else {
|
|
fileUpload := &management.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 *management.FileUpload
|
|
|
|
req.DarkLogoFile = &nilFile
|
|
} else {
|
|
fileUpload := &management.FileUpload{
|
|
Content: darkLogoFile.File,
|
|
Filename: darkLogoFile.Filename,
|
|
Size: darkLogoFile.Size,
|
|
ContentType: darkLogoFile.ContentType,
|
|
}
|
|
req.DarkLogoFile = &fileUpload
|
|
}
|
|
}
|
|
|
|
trustCenter, _, err := r.management.UpdateBrand(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, complianceportal.ActionCompliancePortalAccessUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var (
|
|
documentAccesses []management.UpdateDocumentAccessRequest
|
|
reportAccesses []management.UpdateDocumentAccessRequest
|
|
fileAccesses []management.UpdateDocumentAccessRequest
|
|
)
|
|
|
|
for _, documentAccess := range input.Documents {
|
|
documentAccesses = append(documentAccesses, management.UpdateDocumentAccessRequest{
|
|
ID: documentAccess.ID,
|
|
Status: documentAccess.Status,
|
|
})
|
|
}
|
|
|
|
for _, reportAccess := range input.Reports {
|
|
reportAccesses = append(reportAccesses, management.UpdateDocumentAccessRequest{
|
|
ID: reportAccess.ID,
|
|
Status: reportAccess.Status,
|
|
})
|
|
}
|
|
|
|
for _, fileAccess := range input.TrustCenterFiles {
|
|
fileAccesses = append(fileAccesses, management.UpdateDocumentAccessRequest{
|
|
ID: fileAccess.ID,
|
|
Status: fileAccess.Status,
|
|
})
|
|
}
|
|
|
|
access, err := r.management.UpdateAccess(
|
|
ctx, scope,
|
|
&management.UpdateAccessRequest{
|
|
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, complianceportal.ActionCompliancePortalAccessDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.DeleteAccess(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, complianceportal.ActionCompliancePortalReferenceCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reference, err := r.management.CreateReference(
|
|
ctx, scope,
|
|
&management.CreateReferenceRequest{
|
|
TrustCenterID: input.TrustCenterID,
|
|
Name: input.Name,
|
|
Description: input.Description,
|
|
WebsiteURL: input.WebsiteURL,
|
|
LogoFile: management.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, complianceportal.ActionCompliancePortalReferenceUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req := &management.UpdateReferenceRequest{
|
|
ID: input.ID,
|
|
Name: input.Name,
|
|
Description: gqlutils.UnwrapOmittable(input.Description),
|
|
WebsiteURL: input.WebsiteURL,
|
|
Rank: input.Rank,
|
|
}
|
|
|
|
if input.LogoFile != nil {
|
|
req.LogoFile = &management.File{
|
|
Content: input.LogoFile.File,
|
|
Filename: input.LogoFile.Filename,
|
|
Size: input.LogoFile.Size,
|
|
ContentType: input.LogoFile.ContentType,
|
|
}
|
|
}
|
|
|
|
reference, err := r.management.UpdateReference(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, complianceportal.ActionCompliancePortalReferenceDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.DeleteReference(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, complianceportal.ActionComplianceFrameworkCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cf, err := r.management.CreateFramework(
|
|
ctx, scope,
|
|
&management.CreateFrameworkRequest{
|
|
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, complianceportal.ActionComplianceFrameworkUpdateRank)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cf, err := r.management.UpdateFramework(ctx, scope, &management.UpdateFrameworkRequest{
|
|
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, complianceportal.ActionComplianceFrameworkDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.DeleteFramework(
|
|
ctx, scope,
|
|
&management.DeleteFrameworkRequest{
|
|
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
|
|
}
|
|
|
|
// CreateComplianceCustomLink is the resolver for the createComplianceCustomLink field.
|
|
func (r *mutationResolver) CreateComplianceCustomLink(ctx context.Context, input types.CreateComplianceCustomLinkInput) (*types.CreateComplianceCustomLinkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.TrustCenterID, complianceportal.ActionComplianceCustomLinkCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
item, err := r.management.CreateCustomLink(
|
|
ctx, scope,
|
|
&management.CreateCustomLinkRequest{
|
|
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 custom link", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.CreateComplianceCustomLinkPayload{
|
|
ComplianceCustomLinkEdge: types.NewComplianceCustomLinkEdge(item, coredata.ComplianceCustomLinkOrderFieldRank),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateComplianceCustomLink is the resolver for the updateComplianceCustomLink field.
|
|
func (r *mutationResolver) UpdateComplianceCustomLink(ctx context.Context, input types.UpdateComplianceCustomLinkInput) (*types.UpdateComplianceCustomLinkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, complianceportal.ActionComplianceCustomLinkUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
item, err := r.management.UpdateCustomLink(ctx, scope, &management.UpdateCustomLinkRequest{
|
|
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 custom link", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.UpdateComplianceCustomLinkPayload{
|
|
ComplianceCustomLink: types.NewComplianceCustomLink(item),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteComplianceCustomLink is the resolver for the deleteComplianceCustomLink field.
|
|
func (r *mutationResolver) DeleteComplianceCustomLink(ctx context.Context, input types.DeleteComplianceCustomLinkInput) (*types.DeleteComplianceCustomLinkPayload, error) {
|
|
scope, err := r.authorize(ctx, input.ID, complianceportal.ActionComplianceCustomLinkDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.DeleteCustomLink(ctx, scope, &management.DeleteCustomLinkRequest{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 custom link", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteComplianceCustomLinkPayload{
|
|
DeletedComplianceCustomLinkID: 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, complianceportal.ActionCompliancePortalFileCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.management.CreateFile(
|
|
ctx, scope,
|
|
&management.CreateFileRequest{
|
|
OrganizationID: input.OrganizationID,
|
|
Name: input.Name,
|
|
Category: input.Category,
|
|
File: management.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, complianceportal.ActionCompliancePortalFileUpdate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.management.UpdateFile(
|
|
ctx, scope,
|
|
&management.UpdateFileRequest{
|
|
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, complianceportal.ActionCompliancePortalFileGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
file, err := r.management.GetFile(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, complianceportal.ActionCompliancePortalFileDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.DeleteFile(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.TrustCenterID, complianceportal.ActionCustomDomainCreate)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
domain, err := r.management.AddCustomDomain(
|
|
ctx, scope,
|
|
input.TrustCenterID,
|
|
input.Domain,
|
|
)
|
|
if err != nil {
|
|
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
|
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
|
}
|
|
|
|
if errors.Is(err, management.ErrCustomDomainSlotTaken) {
|
|
return nil, gqlutils.Conflictf(ctx, "compliance page already has a custom domain")
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot create custom domain", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
customDomain, err := r.newCustomDomainType(ctx, scope, domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.CreateCustomDomainPayload{
|
|
CustomDomain: customDomain,
|
|
}, 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.CustomDomainID, complianceportal.ActionCustomDomainDelete)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := r.management.RemoveCustomDomain(ctx, scope, input.CustomDomainID); err != nil {
|
|
if errors.Is(err, complianceportal.ErrCustomDomainManaged) {
|
|
return nil, gqlutils.Conflictf(ctx, "managed domain cannot be deleted")
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot delete custom domain", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return &types.DeleteCustomDomainPayload{
|
|
DeletedCustomDomainID: input.CustomDomainID,
|
|
}, 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, complianceportal.ActionCompliancePortalGet); 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, complianceportal.ActionCompliancePortalGet); 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, complianceportal.ActionCompliancePortalGetNda)
|
|
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.management.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, complianceportal.ActionCompliancePortalAccessList)
|
|
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.management.ListAccesses(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, complianceportal.ActionCompliancePortalReferenceList)
|
|
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.management.ListReferences(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, complianceportal.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.management.ListFrameworksWithHidden(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
|
|
}
|
|
|
|
// CustomLinks is the resolver for the customLinks field.
|
|
func (r *trustCenterResolver) CustomLinks(ctx context.Context, obj *types.TrustCenter, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.OrderBy[coredata.ComplianceCustomLinkOrderField]) (*types.ComplianceCustomLinkConnection, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, complianceportal.ActionComplianceCustomLinkList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pageOrderBy := page.OrderBy[coredata.ComplianceCustomLinkOrderField]{
|
|
Field: coredata.ComplianceCustomLinkOrderFieldRank,
|
|
Direction: page.OrderDirectionAsc,
|
|
}
|
|
|
|
if orderBy != nil {
|
|
pageOrderBy = page.OrderBy[coredata.ComplianceCustomLinkOrderField]{
|
|
Field: orderBy.Field,
|
|
Direction: orderBy.Direction,
|
|
}
|
|
}
|
|
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
result, err := r.management.ListCustomLinks(ctx, scope, obj.ID, cursor)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list compliance custom links", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewComplianceCustomLinkConnection(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, complianceportal.ActionMailingListSubscriberList)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.MailingList != nil {
|
|
return obj.MailingList, nil
|
|
}
|
|
|
|
ml, err := r.management.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
|
|
}
|
|
|
|
// DefaultDomain is the resolver for the defaultDomain field.
|
|
func (r *trustCenterResolver) DefaultDomain(ctx context.Context, obj *types.TrustCenter) (*types.CustomDomain, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, complianceportal.ActionCustomDomainGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
domain, err := r.management.GetDefaultDomain(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot load default domain", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if domain == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return r.newCustomDomainType(ctx, scope, domain)
|
|
}
|
|
|
|
// CustomDomain is the resolver for the customDomain field.
|
|
func (r *trustCenterResolver) CustomDomain(ctx context.Context, obj *types.TrustCenter) (*types.CustomDomain, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, complianceportal.ActionCustomDomainGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
domain, err := r.management.GetCustomDomain(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot load custom domain", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
if domain == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return r.newCustomDomainType(ctx, scope, domain)
|
|
}
|
|
|
|
// PublicURL is the resolver for the publicUrl field.
|
|
func (r *trustCenterResolver) PublicURL(ctx context.Context, obj *types.TrustCenter) (string, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, complianceportal.ActionCompliancePortalGet)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
publicURL, err := r.management.PublicURL(ctx, scope, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot resolve trust center public url", log.Error(err))
|
|
return "", gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return publicURL, 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, complianceportal.ActionCompliancePortalAccessGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
access, err := r.management.GetAccess(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, scope, *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, complianceportal.ActionCompliancePortalAccessGet)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.management.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, complianceportal.ActionCompliancePortalAccessGet)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.management.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, complianceportal.ActionCompliancePortalAccessGet)
|
|
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.management.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 obj.ReportFile == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
if _, err := r.authorize(ctx, obj.ReportFile.ID, probo.ActionFileGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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, complianceportal.ActionCompliancePortalFileGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.TrustCenterFileID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
trustCenterFile, err := r.management.GetFile(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, complianceportal.ActionCompliancePortalDocumentAccessList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.management.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, complianceportal.ActionCompliancePortalFileGetFileUrl); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.loadFile(ctx, obj.File.ID)
|
|
}
|
|
|
|
// Alias is the resolver for the alias field.
|
|
func (r *trustCenterFileResolver) Alias(ctx context.Context, obj *types.TrustCenterFile) (*string, error) {
|
|
scope, err := r.authorize(ctx, obj.ID, resourcealias.ActionAliasGet)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return r.resourceAlias.GetByResourceID(ctx, scope, obj.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.management.GetFile(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, complianceportal.ActionCompliancePortalFileList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.management.CountFilesForOrganizationID(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, complianceportal.ActionCompliancePortalReferenceGetLogoUrl); 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, complianceportal.ActionCompliancePortalReferenceList)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
count, err := r.management.CountReferences(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
|
|
}
|
|
|
|
// ComplianceCustomLink returns schema.ComplianceCustomLinkResolver implementation.
|
|
func (r *Resolver) ComplianceCustomLink() schema.ComplianceCustomLinkResolver {
|
|
return &complianceCustomLinkResolver{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 (
|
|
complianceCustomLinkResolver struct{ *Resolver }
|
|
complianceFrameworkResolver struct{ *Resolver }
|
|
customDomainResolver struct{ *Resolver }
|
|
trustCenterResolver struct{ *Resolver }
|
|
trustCenterAccessResolver struct{ *Resolver }
|
|
trustCenterDocumentAccessResolver struct{ *Resolver }
|
|
trustCenterDocumentAccessConnectionResolver struct{ *Resolver }
|
|
trustCenterFileResolver struct{ *Resolver }
|
|
trustCenterFileConnectionResolver struct{ *Resolver }
|
|
trustCenterReferenceResolver struct{ *Resolver }
|
|
trustCenterReferenceConnectionResolver struct{ *Resolver }
|
|
)
|