Change gqlgen filename_template from {name}.resolvers.go to
{name}_resolvers.go across all three APIs for consistent Go naming.
Signed-off-by: Émile Ré <emile@getprobo.com>
1274 lines
45 KiB
Go
1274 lines
45 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.87
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"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) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
trustCenter, file, err := prb.TrustCenters.Update(
|
|
ctx,
|
|
&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, file),
|
|
}, nil
|
|
}
|
|
|
|
// UploadTrustCenterNda is the resolver for the uploadTrustCenterNDA field.
|
|
func (r *mutationResolver) UploadTrustCenterNda(ctx context.Context, input types.UploadTrustCenterNDAInput) (*types.UploadTrustCenterNDAPayload, error) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterNonDisclosureAgreementUpload); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
trustCenter, file, err := prb.TrustCenters.UploadNDA(
|
|
ctx,
|
|
&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, file),
|
|
}, nil
|
|
}
|
|
|
|
// DeleteTrustCenterNda is the resolver for the deleteTrustCenterNDA field.
|
|
func (r *mutationResolver) DeleteTrustCenterNda(ctx context.Context, input types.DeleteTrustCenterNDAInput) (*types.DeleteTrustCenterNDAPayload, error) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterNonDisclosureAgreementDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
trustCenter, file, err := prb.TrustCenters.DeleteNDA(ctx, 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, file),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterBrand is the resolver for the updateTrustCenterBrand field.
|
|
func (r *mutationResolver) UpdateTrustCenterBrand(ctx context.Context, input types.UpdateTrustCenterBrandInput) (*types.UpdateTrustCenterBrandPayload, error) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
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, file, err := prb.TrustCenters.UpdateTrustCenterBrand(ctx, 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, file),
|
|
}, nil
|
|
}
|
|
|
|
// UpdateTrustCenterAccess is the resolver for the updateTrustCenterAccess field.
|
|
func (r *mutationResolver) UpdateTrustCenterAccess(ctx context.Context, input types.UpdateTrustCenterAccessInput) (*types.UpdateTrustCenterAccessPayload, error) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterAccessUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
var documentAccesses []probo.UpdateTrustCenterDocumentAccessRequest
|
|
var reportAccesses []probo.UpdateTrustCenterDocumentAccessRequest
|
|
var 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 := prb.TrustCenterAccesses.Update(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterAccessDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
err := prb.TrustCenterAccesses.Delete(ctx, input.ID)
|
|
if 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) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionTrustCenterReferenceCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
reference, err := prb.TrustCenterReferences.Create(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterReferenceUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
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 := prb.TrustCenterReferences.Update(ctx, 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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterReferenceDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
err := prb.TrustCenterReferences.Delete(ctx, input.ID)
|
|
if 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) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionComplianceFrameworkCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
cf, err := prb.ComplianceFrameworks.Create(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionComplianceFrameworkUpdateRank); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
cf, err := prb.ComplianceFrameworks.Update(ctx, &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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionComplianceFrameworkDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
err := prb.ComplianceFrameworks.Delete(
|
|
ctx,
|
|
&probo.DeleteComplianceFrameworkRequest{
|
|
ID: input.ID,
|
|
},
|
|
)
|
|
if 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) {
|
|
if err := r.authorize(ctx, input.TrustCenterID, probo.ActionComplianceExternalURLCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.TrustCenterID.TenantID())
|
|
|
|
item, err := prb.ComplianceExternalURLs.Create(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionComplianceExternalURLUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
item, err := prb.ComplianceExternalURLs.Update(ctx, &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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionComplianceExternalURLDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
if err := prb.ComplianceExternalURLs.Delete(ctx, &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) {
|
|
if err := r.authorize(ctx, input.OrganizationID, probo.ActionTrustCenterFileCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
|
|
|
file, err := prb.TrustCenterFiles.Create(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileUpdate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
file, err := prb.TrustCenterFiles.Update(
|
|
ctx,
|
|
&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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
file, err := prb.TrustCenterFiles.Get(ctx, 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) {
|
|
if err := r.authorize(ctx, input.ID, probo.ActionTrustCenterFileDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.ID.TenantID())
|
|
|
|
err := prb.TrustCenterFiles.Delete(ctx, input.ID)
|
|
if 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) {
|
|
if err := r.authorize(ctx, input.OrganizationID, probo.ActionCustomDomainCreate); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
|
|
|
domain, err := prb.CustomDomains.CreateCustomDomain(
|
|
ctx,
|
|
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) {
|
|
if err := r.authorize(ctx, input.OrganizationID, probo.ActionCustomDomainDelete); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, input.OrganizationID.TenantID())
|
|
|
|
// TODO Drop this wierd logic
|
|
// Get the current custom domain ID before deleting
|
|
domain, err := prb.CustomDomains.GetOrganizationCustomDomain(ctx, 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 := prb.CustomDomains.DeleteCustomDomain(ctx, 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
|
|
}
|
|
|
|
// LogoFileURL is the resolver for the logoFileUrl field.
|
|
func (r *trustCenterResolver) LogoFileURL(ctx context.Context, obj *types.TrustCenter) (*string, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
logoURL, err := prb.TrustCenters.GenerateLogoURL(ctx, obj.ID, 1*time.Hour)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot generate logo url", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return logoURL, nil
|
|
}
|
|
|
|
// DarkLogoFileURL is the resolver for the darkLogoFileUrl field.
|
|
func (r *trustCenterResolver) DarkLogoFileURL(ctx context.Context, obj *types.TrustCenter) (*string, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
logoURL, err := prb.TrustCenters.GenerateDarkLogoURL(ctx, obj.ID, 1*time.Hour)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot generate logo url", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return logoURL, nil
|
|
}
|
|
|
|
// NdaFileURL is the resolver for the ndaFileUrl field.
|
|
func (r *trustCenterResolver) NdaFileURL(ctx context.Context, obj *types.TrustCenter) (*string, 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 {
|
|
return nil, nil
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
fileURL, err := prb.TrustCenters.GenerateNDAFileURL(ctx, obj.ID, 15*time.Minute)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot generate NDA file URL", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return fileURL, nil
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *trustCenterResolver) Organization(ctx context.Context, obj *types.TrustCenter) (*types.Organization, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
trustCenter, err := prb.TrustCenters.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
organization, err := prb.Organizations.Get(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
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 := prb.TrustCenterAccesses.ListForTrustCenterID(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterReferenceList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
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 := prb.TrustCenterReferences.ListForTrustCenterID(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionComplianceFrameworkList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
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 := prb.ComplianceFrameworks.ListWithHiddenForTrustCenterID(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionComplianceExternalURLList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
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 := prb.ComplianceExternalURLs.List(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionMailingListSubscriberList); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.MailingList != nil {
|
|
return obj.MailingList, nil
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
ml, err := prb.TrustCenters.GetMailingList(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
access, err := prb.TrustCenterAccesses.Get(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
count, err := prb.TrustCenterAccesses.CountPendingRequestDocumentAccesses(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet); err != nil {
|
|
return 0, err
|
|
}
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
count, err := prb.TrustCenterAccesses.CountActiveDocumentAccesses(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterAccessGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
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 := prb.TrustCenterAccesses.ListAvailableDocumentAccesses(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionDocumentGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.DocumentID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.TrustCenterAccessID.TenantID())
|
|
|
|
document, err := prb.Documents.Get(ctx, *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
|
|
}
|
|
|
|
// Report is the resolver for the report field.
|
|
func (r *trustCenterDocumentAccessResolver) Report(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.Report, error) {
|
|
if err := r.authorize(ctx, obj.TrustCenterAccessID, probo.ActionReportGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.ReportID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.TrustCenterAccessID.TenantID())
|
|
|
|
report, err := prb.Reports.Get(ctx, *obj.ReportID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot load report", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewReport(report), nil
|
|
}
|
|
|
|
// TrustCenterFile is the resolver for the trustCenterFile field.
|
|
func (r *trustCenterDocumentAccessResolver) TrustCenterFile(ctx context.Context, obj *types.TrustCenterDocumentAccess) (*types.TrustCenterFile, error) {
|
|
if err := r.authorize(ctx, obj.TrustCenterAccessID, probo.ActionTrustCenterFileGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if obj.TrustCenterFileID == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.TrustCenterAccessID.TenantID())
|
|
|
|
trustCenterFile, err := prb.TrustCenterFiles.Get(ctx, *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) {
|
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterDocumentAccessList); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
|
|
count, err := prb.TrustCenterAccesses.CountDocumentAccesses(ctx, 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
|
|
}
|
|
|
|
// FileURL is the resolver for the fileUrl field.
|
|
func (r *trustCenterFileResolver) FileURL(ctx context.Context, obj *types.TrustCenterFile) (string, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterFileGetFileUrl); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
fileURL, err := prb.TrustCenterFiles.GenerateFileURL(ctx, obj.ID, 1*time.Hour)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot generate file URL", log.Error(err))
|
|
return "", gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return fileURL, nil
|
|
}
|
|
|
|
// Organization is the resolver for the organization field.
|
|
func (r *trustCenterFileResolver) Organization(ctx context.Context, obj *types.TrustCenterFile) (*types.Organization, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionOrganizationGet); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
trustCenterFile, err := prb.TrustCenterFiles.Get(ctx, obj.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get trust center file", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
organization, err := prb.Organizations.Get(ctx, 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) {
|
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterFileList); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
|
|
count, err := prb.TrustCenterFiles.CountForOrganizationID(ctx, 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
|
|
}
|
|
|
|
// LogoURL is the resolver for the logoUrl field.
|
|
func (r *trustCenterReferenceResolver) LogoURL(ctx context.Context, obj *types.TrustCenterReference) (string, error) {
|
|
if err := r.authorize(ctx, obj.ID, probo.ActionTrustCenterReferenceGetLogoUrl); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ID.TenantID())
|
|
|
|
fileURL, err := prb.TrustCenterReferences.GenerateLogoURL(ctx, obj.ID, 1*time.Hour)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot generate logo URL", log.Error(err))
|
|
return "", gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return fileURL, nil
|
|
}
|
|
|
|
// 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) {
|
|
if err := r.authorize(ctx, obj.ParentID, probo.ActionTrustCenterReferenceList); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
prb := r.ProboService(ctx, obj.ParentID.TenantID())
|
|
|
|
count, err := prb.TrustCenterReferences.CountForTrustCenterID(ctx, 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 }
|