Enable rbac on node query

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-12-23 09:43:45 +01:00
parent e9ac50d91c
commit cc964ecc91
2 changed files with 228 additions and 195 deletions

View File

@@ -35,6 +35,7 @@ const (
ActionTrustCenterReferenceCreate = "core:trust-center:create-reference" ActionTrustCenterReferenceCreate = "core:trust-center:create-reference"
// TrustCenterAccess actions // TrustCenterAccess actions
ActionTrustCenterAccessGet = "core:trust-center-access:get"
ActionTrustCenterAccessUpdate = "core:trust-center-access:update" ActionTrustCenterAccessUpdate = "core:trust-center-access:update"
ActionTrustCenterAccessDelete = "core:trust-center-access:delete" ActionTrustCenterAccessDelete = "core:trust-center-access:delete"
@@ -65,16 +66,19 @@ const (
ActionVendorAssess = "core:vendor:assess" ActionVendorAssess = "core:vendor:assess"
// VendorContact actions // VendorContact actions
ActionVendorContactGet = "core:vendor-contact:get"
ActionVendorContactCreate = "core:vendor-contact:create" ActionVendorContactCreate = "core:vendor-contact:create"
ActionVendorContactUpdate = "core:vendor-contact:update" ActionVendorContactUpdate = "core:vendor-contact:update"
ActionVendorContactDelete = "core:vendor-contact:delete" ActionVendorContactDelete = "core:vendor-contact:delete"
// VendorService actions // VendorService actions
ActionVendorServiceGet = "core:vendor-service:get"
ActionVendorServiceCreate = "core:vendor-service:create" ActionVendorServiceCreate = "core:vendor-service:create"
ActionVendorServiceUpdate = "core:vendor-service:update" ActionVendorServiceUpdate = "core:vendor-service:update"
ActionVendorServiceDelete = "core:vendor-service:delete" ActionVendorServiceDelete = "core:vendor-service:delete"
// VendorComplianceReport actions // VendorComplianceReport actions
ActionVendorComplianceReportGet = "core:vendor-compliance-report:get"
ActionVendorComplianceReportUpload = "core:vendor-compliance-report:upload" ActionVendorComplianceReportUpload = "core:vendor-compliance-report:upload"
ActionVendorComplianceReportDelete = "core:vendor-compliance-report:delete" ActionVendorComplianceReportDelete = "core:vendor-compliance-report:delete"
@@ -243,6 +247,7 @@ const (
// Meeting actions // Meeting actions
ActionMeetingList = "core:meeting:list" ActionMeetingList = "core:meeting:list"
ActionMeetingGet = "core:meeting:get"
ActionMeetingCreate = "core:meeting:create" ActionMeetingCreate = "core:meeting:create"
ActionMeetingUpdate = "core:meeting:update" ActionMeetingUpdate = "core:meeting:update"
ActionMeetingDelete = "core:meeting:delete" ActionMeetingDelete = "core:meeting:delete"
@@ -263,6 +268,7 @@ const (
ActionDataProtectionOfficerList = "core:data-protection-officer:list" ActionDataProtectionOfficerList = "core:data-protection-officer:list"
ActionRightsRequesList = "core:rights-request:list" ActionRightsRequesList = "core:rights-request:list"
ActionRightsRequestGet = "core:rights-request:get"
ActionStateOfApplicabilityList = "core:state-of-applicability:list" ActionStateOfApplicabilityList = "core:state-of-applicability:list"
ActionStateOfApplicabilityGet = "core:state-of-applicability:get" ActionStateOfApplicabilityGet = "core:state-of-applicability:get"

View File

@@ -5798,282 +5798,309 @@ func (r *processingActivityConnectionResolver) TotalCount(ctx context.Context, o
// Node is the resolver for the node field. // Node is the resolver for the node field.
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) { func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
// TODO use right action var (
//r.MustAuthorize(ctx, id, probo.ActionGet) loadNode func(ctx context.Context, id gid.GID) (types.Node, error)
action string
prb := r.ProboService(ctx, id.TenantID()) prb = r.ProboService(ctx, id.TenantID())
)
switch id.EntityType() { switch id.EntityType() {
case coredata.OrganizationEntityType: case coredata.OrganizationEntityType:
action = iam.ActionIAMOrganizationGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
organization, err := prb.Organizations.Get(ctx, id) organization, err := prb.Organizations.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get organization: %w", err))
}
return types.NewOrganization(organization), nil return types.NewOrganization(organization), nil
}
case coredata.PeopleEntityType: case coredata.PeopleEntityType:
action = probo.ActionPeopleGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
people, err := prb.Peoples.Get(ctx, id) people, err := prb.Peoples.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get people: %w", err))
}
return types.NewPeople(people), nil return types.NewPeople(people), nil
}
case coredata.VendorEntityType: case coredata.VendorEntityType:
action = probo.ActionVendorGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
vendor, err := prb.Vendors.Get(ctx, id) vendor, err := prb.Vendors.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get vendor: %w", err))
}
return types.NewVendor(vendor), nil return types.NewVendor(vendor), nil
}
case coredata.FrameworkEntityType: case coredata.FrameworkEntityType:
action = probo.ActionFrameworkGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
framework, err := prb.Frameworks.Get(ctx, id) framework, err := prb.Frameworks.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get framework: %w", err))
}
return types.NewFramework(framework), nil return types.NewFramework(framework), nil
}
case coredata.MeasureEntityType: case coredata.MeasureEntityType:
action = probo.ActionMeasureGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
measure, err := prb.Measures.Get(ctx, id) measure, err := prb.Measures.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get measure: %w", err))
}
return types.NewMeasure(measure), nil return types.NewMeasure(measure), nil
}
case coredata.TaskEntityType: case coredata.TaskEntityType:
action = probo.ActionTaskGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
task, err := prb.Tasks.Get(ctx, id) task, err := prb.Tasks.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get task: %w", err))
}
return types.NewTask(task), nil return types.NewTask(task), nil
}
case coredata.EvidenceEntityType: case coredata.EvidenceEntityType:
action = probo.ActionEvidenceList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
evidence, err := prb.Evidences.Get(ctx, id) evidence, err := prb.Evidences.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get evidence: %w", err)) return nil, err
} }
return types.NewEvidence(evidence), nil return types.NewEvidence(evidence), nil
}
case coredata.DocumentEntityType: case coredata.DocumentEntityType:
action = probo.ActionDocumentGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
document, err := prb.Documents.Get(ctx, id) document, err := prb.Documents.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get document: %w", err))
}
return types.NewDocument(document), nil return types.NewDocument(document), nil
}
case coredata.ControlEntityType: case coredata.ControlEntityType:
action = probo.ActionControlList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
control, err := prb.Controls.Get(ctx, id) control, err := prb.Controls.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get control: %w", err))
}
return types.NewControl(control), nil return types.NewControl(control), nil
}
case coredata.RiskEntityType: case coredata.RiskEntityType:
action = probo.ActionRiskList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
risk, err := prb.Risks.Get(ctx, id) risk, err := prb.Risks.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get risk: %w", err))
}
return types.NewRisk(risk), nil return types.NewRisk(risk), nil
}
case coredata.VendorComplianceReportEntityType: case coredata.VendorComplianceReportEntityType:
action = probo.ActionVendorComplianceReportGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
vendorComplianceReport, err := prb.VendorComplianceReports.Get(ctx, id) vendorComplianceReport, err := prb.VendorComplianceReports.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get vendor compliance report: %w", err)) return nil, err
} }
return types.NewVendorComplianceReport(vendorComplianceReport), nil return types.NewVendorComplianceReport(vendorComplianceReport), nil
}
case coredata.VendorContactEntityType: case coredata.VendorContactEntityType:
action = probo.ActionVendorContactGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
vendorContact, err := prb.VendorContacts.Get(ctx, id) vendorContact, err := prb.VendorContacts.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get vendor contact: %w", err)) return nil, err
} }
return types.NewVendorContact(vendorContact), nil return types.NewVendorContact(vendorContact), nil
}
case coredata.VendorServiceEntityType: case coredata.VendorServiceEntityType:
action = probo.ActionVendorServiceGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
vendorService, err := prb.VendorServices.Get(ctx, id) vendorService, err := prb.VendorServices.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get vendor service: %w", err)) return nil, err
} }
return types.NewVendorService(vendorService), nil return types.NewVendorService(vendorService), nil
}
case coredata.DocumentVersionEntityType: case coredata.DocumentVersionEntityType:
action = probo.ActionDocumentVersionList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
documentVersion, err := prb.Documents.GetVersion(ctx, id) documentVersion, err := prb.Documents.GetVersion(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get document version: %w", err)) return nil, err
} }
return types.NewDocumentVersion(documentVersion), nil return types.NewDocumentVersion(documentVersion), nil
}
case coredata.DocumentVersionSignatureEntityType: case coredata.DocumentVersionSignatureEntityType:
action = probo.ActionDocumentVersionSignatureList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
documentVersionSignature, err := prb.Documents.GetVersionSignature(ctx, id) documentVersionSignature, err := prb.Documents.GetVersionSignature(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get document version signature: %w", err)) return nil, err
} }
return types.NewDocumentVersionSignature(documentVersionSignature), nil return types.NewDocumentVersionSignature(documentVersionSignature), nil
}
case coredata.AssetEntityType: case coredata.AssetEntityType:
action = probo.ActionAssetList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
asset, err := prb.Assets.Get(ctx, id) asset, err := prb.Assets.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get asset: %w", err))
}
return types.NewAsset(asset), nil return types.NewAsset(asset), nil
}
case coredata.DatumEntityType: case coredata.DatumEntityType:
action = probo.ActionDatumList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
datum, err := prb.Data.Get(ctx, id) datum, err := prb.Data.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get data: %w", err)) return nil, err
} }
return types.NewDatum(datum), nil return types.NewDatum(datum), nil
}
case coredata.AuditEntityType: case coredata.AuditEntityType:
action = probo.ActionAuditList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
audit, err := prb.Audits.Get(ctx, id) audit, err := prb.Audits.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get audit: %w", err))
}
return types.NewAudit(audit), nil return types.NewAudit(audit), nil
}
case coredata.NonconformityEntityType: case coredata.NonconformityEntityType:
action = probo.ActionNonconformityList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
nonconformity, err := prb.Nonconformities.Get(ctx, id) nonconformity, err := prb.Nonconformities.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get nonconformity: %w", err)) return nil, err
} }
return types.NewNonconformity(nonconformity), nil return types.NewNonconformity(nonconformity), nil
}
case coredata.ObligationEntityType: case coredata.ObligationEntityType:
action = probo.ActionObligationList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
obligation, err := prb.Obligations.Get(ctx, id) obligation, err := prb.Obligations.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get obligation: %w", err)) return nil, err
} }
return types.NewObligation(obligation), nil return types.NewObligation(obligation), nil
}
case coredata.ContinualImprovementEntityType: case coredata.ContinualImprovementEntityType:
action = probo.ActionContinualImprovementList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
continualImprovement, err := prb.ContinualImprovements.Get(ctx, id) continualImprovement, err := prb.ContinualImprovements.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get continual improvement: %w", err)) return nil, err
} }
return types.NewContinualImprovement(continualImprovement), nil return types.NewContinualImprovement(continualImprovement), nil
}
case coredata.ReportEntityType: case coredata.ReportEntityType:
action = probo.ActionReportGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
report, err := prb.Reports.Get(ctx, id) report, err := prb.Reports.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get report: %w", err)) return nil, err
} }
return types.NewReport(report), nil return types.NewReport(report), nil
}
case coredata.ProcessingActivityEntityType: case coredata.ProcessingActivityEntityType:
action = probo.ActionProcessingActivityList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
processingActivity, err := prb.ProcessingActivities.Get(ctx, id) processingActivity, err := prb.ProcessingActivities.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get processing activity: %w", err)) return nil, err
} }
return types.NewProcessingActivity(processingActivity), nil return types.NewProcessingActivity(processingActivity), nil
}
case coredata.DataProtectionImpactAssessmentEntityType: case coredata.DataProtectionImpactAssessmentEntityType:
// TODO: add action
// action = probo.ActionDataProtectionImpactAssessmentGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
dpia, err := prb.DataProtectionImpactAssessments.Get(ctx, id) dpia, err := prb.DataProtectionImpactAssessments.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get processing activity dpia: %w", err)) return nil, err
} }
return types.NewDataProtectionImpactAssessment(dpia), nil return types.NewDataProtectionImpactAssessment(dpia), nil
}
case coredata.TransferImpactAssessmentEntityType: case coredata.TransferImpactAssessmentEntityType:
// TODO: add action
//action = probo.ActionTransferImpactAssessmentGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
tia, err := prb.TransferImpactAssessments.Get(ctx, id) tia, err := prb.TransferImpactAssessments.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get processing activity tia: %w", err)) return nil, err
} }
return types.NewTransferImpactAssessment(tia), nil return types.NewTransferImpactAssessment(tia), nil
}
case coredata.SnapshotEntityType: case coredata.SnapshotEntityType:
action = probo.ActionSnapshotList
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
snapshot, err := prb.Snapshots.Get(ctx, id) snapshot, err := prb.Snapshots.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get snapshot: %w", err)) return nil, err
} }
return types.NewSnapshot(snapshot), nil return types.NewSnapshot(snapshot), nil
}
case coredata.TrustCenterEntityType: case coredata.TrustCenterEntityType:
action = probo.ActionTrustCenterGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
trustCenter, file, err := prb.TrustCenters.Get(ctx, id) trustCenter, file, err := prb.TrustCenters.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get trust center with file: %w", err)) return nil, err
} }
return types.NewTrustCenter(trustCenter, file), nil return types.NewTrustCenter(trustCenter, file), nil
}
case coredata.TrustCenterAccessEntityType: case coredata.TrustCenterAccessEntityType:
action = probo.ActionTrustCenterAccessGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
trustCenterAccess, err := prb.TrustCenterAccesses.Get(ctx, id) trustCenterAccess, err := prb.TrustCenterAccesses.Get(ctx, id)
if err != nil { if err != nil {
panic(fmt.Errorf("cannot get trust center access: %w", err)) return nil, err
} }
return types.NewTrustCenterAccess(trustCenterAccess), nil return types.NewTrustCenterAccess(trustCenterAccess), nil
}
case coredata.MeetingEntityType: case coredata.MeetingEntityType:
action = probo.ActionMeetingGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
meeting, err := prb.Meetings.Get(ctx, id) meeting, err := prb.Meetings.Get(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceAlreadyExists) { return nil, err
return nil, gqlutils.Conflict(err)
} }
panic(fmt.Errorf("cannot get meeting: %w", err))
}
return types.NewMeeting(meeting), nil return types.NewMeeting(meeting), nil
}
case coredata.RightsRequestEntityType: case coredata.RightsRequestEntityType:
action = probo.ActionRightsRequestGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
rightsRequest, err := prb.RightsRequests.Get(ctx, id) rightsRequest, err := prb.RightsRequests.Get(ctx, id)
if err != nil { if err != nil {
var errNotFound *coredata.ErrRightsRequestNotFound return nil, err
if errors.As(err, &errNotFound) {
return nil, gqlutils.NotFound(errNotFound)
} }
panic(fmt.Errorf("cannot get rights request: %w", err)) return types.NewRightsRequest(rightsRequest), nil
}
case coredata.StateOfApplicabilityEntityType:
action = probo.ActionStateOfApplicabilityGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
stateOfApplicability, err := prb.StatesOfApplicability.Get(ctx, id)
if err != nil {
return nil, err
}
return types.NewStateOfApplicability(stateOfApplicability), nil
}
default:
} }
return types.NewRightsRequest(rightsRequest), nil r.MustAuthorize(ctx, id, action)
case coredata.StateOfApplicabilityEntityType:
stateOfApplicability, err := prb.StatesOfApplicability.Get(ctx, id) node, err := loadNode(ctx, id)
if err != nil { if err != nil {
if errors.Is(err, coredata.ErrResourceNotFound) { if errors.Is(err, coredata.ErrResourceNotFound) {
return nil, gqlutils.NotFound(err) return nil, gqlutils.NotFound(err)
} }
panic(fmt.Errorf("cannot get state_of_applicability: %w", err))
panic(fmt.Errorf("cannot load node: %w", err))
} }
return types.NewStateOfApplicability(stateOfApplicability), nil return node, nil
default:
}
panic(fmt.Errorf("unknown entity type: %d", id.EntityType()))
} }
// Viewer is the resolver for the viewer field. // Viewer is the resolver for the viewer field.