Use trust center from context

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-13 14:42:05 +04:00
committed by Bryan Frimin
parent 7322201dab
commit e220c259b3
33 changed files with 535 additions and 839 deletions

View File

@@ -0,0 +1,52 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"net/http"
"github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/v2/gqlerror"
"go.gearno.de/kit/httpserver"
"go.probo.inc/probo/pkg/server/gqlutils"
)
func NewCompliancePagePresenceMiddleware() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
compliancePage := CompliancePageFromContext(r.Context())
if compliancePage == nil {
httpserver.RenderJSON(
w,
http.StatusNotFound,
&graphql.Response{
Errors: gqlerror.List{
gqlutils.NotFoundf(
r.Context(),
"compliance page not found",
),
},
},
)
return
}
next.ServeHTTP(w, r)
},
)
}
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"go.probo.inc/probo/pkg/coredata"
)
type ctxKey struct{ name string }
var (
compliancePageKey = &ctxKey{name: "compliance_page"}
)
func CompliancePageFromContext(ctx context.Context) *coredata.TrustCenter {
trustCenter, _ := ctx.Value(compliancePageKey).(*coredata.TrustCenter)
return trustCenter
}

View File

@@ -0,0 +1,56 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"net/http"
"github.com/go-chi/chi/v5"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/trust"
)
func NewIDMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// TODO: remove slug support
value := chi.URLParam(r, "slugOrId")
if id, err := gid.ParseGID(value); err == nil {
compliancePage, err := trustSvc.Get(ctx, id)
if err != nil || !compliancePage.Active {
next.ServeHTTP(w, r)
return
}
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
return
}
if compliancePage, err := trustSvc.GetBySlug(ctx, value); err == nil && compliancePage.Active {
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
return
}
next.ServeHTTP(w, r)
},
)
}
}

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package compliancepage
import (
"context"
"net/http"
"go.probo.inc/probo/pkg/trust"
)
func NewSNIMiddleware(trustSvc *trust.Service) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if r.TLS == nil {
next.ServeHTTP(w, r)
return
}
compliancePage, err := trustSvc.GetByDomainName(ctx, r.TLS.ServerName)
if err != nil || !compliancePage.Active {
next.ServeHTTP(w, r)
return
}
ctx = context.WithValue(ctx, compliancePageKey, compliancePage)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
}

View File

