Stop using coredata.People except for people service and people page resolvers

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-02-03 19:22:35 +04:00
parent 70dec6cc7d
commit e156a428d4
36 changed files with 1380 additions and 462 deletions

View File

@@ -34,7 +34,7 @@ type (
SourceID *gid.GID `db:"source_id"`
Name string `db:"name"`
Amount int `db:"amount"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
OrganizationID gid.GID `db:"organization_id"`
AssetType AssetType `db:"asset_type"`
DataTypesStored string `db:"data_types_stored"`

View File

@@ -34,7 +34,7 @@ type (
ReferenceID string `db:"reference_id"`
Description *string `db:"description"`
Source *string `db:"source"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
TargetDate *time.Time `db:"target_date"`
Status ContinualImprovementStatus `db:"status"`
Priority ContinualImprovementPriority `db:"priority"`

View File

@@ -32,7 +32,7 @@ type (
ID gid.GID `db:"id"`
Name string `db:"name"`
OrganizationID gid.GID `db:"organization_id"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
DataClassification DataClassification `db:"data_classification"`
SnapshotID *gid.GID `db:"snapshot_id"`
SourceID *gid.GID `db:"source_id"`

View File

@@ -32,7 +32,7 @@ type (
Document struct {
ID gid.GID `db:"id"`
OrganizationID gid.GID `db:"organization_id"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
Title string `db:"title"`
DocumentType DocumentType `db:"document_type"`
Classification DocumentClassification `db:"classification"`

View File

@@ -34,7 +34,7 @@ type (
OrganizationID gid.GID `db:"organization_id"`
DocumentID gid.GID `db:"document_id"`
Title string `db:"title"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
VersionNumber int `db:"version_number"`
Classification DocumentClassification `db:"classification"`
Content string `db:"content"`

View File

@@ -35,7 +35,7 @@ type (
OrganizationID gid.GID `json:"-"`
DocumentVersionID gid.GID `json:"document_version_id"`
State DocumentVersionSignatureState `json:"state"`
SignedBy gid.GID `json:"signed_by"`
SignedBy gid.GID `json:"signed_by_profile_id"`
SignedAt *time.Time `json:"signed_at"`
RequestedAt time.Time `json:"requested_at"`
CreatedAt time.Time `json:"created_at"`

View File

@@ -31,7 +31,7 @@ const (
ConnectorEntityType uint16 = 5
VendorRiskAssessmentEntityType uint16 = 6
VendorEntityType uint16 = 7
PeopleEntityType uint16 = 8
_ uint16 = 8 // PeopleEntityType - removed
VendorComplianceReportEntityType uint16 = 9
DocumentEntityType uint16 = 10
IdentityEntityType uint16 = 11
@@ -99,8 +99,6 @@ func NewEntityFromID(id gid.GID) (any, bool) {
return &VendorRiskAssessment{ID: id}, true
case VendorEntityType:
return &Vendor{ID: id}, true
case PeopleEntityType:
return &People{ID: id}, true
case VendorComplianceReportEntityType:
return &VendorComplianceReport{ID: id}, true
case DocumentEntityType:

View File

@@ -29,7 +29,7 @@ type (
MeetingAttendee struct {
MeetingID gid.GID `db:"meeting_id"`
OrganizationID gid.GID `db:"organization_id"`
AttendeeID gid.GID `db:"attendee_id"`
AttendeeID gid.GID `db:"attendee_profile_id"`
CreatedAt time.Time `db:"created_at"`
}

View File

@@ -40,6 +40,8 @@ type (
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
MembershipProfiles []*MembershipProfile
)
func (p *MembershipProfile) AuthorizationAttributes(ctx context.Context, conn pg.Conn) (map[string]string, error) {
@@ -156,6 +158,167 @@ LIMIT 1;
return nil
}
func (p *MembershipProfiles) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
profileIDs []gid.GID,
) error {
q := `
SELECT
id,
membership_id,
full_name,
kind,
additionalEmailAddresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
iam_membership_profiles
WHERE
%s
AND id = ANY(@profile_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"profile_ids": profileIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query profiles: %w", err)
}
profiles, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MembershipProfile])
if err != nil {
return fmt.Errorf("cannot collect profiles: %w", err)
}
*p = profiles
return nil
}
func (p *MembershipProfiles) LoadByMeetingID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
meetingID gid.GID,
) error {
q := `
WITH attendees AS (
SELECT
p.id,
p.membership_id,
p.full_name,
p.kind,
p.additionalEmailAddresses,
p.position,
p.contract_start_date,
p.contract_end_date,
p.created_at,
p.updated_at,
ma.created_at AS attendee_created_at
FROM
iam_membership_profiles p
INNER JOIN
meeting_attendees ma ON p.id = ma.attendee_profile_id
WHERE
ma.meeting_id = @meeting_id
)
SELECT
id,
organization_id,
kind,
full_name,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
attendees
WHERE
%s
ORDER BY
attendee_created_at ASC
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"meeting_id": meetingID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query profiles: %w", err)
}
profiles, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MembershipProfile])
if err != nil {
return fmt.Errorf("cannot collect profiles: %w", err)
}
*p = profiles
return nil
}
func (p *MembershipProfiles) LoadAwaitingSigning(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
WITH signatories AS (
SELECT
signed_by
FROM
document_version_signatures
WHERE
%s
AND state = 'REQUESTED'
GROUP BY
signed_by
)
SELECT
id,
organization_id,
kind,
full_name,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
iam_membership_profiles
INNER JOIN signatories ON iam_membership_profiles.id = signatories.signed_by_profile_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
rows, err := conn.Query(ctx, q, scope.SQLArguments())
if err != nil {
return fmt.Errorf("cannot query profiles: %w", err)
}
profiles, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MembershipProfile])
if err != nil {
return fmt.Errorf("cannot collect profiles: %w", err)
}
*p = profiles
return nil
}
func (p *MembershipProfile) Insert(
ctx context.Context,
conn pg.Conn,

View File

@@ -39,7 +39,7 @@ type (
DateIdentified *time.Time `db:"date_identified"`
RootCause string `db:"root_cause"`
CorrectiveAction *string `db:"corrective_action"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
DueDate *time.Time `db:"due_date"`
Status NonconformityStatus `db:"status"`
EffectivenessCheck *string `db:"effectiveness_check"`

View File

@@ -36,7 +36,7 @@ type (
Requirement *string `db:"requirement"`
ActionsToBeImplemented *string `db:"actions_to_be_implemented"`
Regulator *string `db:"regulator"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
LastReviewDate *time.Time `db:"last_review_date"`
DueDate *time.Time `db:"due_date"`
Status ObligationStatus `db:"status"`

View File

@@ -74,108 +74,17 @@ func (p *People) AuthorizationAttributes(ctx context.Context, conn pg.Conn) (map
return map[string]string{"organization_id": organizationID.String()}, nil
}
// FIXME remove: only used in people_service
func (p *People) LoadByID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
peopleID gid.GID,
) error {
q := `
SELECT
id,
organization_id,
kind,
full_name,
primary_email_address,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
peoples
WHERE
%s
AND id = @people_id
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"people_id": peopleID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query people: %w", err)
}
people, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[People])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return ErrResourceNotFound
}
return fmt.Errorf("cannot collect people: %w", err)
}
*p = people
return nil
}
func (p *People) LoadByEmail(
ctx context.Context,
conn pg.Conn,
scope Scoper,
primaryEmailAddress string,
) error {
q := `
SELECT
id,
organization_id,
kind,
full_name,
primary_email_address,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
peoples
WHERE
%s
AND primary_email_address = @primary_email_address
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"primary_email_address": primaryEmailAddress}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query people: %w", err)
}
people, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[People])
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return ErrResourceNotFound
}
return fmt.Errorf("cannot collect people: %w", err)
}
*p = people
return nil
}
// FIXME remove: only used in document_service
func (p *People) LoadByEmailAndOrganizationID(
ctx context.Context,
conn pg.Conn,
@@ -232,52 +141,7 @@ LIMIT 1;
return nil
}
func (p *Peoples) LoadByIDs(
ctx context.Context,
conn pg.Conn,
scope Scoper,
peopleIDs []gid.GID,
) error {
q := `
SELECT
id,
organization_id,
kind,
full_name,
primary_email_address,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
peoples
WHERE
%s
AND id = ANY(@people_ids)
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"people_ids": peopleIDs}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query people: %w", err)
}
peoples, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[People])
if err != nil {
return fmt.Errorf("cannot collect people: %w", err)
}
*p = peoples
return nil
}
// FIXME remove: only used in people_service
func (p People) Insert(
ctx context.Context,
conn pg.Conn,
@@ -333,6 +197,7 @@ VALUES (
return err
}
// FIXME remove: only used in people_service
func (p People) Delete(
ctx context.Context,
conn pg.Conn,
@@ -361,6 +226,7 @@ DELETE FROM peoples WHERE %s AND id = @people_id
return nil
}
// FIXME remove: only used in people_service
func (p *Peoples) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
@@ -396,6 +262,7 @@ WHERE
return count, nil
}
// FIXME remove: only used in people_service
func (p *Peoples) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,
@@ -448,6 +315,7 @@ WHERE
return nil
}
// FIXME remove: only used in people_service
func (p *People) Update(
ctx context.Context,
conn pg.Conn,
@@ -488,123 +356,3 @@ WHERE %s
return nil
}
func (p *Peoples) LoadAwaitingSigning(
ctx context.Context,
conn pg.Conn,
scope Scoper,
) error {
q := `
WITH signatories AS (
SELECT
signed_by
FROM
document_version_signatures
WHERE
%s
AND state = 'REQUESTED'
GROUP BY
signed_by
)
SELECT
id,
organization_id,
kind,
full_name,
primary_email_address,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
peoples
INNER JOIN signatories ON peoples.id = signatories.signed_by
`
q = fmt.Sprintf(q, scope.SQLFragment())
rows, err := conn.Query(ctx, q, scope.SQLArguments())
if err != nil {
return fmt.Errorf("cannot query people: %w", err)
}
peoples, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[People])
if err != nil {
return fmt.Errorf("cannot collect people: %w", err)
}
*p = peoples
return nil
}
func (p *Peoples) LoadByMeetingID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
meetingID gid.GID,
) error {
q := `
WITH people_attendees AS (
SELECT
p.id,
p.organization_id,
p.kind,
p.full_name,
p.primary_email_address,
p.additional_email_addresses,
p.position,
p.contract_start_date,
p.contract_end_date,
p.created_at,
p.updated_at,
p.tenant_id,
ma.created_at AS attendee_created_at
FROM
peoples p
INNER JOIN
meeting_attendees ma ON p.id = ma.attendee_id
WHERE
ma.meeting_id = @meeting_id
)
SELECT
id,
organization_id,
kind,
full_name,
primary_email_address,
additional_email_addresses,
position,
contract_start_date,
contract_end_date,
created_at,
updated_at
FROM
people_attendees
WHERE
%s
ORDER BY
attendee_created_at ASC
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"meeting_id": meetingID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot query people: %w", err)
}
peoples, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[People])
if err != nil {
return fmt.Errorf("cannot collect people: %w", err)
}
*p = peoples
return nil
}

View File

@@ -51,7 +51,7 @@ type (
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"`
DataProtectionOfficerID *gid.GID `db:"dpo_profile_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}

View File

@@ -36,7 +36,7 @@ type (
Category string `db:"category"`
Treatment RiskTreatment `db:"treatment"`
Note string `db:"note"`
OwnerID *gid.GID `db:"owner_id"`
OwnerID *gid.GID `db:"owner_profile_id"`
InherentLikelihood int `db:"inherent_likelihood"`
InherentImpact int `db:"inherent_impact"`
InherentRiskScore int `db:"inherent_risk_score"`

View File

@@ -35,7 +35,7 @@ type (
Name string `db:"name"`
SourceID *gid.GID `db:"source_id"`
SnapshotID *gid.GID `db:"snapshot_id"`
OwnerID gid.GID `db:"owner_id"`
OwnerID gid.GID `db:"owner_profile_id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}

View File

@@ -39,7 +39,7 @@ type (
State TaskState `db:"state"`
ReferenceID string `db:"reference_id"`
TimeEstimate *time.Duration `db:"time_estimate"`
AssignedToID *gid.GID `db:"assigned_to"`
AssignedToID *gid.GID `db:"assigned_to_profile_id"`
Deadline *time.Time `db:"deadline"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`

View File

@@ -45,8 +45,8 @@ type (
SubprocessorsListURL *string `db:"subprocessors_list_url"`
Certifications []string `db:"certifications"`
Countries CountryCodes `db:"countries"`
BusinessOwnerID *gid.GID `db:"business_owner_id"`
SecurityOwnerID *gid.GID `db:"security_owner_id"`
BusinessOwnerID *gid.GID `db:"business_owner_profile_id"`
SecurityOwnerID *gid.GID `db:"security_owner_profile_id"`
StatusPageURL *string `db:"status_page_url"`
TermsOfServiceURL *string `db:"terms_of_service_url"`
SecurityPageURL *string `db:"security_page_url"`