255 lines
8.1 KiB
Go
255 lines
8.1 KiB
Go
package complianceportal_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.94
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"go.gearno.de/kit/log"
|
|
"go.probo.inc/probo/pkg/complianceportal/visitor"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/gid"
|
|
"go.probo.inc/probo/pkg/page"
|
|
"go.probo.inc/probo/pkg/server/api/authn"
|
|
"go.probo.inc/probo/pkg/server/api/complianceportal"
|
|
"go.probo.inc/probo/pkg/server/api/complianceportal/v1/schema"
|
|
"go.probo.inc/probo/pkg/server/api/complianceportal/v1/types"
|
|
"go.probo.inc/probo/pkg/server/gqlutils"
|
|
)
|
|
|
|
// Viewer is the resolver for the viewer field.
|
|
func (r *queryResolver) Viewer(ctx context.Context) (*types.Identity, error) {
|
|
identity := authn.IdentityFromContext(ctx)
|
|
|
|
if identity == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
return &types.Identity{
|
|
ID: identity.ID,
|
|
Email: identity.EmailAddress,
|
|
FullName: identity.FullName,
|
|
EmailVerified: identity.EmailAddressVerified,
|
|
Locale: identity.Locale,
|
|
CreatedAt: identity.CreatedAt,
|
|
UpdatedAt: identity.UpdatedAt,
|
|
}, nil
|
|
}
|
|
|
|
// Node is the resolver for the node field.
|
|
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
|
|
scope := coredata.NewScopeFromObjectID(id)
|
|
visitorService := r.visitor
|
|
|
|
switch id.EntityType() {
|
|
case coredata.DocumentEntityType:
|
|
compliancePortal := complianceportal.CompliancePortalFromContext(ctx)
|
|
|
|
document, err := visitorService.GetDocument(ctx, scope, compliancePortal.OrganizationID, id)
|
|
if err != nil {
|
|
if errors.Is(err, visitor.ErrDocumentNotFound) || errors.Is(err, visitor.ErrDocumentNotVisible) || errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
|
|
}
|
|
|
|
if _, ok := errors.AsType[*visitor.ErrDocumentArchived](err); ok {
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get document", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewDocument(document), nil
|
|
|
|
case coredata.FrameworkEntityType:
|
|
framework, err := visitorService.GetFramework(ctx, scope, id)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get framework", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewFramework(framework), nil
|
|
|
|
case coredata.FileEntityType:
|
|
compliancePortal := complianceportal.CompliancePortalFromContext(ctx)
|
|
|
|
file, err := visitorService.GetReport(ctx, scope, compliancePortal.OrganizationID, id)
|
|
if err != nil {
|
|
if errors.Is(err, visitor.ErrReportNotFound) || errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get audit report file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewAuditReport(file), nil
|
|
|
|
case coredata.AuditEntityType:
|
|
audit, err := visitorService.GetAudit(ctx, scope, id)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get audit", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewAudit(audit), nil
|
|
|
|
case coredata.ThirdPartyEntityType:
|
|
thirdParty, err := visitorService.GetThirdParty(ctx, scope, id)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get thirdParty", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewSubprocessor(thirdParty), nil
|
|
|
|
case coredata.CompliancePortalEntityType:
|
|
compliancePortal, err := visitorService.GetPortal(ctx, scope, id)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get compliance portal", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewCompliancePortal(compliancePortal), nil
|
|
|
|
case coredata.CompliancePortalReferenceEntityType:
|
|
reference, err := visitorService.GetPortalReference(ctx, scope, id)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get compliance portal reference", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewCompliancePortalReference(reference), nil
|
|
|
|
case coredata.CompliancePortalFileEntityType:
|
|
compliancePortal := complianceportal.CompliancePortalFromContext(ctx)
|
|
|
|
portalFile, err := visitorService.GetPortalFile(ctx, scope, compliancePortal.OrganizationID, id)
|
|
if err != nil {
|
|
if errors.Is(err, visitor.ErrPortalFileNotFound) || errors.Is(err, visitor.ErrPortalFileNotVisible) {
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot get compliance portal file", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewCompliancePortalFile(portalFile), nil
|
|
|
|
default:
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", id)
|
|
}
|
|
}
|
|
|
|
// AliasedNode is the resolver for the aliasedNode field.
|
|
func (r *queryResolver) AliasedNode(ctx context.Context, alias string) (types.Node, error) {
|
|
resourceID, err := gid.ParseGID(alias)
|
|
if err != nil {
|
|
compliancePortal := complianceportal.CompliancePortalFromContext(ctx)
|
|
scope := coredata.NewScopeFromObjectID(compliancePortal.ID)
|
|
|
|
resourceID, err = r.resourceAlias.ResolveAlias(
|
|
ctx,
|
|
scope,
|
|
alias,
|
|
)
|
|
if err != nil {
|
|
if errors.Is(err, coredata.ErrResourceNotFound) {
|
|
return nil, gqlutils.NotFoundf(ctx, "node %q not found", alias)
|
|
}
|
|
|
|
r.logger.ErrorCtx(ctx, "cannot resolve resource alias", log.Error(err))
|
|
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
}
|
|
|
|
return r.Node(ctx, resourceID)
|
|
}
|
|
|
|
// CurrentCompliancePortal is the resolver for the currentCompliancePortal field.
|
|
func (r *queryResolver) CurrentCompliancePortal(ctx context.Context) (*types.CompliancePortal, error) {
|
|
compliancePortal := complianceportal.CompliancePortalFromContext(ctx)
|
|
|
|
scope := coredata.NewScopeFromObjectID(compliancePortal.ID)
|
|
visitorService := r.visitor
|
|
|
|
compliancePortal, err := visitorService.GetPortal(ctx, scope, compliancePortal.ID)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot get compliance portal", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewCompliancePortal(compliancePortal), nil
|
|
}
|
|
|
|
// OidcProviders is the resolver for the oidcProviders field.
|
|
func (r *queryResolver) OidcProviders(ctx context.Context) ([]*types.OIDCProviderInfo, error) {
|
|
providers := r.iam.OIDCService.EnabledProviders()
|
|
result := make([]*types.OIDCProviderInfo, 0, len(providers))
|
|
|
|
for _, p := range providers {
|
|
name := strings.ToLower(p.String())
|
|
result = append(
|
|
result,
|
|
&types.OIDCProviderInfo{
|
|
Name: name,
|
|
LoginURL: r.baseURL.WithPath("/api/connect/v1/oidc/" + name + "/login").MustString(),
|
|
},
|
|
)
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
// MyRightsRequests is the resolver for the myRightsRequests field.
|
|
func (r *queryResolver) MyRightsRequests(ctx context.Context, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.RightsRequestConnection, error) {
|
|
pageOrderBy := page.OrderBy[coredata.RightsRequestOrderField]{
|
|
Field: coredata.RightsRequestOrderFieldCreatedAt,
|
|
Direction: page.OrderDirectionDesc,
|
|
}
|
|
cursor := types.NewCursor(first, after, last, before, pageOrderBy)
|
|
|
|
identity := authn.IdentityFromContext(ctx)
|
|
if identity == nil {
|
|
emptyPage := page.NewPage([]*coredata.RightsRequest{}, cursor)
|
|
return types.NewRightsRequestConnection(emptyPage), nil
|
|
}
|
|
|
|
compliancePage := complianceportal.CompliancePortalFromContext(ctx)
|
|
scope := coredata.NewScopeFromObjectID(compliancePage.OrganizationID)
|
|
|
|
result, err := r.visitor.ListRightsRequestsForOrganizationIDAndContact(
|
|
ctx,
|
|
scope,
|
|
compliancePage.OrganizationID,
|
|
identity.EmailAddress.String(),
|
|
cursor,
|
|
)
|
|
if err != nil {
|
|
r.logger.ErrorCtx(ctx, "cannot list rights requests", log.Error(err))
|
|
return nil, gqlutils.Internal(ctx)
|
|
}
|
|
|
|
return types.NewRightsRequestConnection(result), nil
|
|
}
|
|
|
|
// Mutation returns schema.MutationResolver implementation.
|
|
func (r *Resolver) Mutation() schema.MutationResolver { return &mutationResolver{r} }
|
|
|
|
// Query returns schema.QueryResolver implementation.
|
|
func (r *Resolver) Query() schema.QueryResolver { return &queryResolver{r} }
|
|
|
|
type (
|
|
mutationResolver struct{ *Resolver }
|
|
queryResolver struct{ *Resolver }
|
|
)
|