Renames the user-facing 'vendor' concept to 'third party' across the entire codebase. The shared common_third_parties reference table is unchanged. Migration. Renames the vendor_category enum, the vendors and vendor_<entity> tables (contacts, services, compliance_reports, business_associate_agreements, data_privacy_agreements, risk_assessments) and their vendor_id columns, the asset_vendors / data_vendors / processing_activity_vendors junction tables, generated_documents.vendors_document_id, the webhook_event_type 'vendor:<verb>' values, and the snapshots_type 'VENDORS' value. Backend. Renames coredata models and SQL queries, probo services, GraphQL / MCP API surface, console / trust / webhook resolvers and types, the CLI (prb vendor* -> prb third-party*; pkg/cmd/vendormgmt -> pkg/cmd/thirdpartymgmt), the document generator, vetting agent prompts, and the common-third-parties-import command. Frontend, packages, n8n, e2e. Renames apps/console pages, components, hooks, routes, dialogs, and tabs; the shared @probo/vendors package (now @probo/third-parties); the @probo/ui Vendors atoms (now ThirdParties, VendorLogo -> ThirdPartyLogo); the n8n community node actions/vendor folder (now actions/thirdParty); and the e2e Go test suite (console and MCP). Filesystem and URL paths use kebab-case (third-parties), GraphQL fields and TypeScript identifiers use camelCase (thirdParty / thirdParties), Go types use PascalCase (ThirdParty), and human-facing text uses 'third party' with a space. Co-authored-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Bryan Frimin <bryan@getprobo.com> Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
383 lines
16 KiB
Go
383 lines
16 KiB
Go
// Copyright (c) 2025-2026 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 probo
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.gearno.de/kit/pg"
|
|
"go.probo.inc/probo/pkg/coredata"
|
|
"go.probo.inc/probo/pkg/gid"
|
|
"go.probo.inc/probo/pkg/page"
|
|
"go.probo.inc/probo/pkg/validator"
|
|
)
|
|
|
|
type ProcessingActivityService struct {
|
|
svc *TenantService
|
|
}
|
|
|
|
type (
|
|
CreateProcessingActivityRequest struct {
|
|
OrganizationID gid.GID
|
|
Name string
|
|
Purpose *string
|
|
DataSubjectCategory *string
|
|
PersonalDataCategory *string
|
|
SpecialOrCriminalData coredata.ProcessingActivitySpecialOrCriminalDatum
|
|
ConsentEvidenceLink *string
|
|
LawfulBasis coredata.ProcessingActivityLawfulBasis
|
|
Recipients *string
|
|
Location *string
|
|
InternationalTransfers bool
|
|
TransferSafeguard *coredata.ProcessingActivityTransferSafeguard
|
|
RetentionPeriod *string
|
|
SecurityMeasures *string
|
|
DataProtectionImpactAssessmentNeeded coredata.ProcessingActivityDataProtectionImpactAssessment
|
|
TransferImpactAssessmentNeeded coredata.ProcessingActivityTransferImpactAssessment
|
|
LastReviewDate *time.Time
|
|
NextReviewDate *time.Time
|
|
Role coredata.ProcessingActivityRole
|
|
DataProtectionOfficerID *gid.GID
|
|
ThirdPartyIDs []gid.GID
|
|
}
|
|
|
|
UpdateProcessingActivityRequest struct {
|
|
ID gid.GID
|
|
Name *string
|
|
Purpose **string
|
|
DataSubjectCategory **string
|
|
PersonalDataCategory **string
|
|
SpecialOrCriminalData *coredata.ProcessingActivitySpecialOrCriminalDatum
|
|
ConsentEvidenceLink **string
|
|
LawfulBasis *coredata.ProcessingActivityLawfulBasis
|
|
Recipients **string
|
|
Location **string
|
|
InternationalTransfers *bool
|
|
TransferSafeguard **coredata.ProcessingActivityTransferSafeguard
|
|
RetentionPeriod **string
|
|
SecurityMeasures **string
|
|
DataProtectionImpactAssessmentNeeded *coredata.ProcessingActivityDataProtectionImpactAssessment
|
|
TransferImpactAssessmentNeeded *coredata.ProcessingActivityTransferImpactAssessment
|
|
LastReviewDate **time.Time
|
|
NextReviewDate **time.Time
|
|
Role *coredata.ProcessingActivityRole
|
|
DataProtectionOfficerID **gid.GID
|
|
ThirdPartyIDs *[]gid.GID
|
|
}
|
|
)
|
|
|
|
func (cpar *CreateProcessingActivityRequest) Validate() error {
|
|
v := validator.New()
|
|
|
|
v.Check(cpar.OrganizationID, "organization_id", validator.Required(), validator.GID(coredata.OrganizationEntityType))
|
|
v.Check(cpar.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
|
|
v.Check(cpar.Purpose, "purpose", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.DataSubjectCategory, "data_subject_category", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.PersonalDataCategory, "personal_data_category", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.SpecialOrCriminalData, "special_or_criminal_data", validator.Required(), validator.OneOfSlice(coredata.ProcessingActivitySpecialOrCriminalData()))
|
|
v.Check(cpar.ConsentEvidenceLink, "consent_evidence_link", validator.SafeText(2048))
|
|
v.Check(cpar.LawfulBasis, "lawful_basis", validator.Required(), validator.OneOfSlice(coredata.ProcessingActivityLawfulBases()))
|
|
v.Check(cpar.Recipients, "recipients", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.Location, "location", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.InternationalTransfers, "international_transfers", validator.Required())
|
|
v.Check(cpar.TransferSafeguard, "transfer_safeguard", validator.OneOfSlice(coredata.ProcessingActivityTransferSafeguards()))
|
|
v.Check(cpar.RetentionPeriod, "retention_period", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.SecurityMeasures, "security_measures", validator.SafeText(TitleMaxLength))
|
|
v.Check(cpar.DataProtectionImpactAssessmentNeeded, "data_protection_impact_assessment_needed", validator.Required(), validator.OneOfSlice(coredata.ProcessingActivityDataProtectionImpactAssessments()))
|
|
v.Check(cpar.TransferImpactAssessmentNeeded, "transfer_impact_assessment_needed", validator.Required(), validator.OneOfSlice(coredata.ProcessingActivityTransferImpactAssessments()))
|
|
v.Check(cpar.Role, "role", validator.Required(), validator.OneOfSlice(coredata.ProcessingActivityRoles()))
|
|
v.Check(cpar.DataProtectionOfficerID, "data_protection_officer_id", validator.GID(coredata.MembershipProfileEntityType))
|
|
v.CheckEach(cpar.ThirdPartyIDs, "third_party_ids", func(index int, item any) {
|
|
v.Check(item, fmt.Sprintf("third_party_ids[%d]", index), validator.Required(), validator.GID(coredata.ThirdPartyEntityType))
|
|
})
|
|
|
|
return v.Error()
|
|
}
|
|
|
|
func (upar *UpdateProcessingActivityRequest) Validate() error {
|
|
v := validator.New()
|
|
|
|
v.Check(upar.ID, "id", validator.Required(), validator.GID(coredata.ProcessingActivityEntityType))
|
|
v.Check(upar.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
|
|
v.Check(upar.Purpose, "purpose", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.DataSubjectCategory, "data_subject_category", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.PersonalDataCategory, "personal_data_category", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.SpecialOrCriminalData, "special_or_criminal_data", validator.OneOfSlice(coredata.ProcessingActivitySpecialOrCriminalData()))
|
|
v.Check(upar.ConsentEvidenceLink, "consent_evidence_link", validator.SafeText(2048))
|
|
v.Check(upar.LawfulBasis, "lawful_basis", validator.OneOfSlice(coredata.ProcessingActivityLawfulBases()))
|
|
v.Check(upar.Recipients, "recipients", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.Location, "location", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.TransferSafeguard, "transfer_safeguards", validator.OneOfSlice(coredata.ProcessingActivityTransferSafeguards()))
|
|
v.Check(upar.RetentionPeriod, "retention_period", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.SecurityMeasures, "security_measures", validator.SafeText(TitleMaxLength))
|
|
v.Check(upar.DataProtectionImpactAssessmentNeeded, "data_protection_impact_assessment_needed", validator.OneOfSlice(coredata.ProcessingActivityDataProtectionImpactAssessments()))
|
|
v.Check(upar.TransferImpactAssessmentNeeded, "transfer_impact_assessment_needed", validator.OneOfSlice(coredata.ProcessingActivityTransferImpactAssessments()))
|
|
v.Check(upar.Role, "role", validator.OneOfSlice(coredata.ProcessingActivityRoles()))
|
|
v.Check(upar.DataProtectionOfficerID, "data_protection_officer_id", validator.GID(coredata.MembershipProfileEntityType))
|
|
v.CheckEach(upar.ThirdPartyIDs, "third_party_ids", func(index int, item any) {
|
|
v.Check(item, fmt.Sprintf("third_party_ids[%d]", index), validator.GID(coredata.ThirdPartyEntityType))
|
|
})
|
|
|
|
return v.Error()
|
|
}
|
|
|
|
func (s ProcessingActivityService) Get(
|
|
ctx context.Context,
|
|
processingActivityID gid.GID,
|
|
) (*coredata.ProcessingActivity, error) {
|
|
processingActivity := &coredata.ProcessingActivity{}
|
|
|
|
err := s.svc.pg.WithConn(
|
|
ctx,
|
|
func(ctx context.Context, conn pg.Querier) error {
|
|
return processingActivity.LoadByID(ctx, conn, s.svc.scope, processingActivityID)
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return processingActivity, nil
|
|
}
|
|
|
|
func (s *ProcessingActivityService) Create(
|
|
ctx context.Context,
|
|
req *CreateProcessingActivityRequest,
|
|
) (*coredata.ProcessingActivity, error) {
|
|
now := time.Now()
|
|
processingActivityThirdParties := &coredata.ProcessingActivityThirdParties{}
|
|
|
|
processingActivity := &coredata.ProcessingActivity{
|
|
ID: gid.New(s.svc.scope.GetTenantID(), coredata.ProcessingActivityEntityType),
|
|
OrganizationID: req.OrganizationID,
|
|
Name: req.Name,
|
|
Purpose: req.Purpose,
|
|
DataSubjectCategory: req.DataSubjectCategory,
|
|
PersonalDataCategory: req.PersonalDataCategory,
|
|
SpecialOrCriminalData: req.SpecialOrCriminalData,
|
|
ConsentEvidenceLink: req.ConsentEvidenceLink,
|
|
LawfulBasis: req.LawfulBasis,
|
|
Recipients: req.Recipients,
|
|
Location: req.Location,
|
|
InternationalTransfers: req.InternationalTransfers,
|
|
TransferSafeguard: req.TransferSafeguard,
|
|
RetentionPeriod: req.RetentionPeriod,
|
|
SecurityMeasures: req.SecurityMeasures,
|
|
DataProtectionImpactAssessmentNeeded: req.DataProtectionImpactAssessmentNeeded,
|
|
TransferImpactAssessmentNeeded: req.TransferImpactAssessmentNeeded,
|
|
LastReviewDate: req.LastReviewDate,
|
|
NextReviewDate: req.NextReviewDate,
|
|
Role: req.Role,
|
|
DataProtectionOfficerID: req.DataProtectionOfficerID,
|
|
CreatedAt: now,
|
|
UpdatedAt: now,
|
|
}
|
|
|
|
err := s.svc.pg.WithTx(
|
|
ctx,
|
|
func(ctx context.Context, conn pg.Tx) error {
|
|
organization := &coredata.Organization{}
|
|
if err := organization.LoadByID(ctx, conn, s.svc.scope, req.OrganizationID); err != nil {
|
|
return fmt.Errorf("cannot load organization: %w", err)
|
|
}
|
|
|
|
if err := processingActivity.Insert(ctx, conn, s.svc.scope); err != nil {
|
|
return fmt.Errorf("cannot insert processing activity: %w", err)
|
|
}
|
|
|
|
if len(req.ThirdPartyIDs) > 0 {
|
|
if err := processingActivityThirdParties.Insert(ctx, conn, s.svc.scope, processingActivity.ID, req.OrganizationID, req.ThirdPartyIDs); err != nil {
|
|
return fmt.Errorf("cannot create processing activity thirdParties: %w", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return processingActivity, nil
|
|
}
|
|
|
|
func (s *ProcessingActivityService) Update(
|
|
ctx context.Context,
|
|
req *UpdateProcessingActivityRequest,
|
|
) (*coredata.ProcessingActivity, error) {
|
|
processingActivity := &coredata.ProcessingActivity{}
|
|
processingActivityThirdParties := &coredata.ProcessingActivityThirdParties{}
|
|
|
|
err := s.svc.pg.WithTx(
|
|
ctx,
|
|
func(ctx context.Context, conn pg.Tx) error {
|
|
if err := processingActivity.LoadByID(ctx, conn, s.svc.scope, req.ID); err != nil {
|
|
return fmt.Errorf("cannot load processing activity: %w", err)
|
|
}
|
|
|
|
if req.Name != nil {
|
|
processingActivity.Name = *req.Name
|
|
}
|
|
if req.Purpose != nil {
|
|
processingActivity.Purpose = *req.Purpose
|
|
}
|
|
if req.DataSubjectCategory != nil {
|
|
processingActivity.DataSubjectCategory = *req.DataSubjectCategory
|
|
}
|
|
if req.PersonalDataCategory != nil {
|
|
processingActivity.PersonalDataCategory = *req.PersonalDataCategory
|
|
}
|
|
if req.SpecialOrCriminalData != nil {
|
|
processingActivity.SpecialOrCriminalData = *req.SpecialOrCriminalData
|
|
}
|
|
if req.ConsentEvidenceLink != nil {
|
|
processingActivity.ConsentEvidenceLink = *req.ConsentEvidenceLink
|
|
}
|
|
if req.LawfulBasis != nil {
|
|
processingActivity.LawfulBasis = *req.LawfulBasis
|
|
}
|
|
if req.Recipients != nil {
|
|
processingActivity.Recipients = *req.Recipients
|
|
}
|
|
if req.Location != nil {
|
|
processingActivity.Location = *req.Location
|
|
}
|
|
if req.InternationalTransfers != nil {
|
|
processingActivity.InternationalTransfers = *req.InternationalTransfers
|
|
}
|
|
if req.TransferSafeguard != nil {
|
|
processingActivity.TransferSafeguard = *req.TransferSafeguard
|
|
}
|
|
if req.RetentionPeriod != nil {
|
|
processingActivity.RetentionPeriod = *req.RetentionPeriod
|
|
}
|
|
if req.SecurityMeasures != nil {
|
|
processingActivity.SecurityMeasures = *req.SecurityMeasures
|
|
}
|
|
if req.DataProtectionImpactAssessmentNeeded != nil {
|
|
processingActivity.DataProtectionImpactAssessmentNeeded = *req.DataProtectionImpactAssessmentNeeded
|
|
}
|
|
if req.TransferImpactAssessmentNeeded != nil {
|
|
processingActivity.TransferImpactAssessmentNeeded = *req.TransferImpactAssessmentNeeded
|
|
}
|
|
if req.LastReviewDate != nil {
|
|
processingActivity.LastReviewDate = *req.LastReviewDate
|
|
}
|
|
if req.NextReviewDate != nil {
|
|
processingActivity.NextReviewDate = *req.NextReviewDate
|
|
}
|
|
if req.Role != nil {
|
|
processingActivity.Role = *req.Role
|
|
}
|
|
if req.DataProtectionOfficerID != nil {
|
|
processingActivity.DataProtectionOfficerID = *req.DataProtectionOfficerID
|
|
}
|
|
|
|
processingActivity.UpdatedAt = time.Now()
|
|
|
|
if err := processingActivity.Update(ctx, conn, s.svc.scope); err != nil {
|
|
return fmt.Errorf("cannot update processing activity: %w", err)
|
|
}
|
|
|
|
if req.ThirdPartyIDs != nil {
|
|
if err := processingActivityThirdParties.Merge(ctx, conn, s.svc.scope, processingActivity.ID, processingActivity.OrganizationID, *req.ThirdPartyIDs); err != nil {
|
|
return fmt.Errorf("cannot update processing activity thirdParties: %w", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return processingActivity, nil
|
|
}
|
|
|
|
func (s ProcessingActivityService) Delete(
|
|
ctx context.Context,
|
|
processingActivityID gid.GID,
|
|
) error {
|
|
processingActivity := coredata.ProcessingActivity{ID: processingActivityID}
|
|
return s.svc.pg.WithTx(
|
|
ctx,
|
|
func(ctx context.Context, tx pg.Tx) error {
|
|
err := processingActivity.Delete(ctx, tx, s.svc.scope)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot delete processing activity: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
)
|
|
}
|
|
|
|
func (s ProcessingActivityService) ListForOrganizationID(
|
|
ctx context.Context,
|
|
organizationID gid.GID,
|
|
cursor *page.Cursor[coredata.ProcessingActivityOrderField],
|
|
) (*page.Page[*coredata.ProcessingActivity, coredata.ProcessingActivityOrderField], error) {
|
|
var processingActivities coredata.ProcessingActivities
|
|
|
|
err := s.svc.pg.WithConn(
|
|
ctx,
|
|
func(ctx context.Context, conn pg.Querier) error {
|
|
err := processingActivities.LoadByOrganizationID(ctx, conn, s.svc.scope, organizationID, cursor)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot load processing activities: %w", err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return page.NewPage(processingActivities, cursor), nil
|
|
}
|
|
|
|
func (s ProcessingActivityService) CountForOrganizationID(
|
|
ctx context.Context,
|
|
organizationID gid.GID,
|
|
) (int, error) {
|
|
var count int
|
|
|
|
err := s.svc.pg.WithConn(
|
|
ctx,
|
|
func(ctx context.Context, conn pg.Querier) (err error) {
|
|
processingActivities := coredata.ProcessingActivities{}
|
|
count, err = processingActivities.CountByOrganizationID(ctx, conn, s.svc.scope, organizationID)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot count processing activities: %w", err)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return count, nil
|
|
}
|