Change registry names

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-12-19 17:25:56 +01:00
parent dccd186eb7
commit cd13f9aa00
42 changed files with 5623 additions and 5610 deletions

View File

@@ -27,48 +27,48 @@ import (
"go.probo.inc/probo/pkg/page"
)
type ErrProcessingActivityDPIANotFound struct {
type ErrDataProtectionImpactAssessmentNotFound struct {
Identifier string
}
func (e ErrProcessingActivityDPIANotFound) Error() string {
return fmt.Sprintf("processing activity dpia not found: %q", e.Identifier)
func (e ErrDataProtectionImpactAssessmentNotFound) Error() string {
return fmt.Sprintf("data protection impact assessment not found: %q", e.Identifier)
}
type (
ProcessingActivityDPIA struct {
ID gid.GID `db:"id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
OrganizationID gid.GID `db:"organization_id"`
ProcessingActivityID gid.GID `db:"processing_activity_id"`
Description *string `db:"description"`
NecessityAndProportionality *string `db:"necessity_and_proportionality"`
PotentialRisk *string `db:"potential_risk"`
Mitigations *string `db:"mitigations"`
ResidualRisk *ProcessingActivityDPIAResidualRisk `db:"residual_risk"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
DataProtectionImpactAssessment struct {
ID gid.GID `db:"id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
OrganizationID gid.GID `db:"organization_id"`
ProcessingActivityID gid.GID `db:"processing_activity_id"`
Description *string `db:"description"`
NecessityAndProportionality *string `db:"necessity_and_proportionality"`
PotentialRisk *string `db:"potential_risk"`
Mitigations *string `db:"mitigations"`
ResidualRisk *DataProtectionImpactAssessmentResidualRisk `db:"residual_risk"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
ProcessingActivityDPIAs []*ProcessingActivityDPIA
DataProtectionImpactAssessments []*DataProtectionImpactAssessment
)
func (dpia *ProcessingActivityDPIA) CursorKey(field ProcessingActivityDPIAOrderField) page.CursorKey {
func (dpia *DataProtectionImpactAssessment) CursorKey(field DataProtectionImpactAssessmentOrderField) page.CursorKey {
switch field {
case ProcessingActivityDPIAOrderFieldCreatedAt:
case DataProtectionImpactAssessmentOrderFieldCreatedAt:
return page.NewCursorKey(dpia.ID, dpia.CreatedAt)
}
panic(fmt.Sprintf("unsupported order by: %s", field))
}
func (dpias *ProcessingActivityDPIAs) CountByOrganizationID(
func (dpias *DataProtectionImpactAssessments) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
filter *ProcessingActivityDPIAFilter,
filter *DataProtectionImpactAssessmentFilter,
) (int, error) {
q := `
SELECT
@@ -92,19 +92,19 @@ WHERE
var count int
err := row.Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot count processing activity dpias: %w", err)
return 0, fmt.Errorf("cannot count data protection impact assessments: %w", err)
}
return count, nil
}
func (dpias *ProcessingActivityDPIAs) LoadByOrganizationID(
func (dpias *DataProtectionImpactAssessments) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
cursor *page.Cursor[ProcessingActivityDPIAOrderField],
filter *ProcessingActivityDPIAFilter,
cursor *page.Cursor[DataProtectionImpactAssessmentOrderField],
filter *DataProtectionImpactAssessmentFilter,
) error {
q := `
SELECT
@@ -138,12 +138,12 @@ WHERE
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity dpias: %w", err)
return fmt.Errorf("cannot query data protection impact assessments: %w", err)
}
results, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ProcessingActivityDPIA])
results, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[DataProtectionImpactAssessment])
if err != nil {
return fmt.Errorf("cannot collect processing activity dpias: %w", err)
return fmt.Errorf("cannot collect data protection impact assessments: %w", err)
}
*dpias = results
@@ -151,7 +151,7 @@ WHERE
return nil
}
func (dpia *ProcessingActivityDPIA) LoadByID(
func (dpia *DataProtectionImpactAssessment) LoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -186,15 +186,15 @@ LIMIT 1;
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity dpia: %w", err)
return fmt.Errorf("cannot query data protection impact assessment: %w", err)
}
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ProcessingActivityDPIA])
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[DataProtectionImpactAssessment])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return &ErrProcessingActivityDPIANotFound{Identifier: dpiaID.String()}
return &ErrDataProtectionImpactAssessmentNotFound{Identifier: dpiaID.String()}
}
return fmt.Errorf("cannot collect processing activity dpia: %w", err)
return fmt.Errorf("cannot collect data protection impact assessment: %w", err)
}
*dpia = result
@@ -202,7 +202,7 @@ LIMIT 1;
return nil
}
func (dpia *ProcessingActivityDPIA) LoadByProcessingActivityID(
func (dpia *DataProtectionImpactAssessment) LoadByProcessingActivityID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -237,15 +237,15 @@ LIMIT 1;
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity dpia: %w", err)
return fmt.Errorf("cannot query data protection impact assessment: %w", err)
}
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ProcessingActivityDPIA])
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[DataProtectionImpactAssessment])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return &ErrProcessingActivityDPIANotFound{Identifier: processingActivityID.String()}
return &ErrDataProtectionImpactAssessmentNotFound{Identifier: processingActivityID.String()}
}
return fmt.Errorf("cannot collect processing activity dpia: %w", err)
return fmt.Errorf("cannot collect data protection impact assessment: %w", err)
}
*dpia = result
@@ -253,7 +253,7 @@ LIMIT 1;
return nil
}
func (dpia *ProcessingActivityDPIA) Insert(
func (dpia *DataProtectionImpactAssessment) Insert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -302,13 +302,13 @@ INSERT INTO processing_activity_data_protection_impact_assessments (
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot insert processing activity dpia: %w", err)
return fmt.Errorf("cannot insert data protection impact assessment: %w", err)
}
return nil
}
func (dpia *ProcessingActivityDPIA) Update(
func (dpia *DataProtectionImpactAssessment) Update(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -341,13 +341,13 @@ WHERE
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot update processing activity dpia: %w", err)
return fmt.Errorf("cannot update data protection impact assessment: %w", err)
}
return nil
}
func (dpia *ProcessingActivityDPIA) Delete(
func (dpia *DataProtectionImpactAssessment) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -366,13 +366,13 @@ WHERE
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot delete processing activity dpia: %w", err)
return fmt.Errorf("cannot delete data protection impact assessment: %w", err)
}
return nil
}
func (dpias ProcessingActivityDPIAs) InsertProcessingActivitySnapshots(
func (dpias DataProtectionImpactAssessments) InsertProcessingActivitySnapshots(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -419,13 +419,14 @@ WHERE dpia.tenant_id = @tenant_id AND dpia.organization_id = @organization_id AN
"tenant_id": scope.GetTenantID(),
"snapshot_id": snapshotID,
"organization_id": organizationID,
"dpia_entity_type": ProcessingActivityDPIAEntityType,
"dpia_entity_type": DataProtectionImpactAssessmentEntityType,
}
_, err := conn.Exec(ctx, query, args)
if err != nil {
return fmt.Errorf("cannot insert processing activity dpia snapshots: %w", err)
return fmt.Errorf("cannot insert data protection impact assessment snapshots: %w", err)
}
return nil
}