@@ -28,7 +28,6 @@ import (
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/authz"
"go.probo.inc/probo/pkg/server/api/connect/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
)
type (
@@ -44,8 +43,6 @@ type (
func NewMux(logger *log.Logger, svc *iam.Service, cookieConfig securecookie.Config, tokenSecret string, baseURL *baseurl.BaseURL) *chi.Mux {
r := chi.NewMux()
r.Use(gqlutils.HTTPContextMiddleware)
sessionMiddleware := authn.NewSessionMiddleware(svc, cookieConfig)
apiKeyMiddleware := authn.NewAPIKeyMiddleware(svc, tokenSecret)
graphqlHandler := NewGraphQLHandler(svc, logger, baseURL, cookieConfig)

View File

@@ -25,9 +25,9 @@ import (
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/probo"
"go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/compliancepage"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
@@ -58,16 +58,19 @@ type (
type ctxKey struct{ name string }
var (
TrustCenterKey = &ctxKey{name: "trust_center"}
trustCenterIDKey = &ctxKey{name: "trust_center_id"}
)
func TrustCenterFromContext(ctx context.Context) probo.TrustCenterInfo {
trustCenter, _ := ctx.Value(TrustCenterKey).(probo.TrustCenterInfo)
return trustCenter
func TrustCenterIDFromContext(ctx context.Context) gid.GID {
if trustCenterID, ok := ctx.Value(trustCenterIDKey).(gid.GID); ok {
return trustCenterID
}
return gid.Nil
}
func ContextWithTrustCenter(ctx context.Context, trustCenter probo.TrustCenterInfo) context.Context {
return context.WithValue(ctx, TrustCenterKey, trustCenter)
func ContextWithTrustCenterID(ctx context.Context, trustCenterID gid.GID) context.Context {
return context.WithValue(ctx, trustCenterIDKey, trustCenterID)
}
func NewMux(
@@ -78,8 +81,8 @@ func NewMux(
) *chi.Mux {
r := chi.NewMux()
sessionMiddleware := authn.NewSessionMiddleware(iamSvc, cookieConfig)
r.Use(sessionMiddleware)
r.Use(compliancepage.NewCompliancePagePresenceMiddleware())
r.Use(authn.NewSessionMiddleware(iamSvc, cookieConfig))
config := schema.Config{
Resolvers: &Resolver{

View File

@@ -553,7 +553,6 @@ type SignInWithTokenPayload {
}
input RequestAllAccessesInput {
trustCenterId: ID!
email: EmailAddr!
fullName: String!
}
@@ -570,26 +569,19 @@ input ExportReportPDFInput {
reportId: ID!
}
input AcceptNonDisclosureAgreementInput {
trustCenterId: ID!
}
input RequestDocumentAccessInput {
trustCenterId: ID!
documentId: ID!
email: EmailAddr!
fullName: String!
}
input RequestReportAccessInput {
trustCenterId: ID!
reportId: ID!
email: EmailAddr!
fullName: String!
}
input RequestTrustCenterFileAccessInput {
trustCenterId: ID!
trustCenterFileId: ID!
email: EmailAddr!
fullName: String!
@@ -618,7 +610,6 @@ type AcceptNonDisclosureAgreementPayload {
type Query {
viewer: Identity
node(id: ID!): Node!
trustCenterBySlug(slug: String!): TrustCenter @mustBeAuthenticated(role: NONE)
currentTrustCenter: TrustCenter @mustBeAuthenticated(role: NONE)
}
@@ -634,9 +625,8 @@ type Mutation {
exportReportPDF(input: ExportReportPDFInput!): ExportReportPDFPayload!
@mustBeAuthenticated(role: NONE)
acceptNonDisclosureAgreement(
input: AcceptNonDisclosureAgreementInput!
): AcceptNonDisclosureAgreementPayload! @mustBeAuthenticated(role: USER)
acceptNonDisclosureAgreement: AcceptNonDisclosureAgreementPayload!
@mustBeAuthenticated(role: USER)
requestDocumentAccess(
input: RequestDocumentAccessInput!

View File

@@ -130,7 +130,7 @@ type ComplexityRoot struct {
}
Mutation struct {
AcceptNonDisclosureAgreement func(childComplexity int, input types.AcceptNonDisclosureAgreementInput) int
AcceptNonDisclosureAgreement func(childComplexity int) int
ExportDocumentPDF func(childComplexity int, input types.ExportDocumentPDFInput) int
ExportReportPDF func(childComplexity int, input types.ExportReportPDFInput) int
ExportTrustCenterFile func(childComplexity int, input types.ExportTrustCenterFileInput) int
@@ -161,7 +161,6 @@ type ComplexityRoot struct {
Query struct {
CurrentTrustCenter func(childComplexity int) int
Node func(childComplexity int, id gid.GID) int
TrustCenterBySlug func(childComplexity int, slug string) int
Viewer func(childComplexity int) int
}
@@ -277,7 +276,7 @@ type MutationResolver interface {
RequestAllAccesses(ctx context.Context, input types.RequestAllAccessesInput) (*types.RequestAccessesPayload, error)
ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error)
ExportReportPDF(ctx context.Context, input types.ExportReportPDFInput) (*types.ExportReportPDFPayload, error)
AcceptNonDisclosureAgreement(ctx context.Context, input types.AcceptNonDisclosureAgreementInput) (*types.AcceptNonDisclosureAgreementPayload, error)
AcceptNonDisclosureAgreement(ctx context.Context) (*types.AcceptNonDisclosureAgreementPayload, error)
RequestDocumentAccess(ctx context.Context, input types.RequestDocumentAccessInput) (*types.RequestAccessesPayload, error)
RequestReportAccess(ctx context.Context, input types.RequestReportAccessInput) (*types.RequestAccessesPayload, error)
RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error)
@@ -289,7 +288,6 @@ type OrganizationResolver interface {
type QueryResolver interface {
Viewer(ctx context.Context) (*types.Identity, error)
Node(ctx context.Context, id gid.GID) (types.Node, error)
TrustCenterBySlug(ctx context.Context, slug string) (*types.TrustCenter, error)
CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error)
}
type ReportResolver interface {
@@ -531,12 +529,7 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
break
}
args, err := ec.field_Mutation_acceptNonDisclosureAgreement_args(ctx, rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Mutation.AcceptNonDisclosureAgreement(childComplexity, args["input"].(types.AcceptNonDisclosureAgreementInput)), true
return e.complexity.Mutation.AcceptNonDisclosureAgreement(childComplexity), true
case "Mutation.exportDocumentPDF":
if e.complexity.Mutation.ExportDocumentPDF == nil {
break
@@ -711,17 +704,6 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin
}
return e.complexity.Query.Node(childComplexity, args["id"].(gid.GID)), true
case "Query.trustCenterBySlug":
if e.complexity.Query.TrustCenterBySlug == nil {
break
}
args, err := ec.field_Query_trustCenterBySlug_args(ctx, rawArgs)
if err != nil {
return 0, false
}
return e.complexity.Query.TrustCenterBySlug(childComplexity, args["slug"].(string)), true
case "Query.viewer":
if e.complexity.Query.Viewer == nil {
break
@@ -1088,7 +1070,6 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler {
opCtx := graphql.GetOperationContext(ctx)
ec := executionContext{opCtx, e, 0, 0, make(chan graphql.DeferredResult)}
inputUnmarshalMap := graphql.BuildUnmarshalerMap(
ec.unmarshalInputAcceptNonDisclosureAgreementInput,
ec.unmarshalInputExportDocumentPDFInput,
ec.unmarshalInputExportReportPDFInput,
ec.unmarshalInputExportTrustCenterFileInput,
@@ -1749,7 +1730,6 @@ type SignInWithTokenPayload {
}
input RequestAllAccessesInput {
trustCenterId: ID!
email: EmailAddr!
fullName: String!
}
@@ -1766,26 +1746,19 @@ input ExportReportPDFInput {
reportId: ID!
}
input AcceptNonDisclosureAgreementInput {
trustCenterId: ID!
}
input RequestDocumentAccessInput {
trustCenterId: ID!
documentId: ID!
email: EmailAddr!
fullName: String!
}
input RequestReportAccessInput {
trustCenterId: ID!
reportId: ID!
email: EmailAddr!
fullName: String!
}
input RequestTrustCenterFileAccessInput {
trustCenterId: ID!
trustCenterFileId: ID!
email: EmailAddr!
fullName: String!
@@ -1814,7 +1787,6 @@ type AcceptNonDisclosureAgreementPayload {
type Query {
viewer: Identity
node(id: ID!): Node!
trustCenterBySlug(slug: String!): TrustCenter @mustBeAuthenticated(role: NONE)
currentTrustCenter: TrustCenter @mustBeAuthenticated(role: NONE)
}
@@ -1830,9 +1802,8 @@ type Mutation {
exportReportPDF(input: ExportReportPDFInput!): ExportReportPDFPayload!
@mustBeAuthenticated(role: NONE)
acceptNonDisclosureAgreement(
input: AcceptNonDisclosureAgreementInput!
): AcceptNonDisclosureAgreementPayload! @mustBeAuthenticated(role: USER)
acceptNonDisclosureAgreement: AcceptNonDisclosureAgreementPayload!
@mustBeAuthenticated(role: USER)
requestDocumentAccess(
input: RequestDocumentAccessInput!
@@ -1869,17 +1840,6 @@ func (ec *executionContext) dir_mustBeAuthenticated_args(ctx context.Context, ra
return args, nil
}
func (ec *executionContext) field_Mutation_acceptNonDisclosureAgreement_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", ec.unmarshalNAcceptNonDisclosureAgreementInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementInput)
if err != nil {
return nil, err
}
args["input"] = arg0
return args, nil
}
func (ec *executionContext) field_Mutation_exportDocumentPDF_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
@@ -1990,17 +1950,6 @@ func (ec *executionContext) field_Query_node_args(ctx context.Context, rawArgs m
return args, nil
}
func (ec *executionContext) field_Query_trustCenterBySlug_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
arg0, err := graphql.ProcessArgField(ctx, rawArgs, "slug", ec.unmarshalNString2string)
if err != nil {
return nil, err
}
args["slug"] = arg0
return args, nil
}
func (ec *executionContext) field_TrustCenter_audits_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) {
var err error
args := map[string]any{}
@@ -3366,8 +3315,7 @@ func (ec *executionContext) _Mutation_acceptNonDisclosureAgreement(ctx context.C
field,
ec.fieldContext_Mutation_acceptNonDisclosureAgreement,
func(ctx context.Context) (any, error) {
fc := graphql.GetFieldContext(ctx)
return ec.resolvers.Mutation().AcceptNonDisclosureAgreement(ctx, fc.Args["input"].(types.AcceptNonDisclosureAgreementInput))
return ec.resolvers.Mutation().AcceptNonDisclosureAgreement(ctx)
},
func(ctx context.Context, next graphql.Resolver) graphql.Resolver {
directive0 := next
@@ -3394,7 +3342,7 @@ func (ec *executionContext) _Mutation_acceptNonDisclosureAgreement(ctx context.C
)
}
func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Mutation",
Field: field,
@@ -3408,17 +3356,6 @@ func (ec *executionContext) fieldContext_Mutation_acceptNonDisclosureAgreement(c
return nil, fmt.Errorf("no field named %q was found under type AcceptNonDisclosureAgreementPayload", field.Name)
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Mutation_acceptNonDisclosureAgreement_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return fc, err
}
return fc, nil
}
@@ -4077,93 +4014,6 @@ func (ec *executionContext) fieldContext_Query_node(ctx context.Context, field g
return fc, nil
}
func (ec *executionContext) _Query_trustCenterBySlug(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
ec.OperationContext,
field,
ec.fieldContext_Query_trustCenterBySlug,
func(ctx context.Context) (any, error) {
fc := graphql.GetFieldContext(ctx)
return ec.resolvers.Query().TrustCenterBySlug(ctx, fc.Args["slug"].(string))
},
func(ctx context.Context, next graphql.Resolver) graphql.Resolver {
directive0 := next
directive1 := func(ctx context.Context) (any, error) {
role, err := ec.unmarshalORole2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐRole(ctx, "NONE")
if err != nil {
var zeroVal *types.TrustCenter
return zeroVal, err
}
if ec.directives.MustBeAuthenticated == nil {
var zeroVal *types.TrustCenter
return zeroVal, errors.New("directive mustBeAuthenticated is not implemented")
}
return ec.directives.MustBeAuthenticated(ctx, nil, directive0, role)
}
next = directive1
return next
},
ec.marshalOTrustCenter2ᚖgoᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐTrustCenter,
true,
false,
)
}
func (ec *executionContext) fieldContext_Query_trustCenterBySlug(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
fc = &graphql.FieldContext{
Object: "Query",
Field: field,
IsMethod: true,
IsResolver: true,
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
switch field.Name {
case "id":
return ec.fieldContext_TrustCenter_id(ctx, field)
case "active":
return ec.fieldContext_TrustCenter_active(ctx, field)
case "slug":
return ec.fieldContext_TrustCenter_slug(ctx, field)
case "ndaFileName":
return ec.fieldContext_TrustCenter_ndaFileName(ctx, field)
case "ndaFileUrl":
return ec.fieldContext_TrustCenter_ndaFileUrl(ctx, field)
case "organization":
return ec.fieldContext_TrustCenter_organization(ctx, field)
case "isUserAuthenticated":
return ec.fieldContext_TrustCenter_isUserAuthenticated(ctx, field)
case "hasAcceptedNonDisclosureAgreement":
return ec.fieldContext_TrustCenter_hasAcceptedNonDisclosureAgreement(ctx, field)
case "documents":
return ec.fieldContext_TrustCenter_documents(ctx, field)
case "audits":
return ec.fieldContext_TrustCenter_audits(ctx, field)
case "vendors":
return ec.fieldContext_TrustCenter_vendors(ctx, field)
case "references":
return ec.fieldContext_TrustCenter_references(ctx, field)
case "trustCenterFiles":
return ec.fieldContext_TrustCenter_trustCenterFiles(ctx, field)
}
return nil, fmt.Errorf("no field named %q was found under type TrustCenter", field.Name)
},
}
defer func() {
if r := recover(); r != nil {
err = ec.Recover(ctx, r)
ec.Error(ctx, err)
}
}()
ctx = graphql.WithFieldContext(ctx, fc)
if fc.Args, err = ec.field_Query_trustCenterBySlug_args(ctx, field.ArgumentMap(ec.Variables)); err != nil {
ec.Error(ctx, err)
return fc, err
}
return fc, nil
}
func (ec *executionContext) _Query_currentTrustCenter(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
return graphql.ResolveField(
ctx,
@@ -7505,33 +7355,6 @@ func (ec *executionContext) fieldContext___Type_isOneOf(_ context.Context, field
// region **************************** input.gotpl *****************************
func (ec *executionContext) unmarshalInputAcceptNonDisclosureAgreementInput(ctx context.Context, obj any) (types.AcceptNonDisclosureAgreementInput, error) {
var it types.AcceptNonDisclosureAgreementInput
asMap := map[string]any{}
for k, v := range obj.(map[string]any) {
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
}
}
return it, nil
}
func (ec *executionContext) unmarshalInputExportDocumentPDFInput(ctx context.Context, obj any) (types.ExportDocumentPDFInput, error) {
var it types.ExportDocumentPDFInput
asMap := map[string]any{}
@@ -7620,20 +7443,13 @@ func (ec *executionContext) unmarshalInputRequestAllAccessesInput(ctx context.Co
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "email", "fullName"}
fieldsInOrder := [...]string{"email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "email":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email"))
data, err := ec.unmarshalNEmailAddr2goᚗproboᚗincᚋproboᚋpkgᚋmailᚐAddr(ctx, v)
@@ -7661,20 +7477,13 @@ func (ec *executionContext) unmarshalInputRequestDocumentAccessInput(ctx context
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "documentId", "email", "fullName"}
fieldsInOrder := [...]string{"documentId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "documentId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("documentId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -7709,20 +7518,13 @@ func (ec *executionContext) unmarshalInputRequestReportAccessInput(ctx context.C
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "reportId", "email", "fullName"}
fieldsInOrder := [...]string{"reportId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "reportId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("reportId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -7757,20 +7559,13 @@ func (ec *executionContext) unmarshalInputRequestTrustCenterFileAccessInput(ctx
asMap[k] = v
}
fieldsInOrder := [...]string{"trustCenterId", "trustCenterFileId", "email", "fullName"}
fieldsInOrder := [...]string{"trustCenterFileId", "email", "fullName"}
for _, k := range fieldsInOrder {
v, ok := asMap[k]
if !ok {
continue
}
switch k {
case "trustCenterId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
if err != nil {
return it, err
}
it.TrustCenterID = data
case "trustCenterFileId":
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("trustCenterFileId"))
data, err := ec.unmarshalNID2goᚗproboᚗincᚋproboᚋpkgᚋgidᚐGID(ctx, v)
@@ -8951,25 +8746,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "trustCenterBySlug":
field := field
innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
}
}()
res = ec._Query_trustCenterBySlug(ctx, field)
return res
}
rrm := func(ctx context.Context) graphql.Marshaler {
return ec.OperationContext.RootResolverMiddleware(ctx,
func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
}
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) })
case "currentTrustCenter":
field := field
@@ -10511,11 +10287,6 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o
// region ***************************** type.gotpl *****************************
func (ec *executionContext) unmarshalNAcceptNonDisclosureAgreementInput2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementInput(ctx context.Context, v any) (types.AcceptNonDisclosureAgreementInput, error) {
res, err := ec.unmarshalInputAcceptNonDisclosureAgreementInput(ctx, v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalNAcceptNonDisclosureAgreementPayload2goᚗproboᚗincᚋproboᚋpkgᚋserverᚋapiᚋtrustᚋv1ᚋtypesᚐAcceptNonDisclosureAgreementPayload(ctx context.Context, sel ast.SelectionSet, v types.AcceptNonDisclosureAgreementPayload) graphql.Marshaler {
return ec._AcceptNonDisclosureAgreementPayload(ctx, sel, &v)
}

View File

@@ -20,10 +20,6 @@ type Node interface {
GetID() gid.GID
}
type AcceptNonDisclosureAgreementInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
}
type AcceptNonDisclosureAgreementPayload struct {
Success bool `json:"success"`
}
@@ -155,27 +151,23 @@ type RequestAccessesPayload struct {
}
type RequestAllAccessesInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestDocumentAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
DocumentID gid.GID `json:"documentId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
DocumentID gid.GID `json:"documentId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestReportAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
ReportID gid.GID `json:"reportId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
ReportID gid.GID `json:"reportId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`
}
type RequestTrustCenterFileAccessInput struct {
TrustCenterID gid.GID `json:"trustCenterId"`
TrustCenterFileID gid.GID `json:"trustCenterFileId"`
Email mail.Addr `json:"email"`
FullName string `json:"fullName"`

View File

@@ -18,6 +18,7 @@ import (
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/page"
"go.probo.inc/probo/pkg/server/api/authn"
"go.probo.inc/probo/pkg/server/api/compliancepage"
"go.probo.inc/probo/pkg/server/api/trust/v1/schema"
"go.probo.inc/probo/pkg/server/api/trust/v1/types"
"go.probo.inc/probo/pkg/server/gqlutils"
@@ -69,6 +70,7 @@ func (r *auditResolver) Report(ctx context.Context, obj *types.Audit) (*types.Re
// IsUserAuthorized is the resolver for the isUserAuthorized field.
func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Document) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
document, err := trustService.Documents.Get(ctx, obj.ID)
if err != nil {
@@ -85,7 +87,6 @@ func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Docu
return false, gqlutils.Unauthenticatedf(ctx, "unauthenticated")
}
trustCenter := TrustCenterFromContext(ctx)
documentAccess, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
trustCenter.ID,
@@ -105,13 +106,13 @@ func (r *documentResolver) IsUserAuthorized(ctx context.Context, obj *types.Docu
// HasUserRequestedAccess is the resolver for the hasUserRequestedAccess field.
func (r *documentResolver) HasUserRequestedAccess(ctx context.Context, obj *types.Document) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
return false, nil // User is not authenticated, so no access requested
}
trustCenter := TrustCenterFromContext(ctx)
// Try to load document access - if it exists (regardless of active status), user has requested it
_, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
@@ -166,7 +167,8 @@ func (r *mutationResolver) SignInWithToken(ctx context.Context, input types.Sign
// RequestAllAccesses is the resolver for the requestAllAccesses field.
func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.RequestAllAccessesInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -186,7 +188,7 @@ func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.R
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: nil,
@@ -212,8 +214,7 @@ func (r *mutationResolver) RequestAllAccesses(ctx context.Context, input types.R
// ExportDocumentPDF is the resolver for the exportDocumentPDF field.
func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.ExportDocumentPDFInput) (*types.ExportDocumentPDFPayload, error) {
trustService := r.TrustService(ctx, input.DocumentID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
document, err := trustService.Documents.Get(ctx, input.DocumentID)
if err != nil {
@@ -241,10 +242,6 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -256,7 +253,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -267,7 +264,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
documentAccess, err := trustService.TrustCenterAccesses.LoadDocumentAccess(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.DocumentID,
)
@@ -301,7 +298,7 @@ func (r *mutationResolver) ExportDocumentPDF(ctx context.Context, input types.Ex
func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.ExportReportPDFInput) (*types.ExportReportPDFPayload, error) {
trustService := r.TrustService(ctx, input.ReportID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
audit, err := trustService.Audits.GetByReportID(ctx, input.ReportID)
if err != nil {
@@ -329,10 +326,6 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
@@ -344,7 +337,7 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -355,7 +348,7 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
reportAccess, err := trustService.TrustCenterAccesses.LoadReportAccess(
ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.ReportID,
)
@@ -386,15 +379,25 @@ func (r *mutationResolver) ExportReportPDF(ctx context.Context, input types.Expo
}
// AcceptNonDisclosureAgreement is the resolver for the acceptNonDisclosureAgreement field.
func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context, input types.AcceptNonDisclosureAgreementInput) (*types.AcceptNonDisclosureAgreementPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context) (*types.AcceptNonDisclosureAgreementPayload, error) {
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
identity := authn.IdentityFromContext(ctx)
if identity == nil {
return nil, gqlutils.Unauthenticatedf(ctx, "unauthenticated")
}
if err := trustService.TrustCenterAccesses.AcceptNonDisclosureAgreement(ctx, input.TrustCenterID, identity.EmailAddress); err != nil {
httpReq := gqlutils.HTTPRequestFromContext(ctx)
if err := trustService.TrustCenterAccesses.AcceptNonDisclosureAgreement(
ctx,
&trust.AcceptNDARequest{
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
IPAddr: httpReq.RemoteAddr,
},
); err != nil {
r.logger.ErrorCtx(ctx, "cannot accept NDA", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
@@ -404,7 +407,8 @@ func (r *mutationResolver) AcceptNonDisclosureAgreement(ctx context.Context, inp
// RequestDocumentAccess is the resolver for the requestDocumentAccess field.
func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input types.RequestDocumentAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
document, err := trustService.Documents.Get(ctx, input.DocumentID)
if err != nil {
@@ -436,7 +440,7 @@ func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input type
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{input.DocumentID},
@@ -461,7 +465,8 @@ func (r *mutationResolver) RequestDocumentAccess(ctx context.Context, input type
// RequestReportAccess is the resolver for the requestReportAccess field.
func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.RequestReportAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
audit, err := trustService.Audits.GetByReportID(ctx, input.ReportID)
if err != nil {
@@ -494,7 +499,7 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{},
@@ -519,7 +524,8 @@ func (r *mutationResolver) RequestReportAccess(ctx context.Context, input types.
// RequestTrustCenterFileAccess is the resolver for the requestTrustCenterFileAccess field.
func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, input types.RequestTrustCenterFileAccessInput) (*types.RequestAccessesPayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterID.TenantID())
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
if err != nil {
@@ -552,7 +558,7 @@ func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, inp
access, err := trustService.TrustCenterAccesses.Request(
ctx,
&trust.TrustCenterAccessRequest{
TrustCenterID: input.TrustCenterID,
TrustCenterID: trustCenter.ID,
Email: identity.EmailAddress,
FullName: identity.FullName,
DocumentIDs: []gid.GID{},
@@ -578,9 +584,8 @@ func (r *mutationResolver) RequestTrustCenterFileAccess(ctx context.Context, inp
// ExportTrustCenterFile is the resolver for the exportTrustCenterFile field.
func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input types.ExportTrustCenterFileInput) (*types.ExportTrustCenterFilePayload, error) {
trustService := r.TrustService(ctx, input.TrustCenterFileID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, input.TrustCenterFileID)
if err != nil {
@@ -608,21 +613,13 @@ func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input type
ndaExists := true
hasAcceptedNDA := false
trustCenter, _, err := trustService.TrustCenters.Get(
ctx,
trustCenterInfo.ID,
)
if err != nil {
r.logger.ErrorCtx(ctx, "cannot get trust center", log.Error(err))
return nil, gqlutils.Internal(ctx)
}
if trustCenter.NonDisclosureAgreementFileID == nil {
ndaExists = false
}
if ndaExists {
hasAcceptedNDA, err = trustService.TrustCenterAccesses.HasAcceptedNonDisclosureAgreement(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
)
if err != nil {
@@ -632,7 +629,7 @@ func (r *mutationResolver) ExportTrustCenterFile(ctx context.Context, input type
}
fileAccess, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
input.TrustCenterFileID,
)
@@ -761,47 +758,18 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
}
}
// TrustCenterBySlug is the resolver for the trustCenterBySlug field.
func (r *queryResolver) TrustCenterBySlug(ctx context.Context, slug string) (*types.TrustCenter, error) {
rootTrustService := r.RootTrustService(ctx)
// CurrentTrustCenter is the resolver for the currentTrustCenter field.
func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error) {
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustCenter, err := rootTrustService.TrustCenters.GetBySlug(ctx, slug)
if err != nil {
return nil, nil
}
if !trustCenter.Active {
return nil, nil
}
trustService := r.TrustService(ctx, trustCenter.TenantID)
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenter.ID)
if err != nil {
panic(fmt.Errorf("cannot get trust center: %w", err))
}
trustService := r.TrustService(ctx, trustCenter.ID.TenantID())
org, err := trustService.Organizations.Get(ctx, trustCenter.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
}
response := types.NewTrustCenter(trustCenter, file)
response.Organization = types.NewOrganization(org)
return response, nil
}
// CurrentTrustCenter is the resolver for the currentTrustCenter field.
func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCenter, error) {
trustCenterInfo := TrustCenterFromContext(ctx)
trustService := r.TrustService(ctx, trustCenterInfo.ID.TenantID())
org, err := trustService.Organizations.Get(ctx, trustCenterInfo.OrganizationID)
if err != nil {
panic(fmt.Errorf("cannot get organization: %w", err))
}
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenterInfo.ID)
trustCenter, file, err := trustService.TrustCenters.Get(ctx, trustCenter.ID)
if err != nil {
panic(fmt.Errorf("cannot get trust center: %w", err))
}
@@ -816,7 +784,7 @@ func (r *queryResolver) CurrentTrustCenter(ctx context.Context) (*types.TrustCen
func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
audit, err := trustService.Audits.GetByReportID(ctx, obj.ID)
if err != nil {
@@ -834,7 +802,7 @@ func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report
}
reportAccess, err := trustService.TrustCenterAccesses.LoadReportAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -852,7 +820,7 @@ func (r *reportResolver) IsUserAuthorized(ctx context.Context, obj *types.Report
func (r *reportResolver) HasUserRequestedAccess(ctx context.Context, obj *types.Report) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -860,7 +828,7 @@ func (r *reportResolver) HasUserRequestedAccess(ctx context.Context, obj *types.
}
_, err := trustService.TrustCenterAccesses.LoadReportAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -1018,7 +986,7 @@ func (r *trustCenterResolver) TrustCenterFiles(ctx context.Context, obj *types.T
func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
trustCenterFile, err := trustService.TrustCenterFiles.Get(ctx, obj.ID)
if err != nil {
@@ -1036,7 +1004,7 @@ func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *typ
}
fileAccess, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)
@@ -1054,7 +1022,7 @@ func (r *trustCenterFileResolver) IsUserAuthorized(ctx context.Context, obj *typ
func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, obj *types.TrustCenterFile) (bool, error) {
trustService := r.TrustService(ctx, obj.ID.TenantID())
trustCenterInfo := TrustCenterFromContext(ctx)
trustCenter := compliancepage.CompliancePageFromContext(ctx)
identity := authn.IdentityFromContext(ctx)
if identity == nil {
@@ -1062,7 +1030,7 @@ func (r *trustCenterFileResolver) HasUserRequestedAccess(ctx context.Context, ob
}
_, err := trustService.TrustCenterAccesses.LoadTrustCenterFileAccess(ctx,
trustCenterInfo.ID,
trustCenter.ID,
identity.EmailAddress,
obj.ID,
)