@@ -177,6 +177,10 @@ func NewEntityFromID(id gid.GID) (any, bool) {
|
||||
return &TransferImpactAssessment{ID: id}, true
|
||||
case RightsRequestEntityType:
|
||||
return &RightsRequest{ID: id}, true
|
||||
case StateOfApplicabilityEntityType:
|
||||
return &StateOfApplicability{ID: id}, true
|
||||
case StateOfApplicabilityControlEntityType:
|
||||
return &StateOfApplicabilityControl{ID: id}, true
|
||||
case MembershipProfileEntityType:
|
||||
return &MembershipProfile{ID: id}, true
|
||||
case SCIMConfigurationEntityType:
|
||||
@@ -187,239 +191,3 @@ func NewEntityFromID(id gid.GID) (any, bool) {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
type EntityInfo struct {
|
||||
Model string
|
||||
Table string
|
||||
}
|
||||
|
||||
var entityRegistry = map[uint16]EntityInfo{
|
||||
OrganizationEntityType: {
|
||||
Model: "Organization",
|
||||
Table: "organizations",
|
||||
},
|
||||
FrameworkEntityType: {
|
||||
Model: "Framework",
|
||||
Table: "frameworks",
|
||||
},
|
||||
MeasureEntityType: {
|
||||
Model: "Measure",
|
||||
Table: "measures",
|
||||
},
|
||||
TaskEntityType: {
|
||||
Model: "Task",
|
||||
Table: "tasks",
|
||||
},
|
||||
EvidenceEntityType: {
|
||||
Model: "Evidence",
|
||||
Table: "evidences",
|
||||
},
|
||||
ConnectorEntityType: {
|
||||
Model: "Connector",
|
||||
Table: "connectors",
|
||||
},
|
||||
VendorRiskAssessmentEntityType: {
|
||||
Model: "VendorRiskAssessment",
|
||||
Table: "vendor_risk_assessments",
|
||||
},
|
||||
VendorEntityType: {
|
||||
Model: "Vendor",
|
||||
Table: "vendors",
|
||||
},
|
||||
PeopleEntityType: {
|
||||
Model: "People",
|
||||
Table: "peoples",
|
||||
},
|
||||
VendorComplianceReportEntityType: {
|
||||
Model: "VendorComplianceReport",
|
||||
Table: "vendor_compliance_reports",
|
||||
},
|
||||
DocumentEntityType: {
|
||||
Model: "Document",
|
||||
Table: "documents",
|
||||
},
|
||||
IdentityEntityType: {
|
||||
Model: "Identity",
|
||||
Table: "identities",
|
||||
},
|
||||
SessionEntityType: {
|
||||
Model: "Session",
|
||||
Table: "iam_sessions",
|
||||
},
|
||||
EmailEntityType: {
|
||||
Model: "Email",
|
||||
Table: "emails",
|
||||
},
|
||||
ControlEntityType: {
|
||||
Model: "Control",
|
||||
Table: "controls",
|
||||
},
|
||||
RiskEntityType: {
|
||||
Model: "Risk",
|
||||
Table: "risks",
|
||||
},
|
||||
DocumentVersionEntityType: {
|
||||
Model: "DocumentVersion",
|
||||
Table: "document_versions",
|
||||
},
|
||||
DocumentVersionSignatureEntityType: {
|
||||
Model: "DocumentVersionSignature",
|
||||
Table: "document_version_signatures",
|
||||
},
|
||||
AssetEntityType: {
|
||||
Model: "Asset",
|
||||
Table: "assets",
|
||||
},
|
||||
DatumEntityType: {
|
||||
Model: "Datum",
|
||||
Table: "data",
|
||||
},
|
||||
AuditEntityType: {
|
||||
Model: "Audit",
|
||||
Table: "audits",
|
||||
},
|
||||
ReportEntityType: {
|
||||
Model: "Report",
|
||||
Table: "reports",
|
||||
},
|
||||
TrustCenterEntityType: {
|
||||
Model: "TrustCenter",
|
||||
Table: "trust_centers",
|
||||
},
|
||||
TrustCenterAccessEntityType: {
|
||||
Model: "TrustCenterAccess",
|
||||
Table: "trust_center_accesses",
|
||||
},
|
||||
VendorBusinessAssociateAgreementEntityType: {
|
||||
Model: "VendorBusinessAssociateAgreement",
|
||||
Table: "vendor_business_associate_agreements",
|
||||
},
|
||||
FileEntityType: {
|
||||
Model: "File",
|
||||
Table: "files",
|
||||
},
|
||||
VendorContactEntityType: {
|
||||
Model: "VendorContact",
|
||||
Table: "vendor_contacts",
|
||||
},
|
||||
VendorDataPrivacyAgreementEntityType: {
|
||||
Model: "VendorDataPrivacyAgreement",
|
||||
Table: "vendor_data_privacy_agreements",
|
||||
},
|
||||
NonconformityEntityType: {
|
||||
Model: "Nonconformity",
|
||||
Table: "nonconformities",
|
||||
},
|
||||
ObligationEntityType: {
|
||||
Model: "Obligation",
|
||||
Table: "obligations",
|
||||
},
|
||||
VendorServiceEntityType: {
|
||||
Model: "VendorService",
|
||||
Table: "vendor_services",
|
||||
},
|
||||
SnapshotEntityType: {
|
||||
Model: "Snapshot",
|
||||
Table: "snapshots",
|
||||
},
|
||||
ContinualImprovementEntityType: {
|
||||
Model: "ContinualImprovement",
|
||||
Table: "continual_improvements",
|
||||
},
|
||||
ProcessingActivityEntityType: {
|
||||
Model: "ProcessingActivity",
|
||||
Table: "processing_activities",
|
||||
},
|
||||
ExportJobEntityType: {
|
||||
Model: "ExportJob",
|
||||
Table: "export_jobs",
|
||||
},
|
||||
TrustCenterReferenceEntityType: {
|
||||
Model: "TrustCenterReference",
|
||||
Table: "trust_center_references",
|
||||
},
|
||||
TrustCenterDocumentAccessEntityType: {
|
||||
Model: "TrustCenterDocumentAccess",
|
||||
Table: "trust_center_document_accesses",
|
||||
},
|
||||
CustomDomainEntityType: {
|
||||
Model: "CustomDomain",
|
||||
Table: "custom_domains",
|
||||
},
|
||||
InvitationEntityType: {
|
||||
Model: "Invitation",
|
||||
Table: "iam_invitations",
|
||||
},
|
||||
MembershipEntityType: {
|
||||
Model: "Membership",
|
||||
Table: "iam_memberships",
|
||||
},
|
||||
SlackMessageEntityType: {
|
||||
Model: "SlackMessage",
|
||||
Table: "slack_messages",
|
||||
},
|
||||
TrustCenterFileEntityType: {
|
||||
Model: "TrustCenterFile",
|
||||
Table: "trust_center_files",
|
||||
},
|
||||
SAMLConfigurationEntityType: {
|
||||
Model: "SAMLConfiguration",
|
||||
Table: "iam_saml_configurations",
|
||||
},
|
||||
PersonalAPIKeyEntityType: {
|
||||
Model: "PersonalAPIKey",
|
||||
Table: "iam_personal_api_keys",
|
||||
},
|
||||
MeetingEntityType: {
|
||||
Model: "Meeting",
|
||||
Table: "meetings",
|
||||
},
|
||||
DataProtectionImpactAssessmentEntityType: {
|
||||
Model: "DataProtectionImpactAssessment",
|
||||
Table: "processing_activity_data_protection_impact_assessments",
|
||||
},
|
||||
TransferImpactAssessmentEntityType: {
|
||||
Model: "TransferImpactAssessment",
|
||||
Table: "processing_activity_transfer_impact_assessments",
|
||||
},
|
||||
RightsRequestEntityType: {
|
||||
Model: "RightsRequest",
|
||||
Table: "rights_requests",
|
||||
},
|
||||
StateOfApplicabilityEntityType: {
|
||||
Model: "StateOfApplicability",
|
||||
Table: "states_of_applicability",
|
||||
},
|
||||
StateOfApplicabilityControlEntityType: {
|
||||
Model: "StateOfApplicabilityControl",
|
||||
Table: "states_of_applicability_controls",
|
||||
},
|
||||
MembershipProfileEntityType: {
|
||||
Model: "MembershipProfile",
|
||||
Table: "iam_membership_profiles",
|
||||
},
|
||||
SCIMConfigurationEntityType: {
|
||||
Model: "SCIMConfiguration",
|
||||
Table: "iam_scim_configurations",
|
||||
},
|
||||
SCIMEventEntityType: {
|
||||
Model: "SCIMEvent",
|
||||
Table: "iam_scim_events",
|
||||
},
|
||||
}
|
||||
|
||||
func EntityTable(entityType uint16) (string, bool) {
|
||||
info, ok := entityRegistry[entityType]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return info.Table, true
|
||||
}
|
||||
|
||||
func EntityModel(entityType uint16) (string, bool) {
|
||||
info, ok := entityRegistry[entityType]
|
||||
if !ok {
|
||||
return "", false
|
||||
}
|
||||
return info.Model, true
|
||||
}
|
||||
|
||||
@@ -269,64 +269,6 @@ LIMIT 1;
|
||||
}, nil
|
||||
}
|
||||
|
||||
func LoadRoleByIdentityAndEntityIDOnly(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
identityID gid.GID,
|
||||
entityID gid.GID,
|
||||
) (MembershipRole, error) {
|
||||
entityType := entityID.EntityType()
|
||||
|
||||
if entityType == OrganizationEntityType {
|
||||
query := `
|
||||
SELECT role
|
||||
FROM iam_memberships
|
||||
WHERE
|
||||
identity_id = $1
|
||||
AND tenant_id = $2
|
||||
AND organization_id = $3
|
||||
LIMIT 1;
|
||||
`
|
||||
var role MembershipRole
|
||||
err := conn.QueryRow(ctx, query, identityID, scope.GetTenantID(), entityID).Scan(&role)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return "", ErrResourceNotFound
|
||||
}
|
||||
return "", fmt.Errorf("cannot query role: %w", err)
|
||||
}
|
||||
return role, nil
|
||||
}
|
||||
|
||||
tableName, ok := EntityTable(entityType)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unsupported entity type for role lookup: %d", entityType)
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT m.role
|
||||
FROM iam_memberships m
|
||||
WHERE
|
||||
m.identity_id = $1
|
||||
AND tenant_id = $2
|
||||
AND m.organization_id = (SELECT organization_id FROM ` + tableName + ` WHERE id = $3)
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
var role MembershipRole
|
||||
err := conn.QueryRow(ctx, query, identityID, scope.GetTenantID(), entityID).Scan(&role)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return "", ErrResourceNotFound
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("cannot query role: %w", err)
|
||||
}
|
||||
|
||||
return role, nil
|
||||
}
|
||||
|
||||
func (m *Membership) LoadByIdentityAndOrg(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
@@ -54,6 +54,20 @@ func (s StateOfApplicability) CursorKey(orderBy StateOfApplicabilityOrderField)
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (s *StateOfApplicability) AuthorizationAttributes(ctx context.Context, conn pg.Conn) (map[string]string, error) {
|
||||
q := `SELECT organization_id FROM states_of_applicability WHERE id = $1 LIMIT 1;`
|
||||
|
||||
var organizationID gid.GID
|
||||
if err := conn.QueryRow(ctx, q, s.ID).Scan(&organizationID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("cannot query state of applicability authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
return map[string]string{"organization_id": organizationID.String()}, nil
|
||||
}
|
||||
|
||||
func (s *StateOfApplicability) LoadByID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
|
||||
@@ -60,26 +60,8 @@ type (
|
||||
}
|
||||
|
||||
AvailableStateOfApplicabilityControls []*AvailableStateOfApplicabilityControl
|
||||
|
||||
ErrStateOfApplicabilityControlNotFound struct {
|
||||
StateOfApplicabilityID gid.GID
|
||||
ControlID gid.GID
|
||||
}
|
||||
|
||||
ErrStateOfApplicabilityControlAlreadyExists struct {
|
||||
StateOfApplicabilityID gid.GID
|
||||
ControlID gid.GID
|
||||
}
|
||||
)
|
||||
|
||||
func (e ErrStateOfApplicabilityControlNotFound) Error() string {
|
||||
return fmt.Sprintf("state of applicability control not found: state_of_applicability_id=%s, control_id=%s", e.StateOfApplicabilityID, e.ControlID)
|
||||
}
|
||||
|
||||
func (e ErrStateOfApplicabilityControlAlreadyExists) Error() string {
|
||||
return fmt.Sprintf("state of applicability control already exists: state_of_applicability_id=%s, control_id=%s", e.StateOfApplicabilityID, e.ControlID)
|
||||
}
|
||||
|
||||
func (s StateOfApplicabilityControl) CursorKey(orderBy StateOfApplicabilityOrderField) page.CursorKey {
|
||||
switch orderBy {
|
||||
case StateOfApplicabilityOrderFieldName:
|
||||
@@ -91,6 +73,20 @@ func (s StateOfApplicabilityControl) CursorKey(orderBy StateOfApplicabilityOrder
|
||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||
}
|
||||
|
||||
func (s *StateOfApplicabilityControl) AuthorizationAttributes(ctx context.Context, conn pg.Conn) (map[string]string, error) {
|
||||
q := `SELECT organization_id FROM states_of_applicability_controls WHERE id = $1 LIMIT 1;`
|
||||
|
||||
var organizationID gid.GID
|
||||
if err := conn.QueryRow(ctx, q, s.ID).Scan(&organizationID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrResourceNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("cannot query state of applicability control authorization attributes: %w", err)
|
||||
}
|
||||
|
||||
return map[string]string{"organization_id": organizationID.String()}, nil
|
||||
}
|
||||
|
||||
func (sac *StateOfApplicabilityControl) LoadByStateOfApplicabilityIDAndControlID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
@@ -140,10 +136,7 @@ LIMIT 1;
|
||||
control, err := pgx.CollectExactlyOneRow(rows, pgx.RowToStructByName[StateOfApplicabilityControl])
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return &ErrStateOfApplicabilityControlNotFound{
|
||||
StateOfApplicabilityID: stateOfApplicabilityID,
|
||||
ControlID: controlID,
|
||||
}
|
||||
return ErrResourceNotFound
|
||||
}
|
||||
return fmt.Errorf("cannot collect state of applicability control: %w", err)
|
||||
}
|
||||
@@ -203,10 +196,7 @@ VALUES (
|
||||
var pgErr *pgconn.PgError
|
||||
if errors.As(err, &pgErr) {
|
||||
if pgErr.Code == "23505" {
|
||||
return &ErrStateOfApplicabilityControlAlreadyExists{
|
||||
StateOfApplicabilityID: sac.StateOfApplicabilityID,
|
||||
ControlID: sac.ControlID,
|
||||
}
|
||||
return ErrResourceAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user