View File

@@ -20,18 +20,18 @@ import (
)
type (
ProcessingActivityDPIAFilter struct {
DataProtectionImpactAssessmentFilter struct {
snapshotID **gid.GID
}
)
func NewProcessingActivityDPIAFilter(snapshotID **gid.GID) *ProcessingActivityDPIAFilter {
return &ProcessingActivityDPIAFilter{
func NewDataProtectionImpactAssessmentFilter(snapshotID **gid.GID) *DataProtectionImpactAssessmentFilter {
return &DataProtectionImpactAssessmentFilter{
snapshotID: snapshotID,
}
}
func (f *ProcessingActivityDPIAFilter) SQLArguments() pgx.NamedArgs {
func (f *DataProtectionImpactAssessmentFilter) SQLArguments() pgx.NamedArgs {
args := pgx.NamedArgs{}
if f.snapshotID != nil && *f.snapshotID != nil {
@@ -41,7 +41,7 @@ func (f *ProcessingActivityDPIAFilter) SQLArguments() pgx.NamedArgs {
return args
}
func (f *ProcessingActivityDPIAFilter) SQLFragment() string {
func (f *DataProtectionImpactAssessmentFilter) SQLFragment() string {
if f.snapshotID == nil {
return "TRUE"
}
@@ -52,3 +52,4 @@ func (f *ProcessingActivityDPIAFilter) SQLFragment() string {
return "snapshot_id = @filter_snapshot_id"
}
}

View File

@@ -16,30 +16,31 @@ package coredata
import "fmt"
type ProcessingActivityTIAOrderField string
type DataProtectionImpactAssessmentOrderField string
const (
ProcessingActivityTIAOrderFieldCreatedAt ProcessingActivityTIAOrderField = "CREATED_AT"
DataProtectionImpactAssessmentOrderFieldCreatedAt DataProtectionImpactAssessmentOrderField = "CREATED_AT"
)
func (p ProcessingActivityTIAOrderField) Column() string {
func (p DataProtectionImpactAssessmentOrderField) Column() string {
return string(p)
}
func (p ProcessingActivityTIAOrderField) String() string {
func (p DataProtectionImpactAssessmentOrderField) String() string {
return string(p)
}
func (p ProcessingActivityTIAOrderField) MarshalText() ([]byte, error) {
func (p DataProtectionImpactAssessmentOrderField) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *ProcessingActivityTIAOrderField) UnmarshalText(text []byte) error {
func (p *DataProtectionImpactAssessmentOrderField) UnmarshalText(text []byte) error {
val := string(text)
switch val {
case string(ProcessingActivityTIAOrderFieldCreatedAt):
*p = ProcessingActivityTIAOrderFieldCreatedAt
case string(DataProtectionImpactAssessmentOrderFieldCreatedAt):
*p = DataProtectionImpactAssessmentOrderFieldCreatedAt
return nil
}
return fmt.Errorf("invalid ProcessingActivityTIAOrderField value: %q", val)
return fmt.Errorf("invalid DataProtectionImpactAssessmentOrderField value: %q", val)
}

View File

@@ -0,0 +1,69 @@
// 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 coredata
import (
"database/sql/driver"
"fmt"
)
type DataProtectionImpactAssessmentResidualRisk string
const (
DataProtectionImpactAssessmentResidualRiskLow DataProtectionImpactAssessmentResidualRisk = "LOW"
DataProtectionImpactAssessmentResidualRiskMedium DataProtectionImpactAssessmentResidualRisk = "MEDIUM"
DataProtectionImpactAssessmentResidualRiskHigh DataProtectionImpactAssessmentResidualRisk = "HIGH"
)
func DataProtectionImpactAssessmentResidualRisks() []DataProtectionImpactAssessmentResidualRisk {
return []DataProtectionImpactAssessmentResidualRisk{
DataProtectionImpactAssessmentResidualRiskLow,
DataProtectionImpactAssessmentResidualRiskMedium,
DataProtectionImpactAssessmentResidualRiskHigh,
}
}
func (p DataProtectionImpactAssessmentResidualRisk) String() string {
return string(p)
}
func (p *DataProtectionImpactAssessmentResidualRisk) Scan(value any) error {
var s string
switch v := value.(type) {
case string:
s = v
case []byte:
s = string(v)
default:
return fmt.Errorf("unsupported type for DataProtectionImpactAssessmentResidualRisk: %T", value)
}
switch s {
case "LOW":
*p = DataProtectionImpactAssessmentResidualRiskLow
case "MEDIUM":
*p = DataProtectionImpactAssessmentResidualRiskMedium
case "HIGH":
*p = DataProtectionImpactAssessmentResidualRiskHigh
default:
return fmt.Errorf("invalid DataProtectionImpactAssessmentResidualRisk value: %q", s)
}
return nil
}
func (p DataProtectionImpactAssessmentResidualRisk) Value() (driver.Value, error) {
return p.String(), nil
}

View File

@@ -67,8 +67,8 @@ const (
UserAPIKeyEntityType uint16 = 43
UserAPIKeyMembershipEntityType uint16 = 44
MeetingEntityType uint16 = 45
ProcessingActivityDPIAEntityType uint16 = 46
ProcessingActivityTIAEntityType uint16 = 47
DataProtectionImpactAssessmentEntityType uint16 = 46
TransferImpactAssessmentEntityType uint16 = 47
)
type EntityInfo struct {
@@ -261,12 +261,12 @@ var entityRegistry = map[uint16]EntityInfo{
Model: "Meeting",
Table: "meetings",
},
ProcessingActivityDPIAEntityType: {
Model: "ProcessingActivityDPIA",
DataProtectionImpactAssessmentEntityType: {
Model: "DataProtectionImpactAssessment",
Table: "processing_activity_data_protection_impact_assessments",
},
ProcessingActivityTIAEntityType: {
Model: "ProcessingActivityTIA",
TransferImpactAssessmentEntityType: {
Model: "TransferImpactAssessment",
Table: "processing_activity_transfer_impact_assessments",
},
}

View File

@@ -2,13 +2,16 @@ ALTER TABLE processing_activities ADD COLUMN last_review_date DATE;
ALTER TABLE processing_activities ADD COLUMN next_review_date DATE;
CREATE TYPE processing_activity_role AS ENUM ('CONTROLLER', 'PROCESSOR');
ALTER TABLE processing_activities ADD COLUMN IF NOT EXISTS role processing_activity_role NOT NULL DEFAULT 'PROCESSOR';
ALTER TABLE processing_activities ADD COLUMN role processing_activity_role NOT NULL DEFAULT 'PROCESSOR';
ALTER TABLE processing_activities ALTER COLUMN role DROP DEFAULT;
ALTER TABLE processing_activities ADD COLUMN IF NOT EXISTS data_protection_officer_id TEXT REFERENCES peoples(id) ON DELETE RESTRICT;
ALTER TABLE processing_activities ADD COLUMN data_protection_officer_id TEXT REFERENCES peoples(id) ON DELETE RESTRICT;
CREATE TYPE processing_activity_dpia_residual_risk AS ENUM ('LOW', 'MEDIUM', 'HIGH');
ALTER TABLE processing_activities RENAME COLUMN data_protection_impact_assessment TO data_protection_impact_assessment_needed;
ALTER TABLE processing_activities RENAME COLUMN transfer_impact_assessment TO transfer_impact_assessment_needed;
CREATE TABLE processing_activity_data_protection_impact_assessments (
id TEXT PRIMARY KEY,
tenant_id TEXT NOT NULL,

View File

@@ -28,31 +28,31 @@ import (
type (
ProcessingActivity struct {
ID gid.GID `db:"id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
OrganizationID gid.GID `db:"organization_id"`
Name string `db:"name"`
Purpose *string `db:"purpose"`
DataSubjectCategory *string `db:"data_subject_category"`
PersonalDataCategory *string `db:"personal_data_category"`
SpecialOrCriminalData ProcessingActivitySpecialOrCriminalDatum `db:"special_or_criminal_data"`
ConsentEvidenceLink *string `db:"consent_evidence_link"`
LawfulBasis ProcessingActivityLawfulBasis `db:"lawful_basis"`
Recipients *string `db:"recipients"`
Location *string `db:"location"`
InternationalTransfers bool `db:"international_transfers"`
TransferSafeguard *ProcessingActivityTransferSafeguard `db:"transfer_safeguards"`
RetentionPeriod *string `db:"retention_period"`
SecurityMeasures *string `db:"security_measures"`
DataProtectionImpactAssessment ProcessingActivityDataProtectionImpactAssessment `db:"data_protection_impact_assessment"`
TransferImpactAssessment ProcessingActivityTransferImpactAssessment `db:"transfer_impact_assessment"`
LastReviewDate *time.Time `db:"last_review_date"`
NextReviewDate *time.Time `db:"next_review_date"`
Role ProcessingActivityRole `db:"role"`
DataProtectionOfficerID *gid.GID `db:"data_protection_officer_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID gid.GID `db:"id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
OrganizationID gid.GID `db:"organization_id"`
Name string `db:"name"`
Purpose *string `db:"purpose"`
DataSubjectCategory *string `db:"data_subject_category"`
PersonalDataCategory *string `db:"personal_data_category"`
SpecialOrCriminalData ProcessingActivitySpecialOrCriminalDatum `db:"special_or_criminal_data"`
ConsentEvidenceLink *string `db:"consent_evidence_link"`
LawfulBasis ProcessingActivityLawfulBasis `db:"lawful_basis"`
Recipients *string `db:"recipients"`
Location *string `db:"location"`
InternationalTransfers bool `db:"international_transfers"`
TransferSafeguard *ProcessingActivityTransferSafeguard `db:"transfer_safeguards"`
RetentionPeriod *string `db:"retention_period"`
SecurityMeasures *string `db:"security_measures"`
DataProtectionImpactAssessmentNeeded ProcessingActivityDataProtectionImpactAssessment `db:"data_protection_impact_assessment_needed"`
TransferImpactAssessmentNeeded ProcessingActivityTransferImpactAssessment `db:"transfer_impact_assessment_needed"`
LastReviewDate *time.Time `db:"last_review_date"`
NextReviewDate *time.Time `db:"next_review_date"`
Role ProcessingActivityRole `db:"role"`
DataProtectionOfficerID *gid.GID `db:"data_protection_officer_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
ProcessingActivities []*ProcessingActivity
@@ -94,8 +94,8 @@ SELECT
transfer_safeguards,
retention_period,
security_measures,
data_protection_impact_assessment,
transfer_impact_assessment,
data_protection_impact_assessment_needed,
transfer_impact_assessment_needed,
last_review_date,
next_review_date,
role,
@@ -192,8 +192,8 @@ SELECT
transfer_safeguards,
retention_period,
security_measures,
data_protection_impact_assessment,
transfer_impact_assessment,
data_protection_impact_assessment_needed,
transfer_impact_assessment_needed,
last_review_date,
next_review_date,
role,
@@ -256,8 +256,8 @@ INSERT INTO processing_activities (
transfer_safeguards,
retention_period,
security_measures,
data_protection_impact_assessment,
transfer_impact_assessment,
data_protection_impact_assessment_needed,
transfer_impact_assessment_needed,
last_review_date,
next_review_date,
role,
@@ -283,8 +283,8 @@ INSERT INTO processing_activities (
@transfer_safeguards,
@retention_period,
@security_measures,
@data_protection_impact_assessment,
@transfer_impact_assessment,
@data_protection_impact_assessment_needed,
@transfer_impact_assessment_needed,
@last_review_date,
@next_review_date,
@role,
@@ -295,32 +295,32 @@ INSERT INTO processing_activities (
`
args := pgx.StrictNamedArgs{
"id": p.ID,
"tenant_id": scope.GetTenantID(),
"snapshot_id": p.SnapshotID,
"source_id": p.SourceID,
"organization_id": p.OrganizationID,
"name": p.Name,
"purpose": p.Purpose,
"data_subject_category": p.DataSubjectCategory,
"personal_data_category": p.PersonalDataCategory,
"special_or_criminal_data": p.SpecialOrCriminalData,
"consent_evidence_link": p.ConsentEvidenceLink,
"lawful_basis": p.LawfulBasis,
"recipients": p.Recipients,
"location": p.Location,
"international_transfers": p.InternationalTransfers,
"transfer_safeguards": p.TransferSafeguard,
"retention_period": p.RetentionPeriod,
"security_measures": p.SecurityMeasures,
"data_protection_impact_assessment": p.DataProtectionImpactAssessment,
"transfer_impact_assessment": p.TransferImpactAssessment,
"last_review_date": p.LastReviewDate,
"next_review_date": p.NextReviewDate,
"role": p.Role,
"data_protection_officer_id": p.DataProtectionOfficerID,
"created_at": p.CreatedAt,
"updated_at": p.UpdatedAt,
"id": p.ID,
"tenant_id": scope.GetTenantID(),
"snapshot_id": p.SnapshotID,
"source_id": p.SourceID,
"organization_id": p.OrganizationID,
"name": p.Name,
"purpose": p.Purpose,
"data_subject_category": p.DataSubjectCategory,
"personal_data_category": p.PersonalDataCategory,
"special_or_criminal_data": p.SpecialOrCriminalData,
"consent_evidence_link": p.ConsentEvidenceLink,
"lawful_basis": p.LawfulBasis,
"recipients": p.Recipients,
"location": p.Location,
"international_transfers": p.InternationalTransfers,
"transfer_safeguards": p.TransferSafeguard,
"retention_period": p.RetentionPeriod,
"security_measures": p.SecurityMeasures,
"data_protection_impact_assessment_needed": p.DataProtectionImpactAssessmentNeeded,
"transfer_impact_assessment_needed": p.TransferImpactAssessmentNeeded,
"last_review_date": p.LastReviewDate,
"next_review_date": p.NextReviewDate,
"role": p.Role,
"data_protection_officer_id": p.DataProtectionOfficerID,
"created_at": p.CreatedAt,
"updated_at": p.UpdatedAt,
}
_, err := conn.Exec(ctx, q, args)
@@ -352,8 +352,8 @@ SET
transfer_safeguards = @transfer_safeguards,
retention_period = @retention_period,
security_measures = @security_measures,
data_protection_impact_assessment = @data_protection_impact_assessment,
transfer_impact_assessment = @transfer_impact_assessment,
data_protection_impact_assessment_needed = @data_protection_impact_assessment_needed,
transfer_impact_assessment_needed = @transfer_impact_assessment_needed,
last_review_date = @last_review_date,
next_review_date = @next_review_date,
role = @role,
@@ -368,27 +368,27 @@ WHERE
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{
"id": p.ID,
"name": p.Name,
"purpose": p.Purpose,
"data_subject_category": p.DataSubjectCategory,
"personal_data_category": p.PersonalDataCategory,
"special_or_criminal_data": p.SpecialOrCriminalData,
"consent_evidence_link": p.ConsentEvidenceLink,
"lawful_basis": p.LawfulBasis,
"recipients": p.Recipients,
"location": p.Location,
"international_transfers": p.InternationalTransfers,
"transfer_safeguards": p.TransferSafeguard,
"retention_period": p.RetentionPeriod,
"security_measures": p.SecurityMeasures,
"data_protection_impact_assessment": p.DataProtectionImpactAssessment,
"transfer_impact_assessment": p.TransferImpactAssessment,
"last_review_date": p.LastReviewDate,
"next_review_date": p.NextReviewDate,
"role": p.Role,
"data_protection_officer_id": p.DataProtectionOfficerID,
"updated_at": p.UpdatedAt,
"id": p.ID,
"name": p.Name,
"purpose": p.Purpose,
"data_subject_category": p.DataSubjectCategory,
"personal_data_category": p.PersonalDataCategory,
"special_or_criminal_data": p.SpecialOrCriminalData,
"consent_evidence_link": p.ConsentEvidenceLink,
"lawful_basis": p.LawfulBasis,
"recipients": p.Recipients,
"location": p.Location,
"international_transfers": p.InternationalTransfers,
"transfer_safeguards": p.TransferSafeguard,
"retention_period": p.RetentionPeriod,
"security_measures": p.SecurityMeasures,
"data_protection_impact_assessment_needed": p.DataProtectionImpactAssessmentNeeded,
"transfer_impact_assessment_needed": p.TransferImpactAssessmentNeeded,
"last_review_date": p.LastReviewDate,
"next_review_date": p.NextReviewDate,
"role": p.Role,
"data_protection_officer_id": p.DataProtectionOfficerID,
"updated_at": p.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
@@ -427,7 +427,7 @@ WHERE
}
func (pas ProcessingActivities) Snapshot(ctx context.Context, conn pg.Conn, scope Scoper, organizationID, snapshotID gid.GID) error {
snapshotters := []ProcessingActivitySnapshotter{ProcessingActivities{}, Vendors{}, ProcessingActivityVendors{}, ProcessingActivityDPIAs{}, ProcessingActivityTIAs{}}
snapshotters := []ProcessingActivitySnapshotter{ProcessingActivities{}, Vendors{}, ProcessingActivityVendors{}, DataProtectionImpactAssessments{}, TransferImpactAssessments{}}
for _, snapshotter := range snapshotters {
if err := snapshotter.InsertProcessingActivitySnapshots(ctx, conn, scope, organizationID, snapshotID); err != nil {
@@ -465,8 +465,8 @@ INSERT INTO processing_activities (
transfer_safeguards,
retention_period,
security_measures,
data_protection_impact_assessment,
transfer_impact_assessment,
data_protection_impact_assessment_needed,
transfer_impact_assessment_needed,
last_review_date,
next_review_date,
role,
@@ -493,8 +493,8 @@ SELECT
par.transfer_safeguards,
par.retention_period,
par.security_measures,
par.data_protection_impact_assessment,
par.transfer_impact_assessment,
par.data_protection_impact_assessment_needed,
par.transfer_impact_assessment_needed,
par.last_review_date,
par.next_review_date,
par.role,

View File

@@ -1,68 +0,0 @@
// 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 coredata
import (
"database/sql/driver"
"fmt"
)
type ProcessingActivityDPIAResidualRisk string
const (
ProcessingActivityDPIAResidualRiskLow ProcessingActivityDPIAResidualRisk = "LOW"
ProcessingActivityDPIAResidualRiskMedium ProcessingActivityDPIAResidualRisk = "MEDIUM"
ProcessingActivityDPIAResidualRiskHigh ProcessingActivityDPIAResidualRisk = "HIGH"
)
func ProcessingActivityDPIAResidualRisks() []ProcessingActivityDPIAResidualRisk {
return []ProcessingActivityDPIAResidualRisk{
ProcessingActivityDPIAResidualRiskLow,
ProcessingActivityDPIAResidualRiskMedium,
ProcessingActivityDPIAResidualRiskHigh,
}
}
func (p ProcessingActivityDPIAResidualRisk) String() string {
return string(p)
}
func (p *ProcessingActivityDPIAResidualRisk) Scan(value any) error {
var s string
switch v := value.(type) {
case string:
s = v
case []byte:
s = string(v)
default:
return fmt.Errorf("unsupported type for ProcessingActivityDPIAResidualRisk: %T", value)
}
switch s {
case "LOW":
*p = ProcessingActivityDPIAResidualRiskLow
case "MEDIUM":
*p = ProcessingActivityDPIAResidualRiskMedium
case "HIGH":
*p = ProcessingActivityDPIAResidualRiskHigh
default:
return fmt.Errorf("invalid ProcessingActivityDPIAResidualRisk value: %q", s)
}
return nil
}
func (p ProcessingActivityDPIAResidualRisk) Value() (driver.Value, error) {
return p.String(), nil
}

View File

@@ -27,16 +27,16 @@ import (
"go.probo.inc/probo/pkg/page"
)
type ErrProcessingActivityTIANotFound struct {
type ErrTransferImpactAssessmentNotFound struct {
Identifier string
}
func (e ErrProcessingActivityTIANotFound) Error() string {
return fmt.Sprintf("processing activity tia not found: %q", e.Identifier)
func (e ErrTransferImpactAssessmentNotFound) Error() string {
return fmt.Sprintf("transfer impact assessment not found: %q", e.Identifier)
}
type (
ProcessingActivityTIA struct {
TransferImpactAssessment struct {
ID gid.GID `db:"id"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`
@@ -51,24 +51,24 @@ type (
UpdatedAt time.Time `db:"updated_at"`
}
ProcessingActivityTIAs []*ProcessingActivityTIA
TransferImpactAssessments []*TransferImpactAssessment
)
func (tia *ProcessingActivityTIA) CursorKey(field ProcessingActivityTIAOrderField) page.CursorKey {
func (tia *TransferImpactAssessment) CursorKey(field TransferImpactAssessmentOrderField) page.CursorKey {
switch field {
case ProcessingActivityTIAOrderFieldCreatedAt:
case TransferImpactAssessmentOrderFieldCreatedAt:
return page.NewCursorKey(tia.ID, tia.CreatedAt)
}
panic(fmt.Sprintf("unsupported order by: %s", field))
}
func (tias *ProcessingActivityTIAs) CountByOrganizationID(
func (tias *TransferImpactAssessments) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
filter *ProcessingActivityTIAFilter,
filter *TransferImpactAssessmentFilter,
) (int, error) {
q := `
SELECT
@@ -92,19 +92,19 @@ WHERE
var count int
err := row.Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot count processing activity tias: %w", err)
return 0, fmt.Errorf("cannot count transfer impact assessments: %w", err)
}
return count, nil
}
func (tias *ProcessingActivityTIAs) LoadByOrganizationID(
func (tias *TransferImpactAssessments) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
cursor *page.Cursor[ProcessingActivityTIAOrderField],
filter *ProcessingActivityTIAFilter,
cursor *page.Cursor[TransferImpactAssessmentOrderField],
filter *TransferImpactAssessmentFilter,
) error {
q := `
SELECT
@@ -138,12 +138,12 @@ WHERE
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity tias: %w", err)
return fmt.Errorf("cannot query transfer impact assessments: %w", err)
}
results, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[ProcessingActivityTIA])
results, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[TransferImpactAssessment])
if err != nil {
return fmt.Errorf("cannot collect processing activity tias: %w", err)
return fmt.Errorf("cannot collect transfer impact assessments: %w", err)
}
*tias = results
@@ -151,7 +151,7 @@ WHERE
return nil
}
func (tia *ProcessingActivityTIA) LoadByID(
func (tia *TransferImpactAssessment) LoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -186,15 +186,15 @@ LIMIT 1;
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity tia: %w", err)
return fmt.Errorf("cannot query transfer impact assessment: %w", err)
}
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ProcessingActivityTIA])
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TransferImpactAssessment])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return &ErrProcessingActivityTIANotFound{Identifier: tiaID.String()}
return &ErrTransferImpactAssessmentNotFound{Identifier: tiaID.String()}
}
return fmt.Errorf("cannot collect processing activity tia: %w", err)
return fmt.Errorf("cannot collect transfer impact assessment: %w", err)
}
*tia = result
@@ -202,7 +202,7 @@ LIMIT 1;
return nil
}
func (tia *ProcessingActivityTIA) LoadByProcessingActivityID(
func (tia *TransferImpactAssessment) LoadByProcessingActivityID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -237,15 +237,15 @@ LIMIT 1;
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query processing activity tia: %w", err)
return fmt.Errorf("cannot query transfer impact assessment: %w", err)
}
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[ProcessingActivityTIA])
result, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[TransferImpactAssessment])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return &ErrProcessingActivityTIANotFound{Identifier: processingActivityID.String()}
return &ErrTransferImpactAssessmentNotFound{Identifier: processingActivityID.String()}
}
return fmt.Errorf("cannot collect processing activity tia: %w", err)
return fmt.Errorf("cannot collect transfer impact assessment: %w", err)
}
*tia = result
@@ -253,7 +253,7 @@ LIMIT 1;
return nil
}
func (tia *ProcessingActivityTIA) Insert(
func (tia *TransferImpactAssessment) Insert(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -302,13 +302,13 @@ INSERT INTO processing_activity_transfer_impact_assessments (
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot insert processing activity tia: %w", err)
return fmt.Errorf("cannot insert transfer impact assessment: %w", err)
}
return nil
}
func (tia *ProcessingActivityTIA) Update(
func (tia *TransferImpactAssessment) Update(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -341,13 +341,13 @@ WHERE
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot update processing activity tia: %w", err)
return fmt.Errorf("cannot update transfer impact assessment: %w", err)
}
return nil
}
func (tia *ProcessingActivityTIA) Delete(
func (tia *TransferImpactAssessment) Delete(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -366,13 +366,13 @@ WHERE
_, err := conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot delete processing activity tia: %w", err)
return fmt.Errorf("cannot delete transfer impact assessment: %w", err)
}
return nil
}
func (tias ProcessingActivityTIAs) InsertProcessingActivitySnapshots(
func (tias TransferImpactAssessments) InsertProcessingActivitySnapshots(
ctx context.Context,
conn pg.Conn,
scope Scoper,
@@ -419,13 +419,14 @@ WHERE tia.tenant_id = @tenant_id AND tia.organization_id = @organization_id AND
"tenant_id": scope.GetTenantID(),
"snapshot_id": snapshotID,
"organization_id": organizationID,
"tia_entity_type": ProcessingActivityTIAEntityType,
"tia_entity_type": TransferImpactAssessmentEntityType,
}
_, err := conn.Exec(ctx, query, args)
if err != nil {
return fmt.Errorf("cannot insert processing activity tia snapshots: %w", err)
return fmt.Errorf("cannot insert transfer impact assessment snapshots: %w", err)
}
return nil
}

View File

@@ -20,18 +20,18 @@ import (
)
type (
ProcessingActivityTIAFilter struct {
TransferImpactAssessmentFilter struct {
snapshotID **gid.GID
}
)
func NewProcessingActivityTIAFilter(snapshotID **gid.GID) *ProcessingActivityTIAFilter {
return &ProcessingActivityTIAFilter{
func NewTransferImpactAssessmentFilter(snapshotID **gid.GID) *TransferImpactAssessmentFilter {
return &TransferImpactAssessmentFilter{
snapshotID: snapshotID,
}
}
func (f *ProcessingActivityTIAFilter) SQLArguments() pgx.NamedArgs {
func (f *TransferImpactAssessmentFilter) SQLArguments() pgx.NamedArgs {
args := pgx.NamedArgs{}
if f.snapshotID != nil && *f.snapshotID != nil {
@@ -41,7 +41,7 @@ func (f *ProcessingActivityTIAFilter) SQLArguments() pgx.NamedArgs {
return args
}
func (f *ProcessingActivityTIAFilter) SQLFragment() string {
func (f *TransferImpactAssessmentFilter) SQLFragment() string {
if f.snapshotID == nil {
return "TRUE"
}
@@ -52,3 +52,4 @@ func (f *ProcessingActivityTIAFilter) SQLFragment() string {
return "snapshot_id = @filter_snapshot_id"
}
}

View File

@@ -16,30 +16,31 @@ package coredata
import "fmt"
type ProcessingActivityDPIAOrderField string
type TransferImpactAssessmentOrderField string
const (
ProcessingActivityDPIAOrderFieldCreatedAt ProcessingActivityDPIAOrderField = "CREATED_AT"
TransferImpactAssessmentOrderFieldCreatedAt TransferImpactAssessmentOrderField = "CREATED_AT"
)
func (p ProcessingActivityDPIAOrderField) Column() string {
func (p TransferImpactAssessmentOrderField) Column() string {
return string(p)
}
func (p ProcessingActivityDPIAOrderField) String() string {
func (p TransferImpactAssessmentOrderField) String() string {
return string(p)
}
func (p ProcessingActivityDPIAOrderField) MarshalText() ([]byte, error) {
func (p TransferImpactAssessmentOrderField) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *ProcessingActivityDPIAOrderField) UnmarshalText(text []byte) error {
func (p *TransferImpactAssessmentOrderField) UnmarshalText(text []byte) error {
val := string(text)
switch val {
case string(ProcessingActivityDPIAOrderFieldCreatedAt):
*p = ProcessingActivityDPIAOrderFieldCreatedAt
case string(TransferImpactAssessmentOrderFieldCreatedAt):
*p = TransferImpactAssessmentOrderFieldCreatedAt
return nil
}
return fmt.Errorf("invalid ProcessingActivityDPIAOrderField value: %q", val)
return fmt.Errorf("invalid TransferImpactAssessmentOrderField value: %q", val)
}