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"`

View File

@@ -42,7 +42,7 @@ func (car *CreateAssetRequest) Validate() error {
v.Check(car.OrganizationID, "organization_id", validator.Required(), validator.GID(coredata.OrganizationEntityType))
v.Check(car.Name, "name", validator.Required(), validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(car.Amount, "amount", validator.Required(), validator.Min(1))
v.Check(car.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(car.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.Check(car.AssetType, "asset_type", validator.Required(), validator.OneOfSlice(coredata.AssetTypes()))
v.Check(car.DataTypesStored, "data_types_stored", validator.Required(), validator.SafeText(ContentMaxLength))
v.CheckEach(car.VendorIDs, "vendor_ids", func(index int, item any) {
@@ -58,7 +58,7 @@ func (uar *UpdateAssetRequest) Validate() error {
v.Check(uar.ID, "id", validator.Required(), validator.GID(coredata.AssetEntityType))
v.Check(uar.Name, "name", validator.SafeTextNoNewLine(NameMaxLength))
v.Check(uar.Amount, "amount", validator.Min(1))
v.Check(uar.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(uar.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(uar.AssetType, "asset_type", validator.OneOfSlice(coredata.AssetTypes()))
v.Check(uar.DataTypesStored, "data_types_stored", validator.SafeText(ContentMaxLength))
v.CheckEach(uar.VendorIDs, "vendor_ids", func(index int, item any) {
@@ -189,9 +189,9 @@ func (s AssetService) Update(
asset.Amount = *req.Amount
}
if req.OwnerID != nil {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
profile := &coredata.MembershipProfile{}
if err := profile.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
asset.OwnerID = *req.OwnerID
}
@@ -247,9 +247,9 @@ func (s AssetService) Create(
}
err := s.svc.pg.WithTx(ctx, func(conn pg.Conn) error {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
profile := &coredata.MembershipProfile{}
if err := profile.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
if err := asset.Insert(ctx, conn, s.svc.scope); err != nil {

View File

@@ -61,7 +61,7 @@ func (ccir *CreateContinualImprovementRequest) Validate() error {
v.Check(ccir.ReferenceID, "reference_id", validator.SafeText(NameMaxLength))
v.Check(ccir.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(ccir.Source, "source", validator.SafeText(ContentMaxLength))
v.Check(ccir.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(ccir.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.Check(ccir.Status, "status", validator.OneOfSlice(coredata.ContinualImprovementStatuses()))
v.Check(ccir.Priority, "priority", validator.OneOfSlice(coredata.ContinualImprovementPriorities()))
@@ -75,7 +75,7 @@ func (ucir *UpdateContinualImprovementRequest) Validate() error {
v.Check(ucir.ReferenceID, "reference_id", validator.SafeText(NameMaxLength))
v.Check(ucir.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(ucir.Source, "source", validator.SafeText(ContentMaxLength))
v.Check(ucir.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(ucir.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(ucir.Status, "status", validator.OneOfSlice(coredata.ContinualImprovementStatuses()))
v.Check(ucir.Priority, "priority", validator.OneOfSlice(coredata.ContinualImprovementPriorities()))
@@ -138,9 +138,9 @@ func (s *ContinualImprovementService) Create(
return fmt.Errorf("cannot load organization: %w", err)
}
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
return fmt.Errorf("cannot load owner profile: %w", err)
}
if err := improvement.Insert(ctx, conn, s.svc.scope); err != nil {
@@ -184,9 +184,9 @@ func (s *ContinualImprovementService) Update(
}
if req.OwnerID != nil {
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
return fmt.Errorf("cannot load owner profile: %w", err)
}
improvement.OwnerID = *req.OwnerID
}

View File

@@ -54,7 +54,7 @@ func (cdr *CreateDatumRequest) Validate() error {
v.Check(cdr.OrganizationID, "organization_id", validator.Required(), validator.GID(coredata.OrganizationEntityType))
v.Check(cdr.Name, "name", validator.SafeTextNoNewLine(NameMaxLength))
v.Check(cdr.DataClassification, "data_classification", validator.Required(), validator.OneOfSlice(coredata.DataClassifications()))
v.Check(cdr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(cdr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.CheckEach(cdr.VendorIDs, "vendor_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("vendor_ids[%d]", index), validator.Required(), validator.GID(coredata.VendorEntityType))
})
@@ -68,7 +68,7 @@ func (udr *UpdateDatumRequest) Validate() error {
v.Check(udr.ID, "id", validator.Required(), validator.GID(coredata.DatumEntityType))
v.Check(udr.Name, "name", validator.SafeTextNoNewLine(NameMaxLength))
v.Check(udr.DataClassification, "data_classification", validator.OneOfSlice(coredata.DataClassifications()))
v.Check(udr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(udr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.CheckEach(udr.VendorIDs, "vendor_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("vendor_ids[%d]", index), validator.Required(), validator.GID(coredata.VendorEntityType))
})
@@ -196,9 +196,9 @@ func (s DatumService) Update(
datum.DataClassification = *req.DataClassification
}
if req.OwnerID != nil {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
datum.OwnerID = *req.OwnerID
}
@@ -249,9 +249,9 @@ func (s DatumService) Create(
err := s.svc.pg.WithTx(
ctx,
func(conn pg.Conn) error {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
if err := datum.Insert(ctx, conn, s.svc.scope); err != nil {

View File

@@ -102,7 +102,7 @@ func (cdr *CreateDocumentRequest) Validate() error {
v.Check(cdr.OrganizationID, "organization_id", validator.Required(), validator.GID(coredata.OrganizationEntityType))
v.Check(cdr.Title, "title", validator.Required(), validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(cdr.Content, "content", validator.Required(), validator.NotEmpty(), validator.MaxLen(documentMaxLength))
v.Check(cdr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(cdr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.Check(cdr.Classification, "classification", validator.Required(), validator.OneOfSlice(coredata.DocumentClassifications()))
v.Check(cdr.DocumentType, "document_type", validator.Required(), validator.OneOfSlice(coredata.DocumentTypes()))
v.Check(cdr.TrustCenterVisibility, "trust_center_visibility", validator.OneOfSlice(coredata.TrustCenterVisibilities()))
@@ -115,7 +115,7 @@ func (udr *UpdateDocumentRequest) Validate() error {
v.Check(udr.DocumentID, "document_id", validator.Required(), validator.GID(coredata.DocumentEntityType))
v.Check(udr.Title, "title", validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(udr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(udr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(udr.Classification, "classification", validator.OneOfSlice(coredata.DocumentClassifications()))
v.Check(udr.DocumentType, "document_type", validator.OneOfSlice(coredata.DocumentTypes()))
v.Check(udr.TrustCenterVisibility, "trust_center_visibility", validator.OneOfSlice(coredata.TrustCenterVisibilities()))
@@ -395,7 +395,7 @@ func (s *DocumentService) Create(
documentVersionID := gid.New(s.svc.scope.GetTenantID(), coredata.DocumentVersionEntityType)
organization := &coredata.Organization{}
people := &coredata.People{}
owner := &coredata.MembershipProfile{}
document := &coredata.Document{
ID: documentID,
@@ -431,12 +431,12 @@ func (s *DocumentService) Create(
return fmt.Errorf("cannot load organization: %w", err)
}
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load people: %w", err)
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
document.OrganizationID = organization.ID
document.OwnerID = people.ID
document.OwnerID = owner.ID
if err := document.Insert(ctx, conn, s.svc.scope); err != nil {
return fmt.Errorf("cannot insert document: %w", err)
@@ -519,9 +519,9 @@ func (s *DocumentService) SendSigningNotifications(
err := s.svc.pg.WithTx(
ctx,
func(tx pg.Conn) error {
var peoples coredata.Peoples
if err := peoples.LoadAwaitingSigning(ctx, tx, s.svc.scope); err != nil {
return fmt.Errorf("cannot load people: %w", err)
var signatories coredata.MembershipProfiles
if err := signatories.LoadAwaitingSigning(ctx, tx, s.svc.scope); err != nil {
return fmt.Errorf("cannot load signatories: %w", err)
}
organization := &coredata.Organization{}
@@ -529,21 +529,21 @@ func (s *DocumentService) SendSigningNotifications(
return fmt.Errorf("cannot load organization: %w", err)
}
for _, people := range peoples {
for _, signatory := range signatories {
token, err := statelesstoken.NewToken(
s.svc.tokenSecret,
TokenTypeSigningRequest,
time.Hour*24*30,
SigningRequestData{
OrganizationID: organizationID,
PeopleID: people.ID,
PeopleID: signatory.ID,
},
)
if err != nil {
return fmt.Errorf("cannot create signing request token: %w", err)
}
emailPresenter := emails.NewPresenter(s.svc.fileManager, s.svc.bucket, s.svc.baseURL, people.FullName)
emailPresenter := emails.NewPresenter(s.svc.fileManager, s.svc.bucket, s.svc.baseURL, signatory.FullName)
subject, textBody, htmlBody, err := emailPresenter.RenderDocumentSigning(
ctx,
@@ -556,8 +556,9 @@ func (s *DocumentService) SendSigningNotifications(
}
email := coredata.NewEmail(
people.FullName,
people.PrimaryEmailAddress,
signatory.FullName,
// FIXME: load email with profile
"contact@getprobo.com",
subject,
textBody,
htmlBody,
@@ -620,6 +621,7 @@ func (s *DocumentService) SignDocumentVersionByEmail(
}
people := &coredata.People{}
// FIXME: will be done differently
if err := people.LoadByEmailAndOrganizationID(ctx, conn, s.svc.scope, userEmail, documentVersion.OrganizationID); err != nil {
return fmt.Errorf("cannot find people record for user email in organization %q: %w", documentVersion.OrganizationID, err)
}
@@ -790,7 +792,7 @@ func (s *DocumentService) createSignatureRequestInTx(
signatoryID gid.GID,
ignoreExisting bool,
) (*coredata.DocumentVersionSignature, error) {
signatory := &coredata.People{}
signatory := &coredata.MembershipProfile{}
documentVersion := &coredata.DocumentVersion{}
if err := documentVersion.LoadByID(ctx, tx, s.svc.scope, documentVersionID); err != nil {
@@ -1383,7 +1385,7 @@ func (s *DocumentService) Update(
}
document := &coredata.Document{}
people := &coredata.People{}
owner := &coredata.MembershipProfile{}
now := time.Now()
err := s.svc.pg.WithTx(
@@ -1414,10 +1416,10 @@ func (s *DocumentService) Update(
}
if req.OwnerID != nil {
if err := people.LoadByID(ctx, tx, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner %q: %w", *req.OwnerID, err)
if err := owner.LoadByID(ctx, tx, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile %q: %w", *req.OwnerID, err)
}
document.OwnerID = people.ID
document.OwnerID = owner.ID
}
document.UpdatedAt = now
@@ -1637,7 +1639,7 @@ func exportDocumentPDF(
) ([]byte, error) {
document := &coredata.Document{}
version := &coredata.DocumentVersion{}
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
organization := &coredata.Organization{}
if err := version.LoadByID(ctx, conn, scope, documentVersionID); err != nil {
@@ -1649,7 +1651,7 @@ func exportDocumentPDF(
}
if err := owner.LoadByID(ctx, conn, scope, document.OwnerID); err != nil {
return nil, fmt.Errorf("cannot load document owner: %w", err)
return nil, fmt.Errorf("cannot load document owner profile: %w", err)
}
if err := organization.LoadByID(ctx, conn, scope, document.OrganizationID); err != nil {

View File

@@ -59,7 +59,7 @@ func (cmr *CreateMeetingRequest) Validate() error {
v.Check(cmr.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(cmr.Date, "date", validator.Required())
v.CheckEach(cmr.AttendeeIDs, "attendee_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("attendee_ids[%d]", index), validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(item, fmt.Sprintf("attendee_ids[%d]", index), validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
})
v.Check(cmr.Minutes, "minutes", validator.SafeText(MinutesMaxLength))
@@ -72,7 +72,7 @@ func (umr *UpdateMeetingRequest) Validate() error {
v.Check(umr.MeetingID, "meeting_id", validator.Required(), validator.GID(coredata.MeetingEntityType))
v.Check(umr.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
v.CheckEach(umr.AttendeeIDs, "attendee_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("attendee_ids[%d]", index), validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(item, fmt.Sprintf("attendee_ids[%d]", index), validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
})
v.Check(umr.Minutes, "minutes", validator.SafeText(MinutesMaxLength))
@@ -196,9 +196,9 @@ func (s MeetingService) Create(
}
if len(req.AttendeeIDs) > 0 {
var attendeePeople coredata.Peoples
var attendeePeople coredata.MembershipProfiles
if err := attendeePeople.LoadByIDs(ctx, conn, s.svc.scope, req.AttendeeIDs); err != nil {
return fmt.Errorf("cannot load attendees: %w", err)
return fmt.Errorf("cannot load attendee profiles: %w", err)
}
var attendees coredata.MeetingAttendees
@@ -221,13 +221,13 @@ func (s MeetingService) Create(
func (s MeetingService) GetAttendees(
ctx context.Context,
meetingID gid.GID,
) (coredata.Peoples, error) {
var people coredata.Peoples
) (coredata.MembershipProfiles, error) {
var attendees coredata.MembershipProfiles
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return people.LoadByMeetingID(ctx, conn, s.svc.scope, meetingID)
return attendees.LoadByMeetingID(ctx, conn, s.svc.scope, meetingID)
},
)
@@ -235,7 +235,7 @@ func (s MeetingService) GetAttendees(
return nil, err
}
return people, nil
return attendees, nil
}
func (s MeetingService) Update(
@@ -272,9 +272,9 @@ func (s MeetingService) Update(
}
if req.AttendeeIDs != nil {
var attendeePeople coredata.Peoples
if err := attendeePeople.LoadByIDs(ctx, conn, s.svc.scope, req.AttendeeIDs); err != nil {
return fmt.Errorf("cannot load attendees: %w", err)
var attendeeProfiles coredata.MembershipProfiles
if err := attendeeProfiles.LoadByIDs(ctx, conn, s.svc.scope, req.AttendeeIDs); err != nil {
return fmt.Errorf("cannot load attendee profiles: %w", err)
}
var attendees coredata.MeetingAttendees

View File

@@ -69,7 +69,7 @@ func (cnr *CreateNonconformityRequest) Validate() error {
v.Check(cnr.AuditID, "audit_id", validator.GID(coredata.AuditEntityType))
v.Check(cnr.RootCause, "root_cause", validator.Required(), validator.SafeText(ContentMaxLength))
v.Check(cnr.CorrectiveAction, "corrective_action", validator.SafeText(ContentMaxLength))
v.Check(cnr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(cnr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.Check(cnr.Status, "status", validator.OneOfSlice(coredata.NonconformityStatuses()))
v.Check(cnr.EffectivenessCheck, "effectiveness_check", validator.SafeText(ContentMaxLength))
@@ -84,7 +84,7 @@ func (unr *UpdateNonconformityRequest) Validate() error {
v.Check(unr.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(unr.RootCause, "root_cause", validator.SafeText(ContentMaxLength))
v.Check(unr.CorrectiveAction, "corrective_action", validator.SafeText(ContentMaxLength))
v.Check(unr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(unr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(unr.Status, "status", validator.OneOfSlice(coredata.NonconformityStatuses()))
v.Check(unr.EffectivenessCheck, "effectiveness_check", validator.SafeText(ContentMaxLength))
@@ -156,9 +156,9 @@ func (s *NonconformityService) Create(
}
}
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
if err := nonconformity.Insert(ctx, conn, s.svc.scope); err != nil {
@@ -209,9 +209,9 @@ func (s *NonconformityService) Update(
nonconformity.CorrectiveAction = *req.CorrectiveAction
}
if req.OwnerID != nil {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
nonconformity.OwnerID = *req.OwnerID
}

View File

@@ -69,7 +69,7 @@ func (cor *CreateObligationRequest) Validate() error {
v.Check(cor.Requirement, "requirement", validator.SafeText(ContentMaxLength))
v.Check(cor.ActionsToBeImplemented, "actions_to_be_implemented", validator.SafeText(ContentMaxLength))
v.Check(cor.Regulator, "regulator", validator.SafeText(TitleMaxLength))
v.Check(cor.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(cor.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
v.Check(cor.Status, "status", validator.OneOfSlice(coredata.ObligationStatuses()))
v.Check(cor.Type, "type", validator.OneOfSlice(coredata.ObligationTypes()))
@@ -85,7 +85,7 @@ func (uor *UpdateObligationRequest) Validate() error {
v.Check(uor.Requirement, "requirement", validator.SafeText(ContentMaxLength))
v.Check(uor.ActionsToBeImplemented, "actions_to_be_implemented", validator.SafeText(ContentMaxLength))
v.Check(uor.Regulator, "regulator", validator.SafeText(NameMaxLength))
v.Check(uor.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(uor.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(uor.Status, "status", validator.OneOfSlice(coredata.ObligationStatuses()))
v.Check(uor.Type, "type", validator.OneOfSlice(coredata.ObligationTypes()))
@@ -151,9 +151,9 @@ func (s *ObligationService) Create(
return fmt.Errorf("cannot load organization: %w", err)
}
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
return fmt.Errorf("cannot load owner profile: %w", err)
}
if err := obligation.Insert(ctx, conn, s.svc.scope); err != nil {
@@ -209,9 +209,9 @@ func (s *ObligationService) Update(
}
if req.OwnerID != nil {
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
return fmt.Errorf("cannot load owner profile: %w", err)
}
obligation.OwnerID = *req.OwnerID
}

View File

@@ -75,7 +75,7 @@ func (cpr *CreatePeopleRequest) Validate() error {
func (upr *UpdatePeopleRequest) Validate() error {
v := validator.New()
v.Check(upr.ID, "id", validator.Required(), validator.GID(coredata.PeopleEntityType))
// v.Check(upr.ID, "id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(upr.Kind, "kind", validator.OneOfSlice(coredata.PeopleKinds()))
v.Check(upr.FullName, "full_name", validator.SafeTextNoNewLine(NameMaxLength))
v.Check(upr.PrimaryEmailAddress, "primary_email_address", validator.NotEmpty())
@@ -261,7 +261,7 @@ func (s PeopleService) Create(
}
now := time.Now()
peopleID := gid.New(s.svc.scope.GetTenantID(), coredata.PeopleEntityType)
peopleID := gid.New(s.svc.scope.GetTenantID(), 8)
organization := &coredata.Organization{}
people := &coredata.People{

View File

@@ -105,7 +105,7 @@ func (cpar *CreateProcessingActivityRequest) Validate() error {
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.PeopleEntityType))
v.Check(cpar.DataProtectionOfficerID, "data_protection_officer_id", validator.GID(coredata.MembershipProfileEntityType))
v.CheckEach(cpar.VendorIDs, "vendor_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("vendor_ids[%d]", index), validator.Required(), validator.GID(coredata.VendorEntityType))
})
@@ -132,7 +132,7 @@ func (upar *UpdateProcessingActivityRequest) Validate() error {
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.PeopleEntityType))
v.Check(upar.DataProtectionOfficerID, "data_protection_officer_id", validator.GID(coredata.MembershipProfileEntityType))
v.CheckEach(upar.VendorIDs, "vendor_ids", func(index int, item any) {
v.Check(item, fmt.Sprintf("vendor_ids[%d]", index), validator.GID(coredata.VendorEntityType))
})
@@ -462,7 +462,7 @@ func (s *ProcessingActivityService) ExportPDF(
for i, pa := range processingActivities {
dpoFullName := (*string)(nil)
if pa.DataProtectionOfficerID != nil {
dpo := &coredata.People{}
dpo := &coredata.MembershipProfile{}
if err := dpo.LoadByID(ctx, conn, s.svc.scope, *pa.DataProtectionOfficerID); err == nil {
dpoFullName = &dpo.FullName
}

View File

@@ -68,7 +68,7 @@ func (crr *CreateRiskRequest) Validate() error {
v.Check(crr.Description, "description", validator.Required(), validator.SafeText(ContentMaxLength))
v.Check(crr.Category, "category", validator.Required(), validator.SafeText(TitleMaxLength))
v.Check(crr.Treatment, "treatment", validator.Required(), validator.OneOfSlice(coredata.RiskTreatments()))
v.Check(crr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(crr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(crr.InherentLikelihood, "inherent_likelihood", validator.Required(), validator.Min(1), validator.Max(5))
v.Check(crr.InherentImpact, "inherent_impact", validator.Required(), validator.Min(1), validator.Max(5))
v.Check(crr.ResidualLikelihood, "residual_likelihood", validator.Min(1), validator.Max(5))
@@ -86,7 +86,7 @@ func (urr *UpdateRiskRequest) Validate() error {
v.Check(urr.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(urr.Category, "category", validator.SafeText(TitleMaxLength))
v.Check(urr.Treatment, "treatment", validator.OneOfSlice(coredata.RiskTreatments()))
v.Check(urr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(urr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(urr.InherentLikelihood, "inherent_likelihood", validator.Min(1), validator.Max(5))
v.Check(urr.InherentImpact, "inherent_impact", validator.Min(1), validator.Max(5))
v.Check(urr.ResidualLikelihood, "residual_likelihood", validator.Min(1), validator.Max(5))
@@ -419,7 +419,7 @@ func (s RiskService) Create(
req CreateRiskRequest,
) (*coredata.Risk, error) {
now := time.Now()
people := coredata.People{}
owner := coredata.MembershipProfile{}
organization := coredata.Organization{}
risk := &coredata.Risk{
@@ -458,8 +458,8 @@ func (s RiskService) Create(
}
if req.OwnerID != nil {
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
if err := owner.LoadByID(ctx, conn, s.svc.scope, *req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
}
@@ -537,9 +537,9 @@ func (s RiskService) Update(
if req.OwnerID != nil {
if *req.OwnerID != nil {
people := coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, **req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
owner := coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, **req.OwnerID); err != nil {
return fmt.Errorf("cannot load owner profile: %w", err)
}
risk.OwnerID = *req.OwnerID
} else {

View File

@@ -53,7 +53,7 @@ func (csr *CreateStateOfApplicabilityRequest) Validate() error {
v.Check(csr.OrganizationID, "organization_id", validator.Required(), validator.GID(coredata.OrganizationEntityType))
v.Check(csr.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(csr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.PeopleEntityType))
v.Check(csr.OwnerID, "owner_id", validator.Required(), validator.GID(coredata.MembershipProfileEntityType))
return v.Error()
}
@@ -63,7 +63,7 @@ func (usr *UpdateStateOfApplicabilityRequest) Validate() error {
v.Check(usr.StateOfApplicabilityID, "state_of_applicability_id", validator.Required(), validator.GID(coredata.StateOfApplicabilityEntityType))
v.Check(usr.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(usr.OwnerID, "owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(usr.OwnerID, "owner_id", validator.GID(coredata.MembershipProfileEntityType))
return v.Error()
}
@@ -445,9 +445,9 @@ func (s StateOfApplicabilityService) ExportPDF(
return fmt.Errorf("cannot load organization: %w", err)
}
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
if err := owner.LoadByID(ctx, conn, s.svc.scope, stateOfApplicability.OwnerID); err != nil {
return fmt.Errorf("cannot load owner: %w", err)
return fmt.Errorf("cannot load owner profile: %w", err)
}
// Load applicability statements

View File

@@ -62,7 +62,7 @@ func (ctr *CreateTaskRequest) Validate() error {
v.Check(ctr.Name, "name", validator.SafeTextNoNewLine(TitleMaxLength))
v.Check(ctr.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(ctr.TimeEstimate, "time_estimate", validator.RangeDuration(0, 1000*time.Hour))
v.Check(ctr.AssignedToID, "assigned_to_id", validator.GID(coredata.PeopleEntityType))
v.Check(ctr.AssignedToID, "assigned_to_id", validator.GID(coredata.MembershipProfileEntityType))
return v.Error()
}
@@ -75,7 +75,7 @@ func (utr *UpdateTaskRequest) Validate() error {
v.Check(utr.Description, "description", validator.SafeText(ContentMaxLength))
v.Check(utr.TimeEstimate, "time_estimate", validator.RangeDuration(0, 1000*time.Hour))
v.Check(utr.State, "state", validator.OneOfSlice(coredata.TaskStates()))
v.Check(utr.AssignedToID, "assigned_to_id", validator.GID(coredata.PeopleEntityType))
v.Check(utr.AssignedToID, "assigned_to_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(utr.MeasureID, "measure_id", validator.GID(coredata.MeasureEntityType))
return v.Error()
@@ -123,9 +123,9 @@ func (s TaskService) Create(
}
if req.AssignedToID != nil {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, *req.AssignedToID); err != nil {
return fmt.Errorf("cannot load assignee: %w", err)
assignee := &coredata.MembershipProfile{}
if err := assignee.LoadByID(ctx, conn, s.svc.scope, *req.AssignedToID); err != nil {
return fmt.Errorf("cannot load assignee profile: %w", err)
}
}
@@ -176,9 +176,9 @@ func (s TaskService) Assign(
return fmt.Errorf("cannot load task %q: %w", taskID, err)
}
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, assignedToID); err != nil {
return fmt.Errorf("cannot load assignee: %w", err)
assignee := &coredata.MembershipProfile{}
if err := assignee.LoadByID(ctx, conn, s.svc.scope, assignedToID); err != nil {
return fmt.Errorf("cannot load assignee profile: %w", err)
}
task.AssignedToID = &assignedToID
@@ -269,9 +269,9 @@ func (s TaskService) Update(
if *req.AssignedToID == nil {
task.AssignedToID = nil
} else {
people := &coredata.People{}
if err := people.LoadByID(ctx, conn, s.svc.scope, **req.AssignedToID); err != nil {
return fmt.Errorf("cannot load assignee: %w", err)
assignee := &coredata.MembershipProfile{}
if err := assignee.LoadByID(ctx, conn, s.svc.scope, **req.AssignedToID); err != nil {
return fmt.Errorf("cannot load assignee profile: %w", err)
}
task.AssignedToID = *req.AssignedToID
}

View File

@@ -111,8 +111,8 @@ func (cvr *CreateVendorRequest) Validate() error {
v.Check(cvr.TrustPageURL, "trust_page_url", validator.SafeText(2048))
v.Check(cvr.TermsOfServiceURL, "terms_of_service_url", validator.SafeText(2048))
v.Check(cvr.StatusPageURL, "status_page_url", validator.SafeText(2048))
v.Check(cvr.BusinessOwnerID, "business_owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(cvr.SecurityOwnerID, "security_owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(cvr.BusinessOwnerID, "business_owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(cvr.SecurityOwnerID, "security_owner_id", validator.GID(coredata.MembershipProfileEntityType))
return v.Error()
}
@@ -136,8 +136,8 @@ func (uvr *UpdateVendorRequest) Validate() error {
v.Check(uvr.TrustPageURL, "trust_page_url", validator.SafeText(2048))
v.Check(uvr.TermsOfServiceURL, "terms_of_service_url", validator.SafeText(2048))
v.Check(uvr.StatusPageURL, "status_page_url", validator.SafeText(2048))
v.Check(uvr.BusinessOwnerID, "business_owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(uvr.SecurityOwnerID, "security_owner_id", validator.GID(coredata.PeopleEntityType))
v.Check(uvr.BusinessOwnerID, "business_owner_id", validator.GID(coredata.MembershipProfileEntityType))
v.Check(uvr.SecurityOwnerID, "security_owner_id", validator.GID(coredata.MembershipProfileEntityType))
return v.Error()
}
@@ -364,9 +364,9 @@ func (s VendorService) Update(
if req.BusinessOwnerID != nil {
if *req.BusinessOwnerID != nil {
businessOwner := &coredata.People{}
businessOwner := &coredata.MembershipProfile{}
if err := businessOwner.LoadByID(ctx, conn, s.svc.scope, **req.BusinessOwnerID); err != nil {
return fmt.Errorf("cannot load business owner: %w", err)
return fmt.Errorf("cannot load business owner profile: %w", err)
}
vendor.BusinessOwnerID = &businessOwner.ID
} else {
@@ -376,9 +376,9 @@ func (s VendorService) Update(
if req.SecurityOwnerID != nil {
if *req.SecurityOwnerID != nil {
securityOwner := &coredata.People{}
securityOwner := &coredata.MembershipProfile{}
if err := securityOwner.LoadByID(ctx, conn, s.svc.scope, **req.SecurityOwnerID); err != nil {
return fmt.Errorf("cannot load security owner: %w", err)
return fmt.Errorf("cannot load security owner profile: %w", err)
}
vendor.SecurityOwnerID = &securityOwner.ID
} else {
@@ -479,17 +479,17 @@ func (s VendorService) Create(
vendor.OrganizationID = organization.ID
if req.BusinessOwnerID != nil {
businessOwner := &coredata.People{}
businessOwner := &coredata.MembershipProfile{}
if err := businessOwner.LoadByID(ctx, conn, s.svc.scope, *req.BusinessOwnerID); err != nil {
return fmt.Errorf("cannot load business owner: %w", err)
return fmt.Errorf("cannot load business owner profile: %w", err)
}
vendor.BusinessOwnerID = &businessOwner.ID
}
if req.SecurityOwnerID != nil {
securityOwner := &coredata.People{}
securityOwner := &coredata.MembershipProfile{}
if err := securityOwner.LoadByID(ctx, conn, s.svc.scope, *req.SecurityOwnerID); err != nil {
return fmt.Errorf("cannot load security owner: %w", err)
return fmt.Errorf("cannot load security owner profile: %w", err)
}
vendor.SecurityOwnerID = &securityOwner.ID
}

View File

@@ -1841,6 +1841,21 @@ type SlackConnectionEdge {
node: SlackConnection!
}
type Profile implements Node {
id: ID!
fullName: String!
email_address: EmailAddr!
additionalEmailAddresses: [EmailAddr!]!
kind: PeopleKind!
position: String
contractStartDate: Datetime
contractEndDate: Datetime
createdAt: Datetime!
updatedAt: Datetime!
permission(action: String!): Boolean! @goField(forceResolver: true)
}
type People implements Node {
id: ID!
fullName: String!
@@ -2234,7 +2249,7 @@ type Meeting implements Node {
name: String!
date: Datetime!
minutes: String
attendees: [People!]! @goField(forceResolver: true)
attendees: [Profile!]! @goField(forceResolver: true)
organization: Organization! @goField(forceResolver: true)
createdAt: Datetime!
updatedAt: Datetime!
@@ -2694,6 +2709,21 @@ type TrustCenterFileEdge {
node: TrustCenterFile!
}
type ProfileConnection
# @goModel(
# model: "go.probo.inc/probo/pkg/server/api/console/v1/types.ProfileConnection"
# ) {
# totalCount: Int! @goField(forceResolver: true)
{
edges: [ProfileEdge!]!
pageInfo: PageInfo!
}
type ProfileEdge {
cursor: CursorKey!
node: Profile!
}
type PeopleConnection
@goModel(
model: "go.probo.inc/probo/pkg/server/api/console/v1/types.PeopleConnection"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
// 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 types
import "go.probo.inc/probo/pkg/coredata"
func NewProfile(profile *coredata.MembershipProfile) *Profile {
return &Profile{
ID: profile.ID,
FullName: profile.FullName,
CreatedAt: profile.CreatedAt,
UpdatedAt: profile.UpdatedAt,
}
}

View File

@@ -1406,7 +1406,7 @@ type Meeting struct {
Name string `json:"name"`
Date time.Time `json:"date"`
Minutes *string `json:"minutes,omitempty"`
Attendees []*People `json:"attendees"`
Attendees []*Profile `json:"attendees"`
Organization *Organization `json:"organization"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
@@ -1612,6 +1612,33 @@ type ProcessingActivityFilter struct {
SnapshotID *gid.GID `json:"snapshotId,omitempty"`
}
type Profile struct {
ID gid.GID `json:"id"`
FullName string `json:"fullName"`
EmailAddress mail.Addr `json:"email_address"`
AdditionalEmailAddresses []mail.Addr `json:"additionalEmailAddresses"`
Kind coredata.PeopleKind `json:"kind"`
Position *string `json:"position,omitempty"`
ContractStartDate *time.Time `json:"contractStartDate,omitempty"`
ContractEndDate *time.Time `json:"contractEndDate,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Permission bool `json:"permission"`
}
func (Profile) IsNode() {}
func (this Profile) GetID() gid.GID { return this.ID }
type ProfileConnection struct {
Edges []*ProfileEdge `json:"edges"`
PageInfo *PageInfo `json:"pageInfo"`
}
type ProfileEdge struct {
Cursor page.CursorKey `json:"cursor"`
Node *Profile `json:"node"`
}
type PublishDocumentVersionInput struct {
DocumentID gid.GID `json:"documentId"`
Changelog *string `json:"changelog,omitempty"`

View File

@@ -1620,7 +1620,7 @@ func (r *measureConnectionResolver) TotalCount(ctx context.Context, obj *types.M
}
// Attendees is the resolver for the attendees field.
func (r *meetingResolver) Attendees(ctx context.Context, obj *types.Meeting) ([]*types.People, error) {
func (r *meetingResolver) Attendees(ctx context.Context, obj *types.Meeting) ([]*types.Profile, error) {
// TODO bug must be paginated
if err := r.authorize(ctx, obj.ID, probo.ActionPeopleList); err != nil {
@@ -1636,12 +1636,12 @@ func (r *meetingResolver) Attendees(ctx context.Context, obj *types.Meeting) ([]
}
if len(attendees) == 0 {
return []*types.People{}, nil
return []*types.Profile{}, nil
}
people := make([]*types.People, len(attendees))
people := make([]*types.Profile, len(attendees))
for i, attendee := range attendees {
people[i] = types.NewPeople(attendee)
people[i] = types.NewProfile(attendee)
}
return people, nil
@@ -6595,6 +6595,11 @@ func (r *processingActivityConnectionResolver) TotalCount(ctx context.Context, o
panic(fmt.Errorf("unsupported resolver: %T", obj.Resolver))
}
// Permission is the resolver for the permission field.
func (r *profileResolver) Permission(ctx context.Context, obj *types.Profile, action string) (bool, error) {
panic(fmt.Errorf("not implemented: Permission - permission"))
}
// Node is the resolver for the node field.
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
var (
@@ -6613,15 +6618,6 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
}
return types.NewOrganization(organization), nil
}
case coredata.PeopleEntityType:
action = probo.ActionPeopleGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
people, err := prb.Peoples.Get(ctx, id)
if err != nil {
return nil, err
}
return types.NewPeople(people), nil
}
case coredata.VendorEntityType:
action = probo.ActionVendorGet
loadNode = func(ctx context.Context, id gid.GID) (types.Node, error) {
@@ -8769,6 +8765,9 @@ func (r *Resolver) ProcessingActivityConnection() schema.ProcessingActivityConne
return &processingActivityConnectionResolver{r}
}
// Profile returns schema.ProfileResolver implementation.
func (r *Resolver) Profile() schema.ProfileResolver { return &profileResolver{r} }
// Query returns schema.QueryResolver implementation.
func (r *Resolver) Query() schema.QueryResolver { return &queryResolver{r} }
@@ -8943,6 +8942,7 @@ type peopleResolver struct{ *Resolver }
type peopleConnectionResolver struct{ *Resolver }
type processingActivityResolver struct{ *Resolver }
type processingActivityConnectionResolver struct{ *Resolver }
type profileResolver struct{ *Resolver }
type queryResolver struct{ *Resolver }
type reportResolver struct{ *Resolver }
type rightsRequestResolver struct{ *Resolver }

View File

@@ -142,7 +142,7 @@ func (s *DocumentService) exportPDFData(
) ([]byte, error) {
document := &coredata.Document{}
version := &coredata.DocumentVersion{}
owner := &coredata.People{}
owner := &coredata.MembershipProfile{}
organization := &coredata.Organization{}
err := s.svc.pg.WithConn(
@@ -161,7 +161,7 @@ func (s *DocumentService) exportPDFData(
}
if err := owner.LoadByID(ctx, conn, s.svc.scope, document.OwnerID); err != nil {
return fmt.Errorf("cannot load document owner: %w", err)
return fmt.Errorf("cannot load document owner profile: %w", err)
}
if err := organization.LoadByID(ctx, conn, s.svc.scope, document.OrganizationID); err != nil {