feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// supportPolicyDocument is the strict stored representation of the support
|
||||
// section. Pointer fields make omission distinct from a configured zero.
|
||||
type supportPolicyDocument struct {
|
||||
SupportResponseDays *BusinessDays `json:"support_response_business_days"`
|
||||
ComplaintResponseDays *BusinessDays `json:"complaint_response_business_days"`
|
||||
ManualAssessmentResponseDays *BusinessDays `json:"manual_assessment_response_business_days"`
|
||||
AppealResponseDays *BusinessDays `json:"appeal_response_business_days"`
|
||||
MaxRequestsPerWindow *int32 `json:"max_requests_per_window"`
|
||||
RequestWindowSeconds *int32 `json:"request_window_seconds"`
|
||||
MaxAppealsPerTarget *int32 `json:"max_appeals_per_target"`
|
||||
PauseWhenWaitingForUser *bool `json:"pause_when_waiting_for_user"`
|
||||
BusinessCalendarVersion *int32 `json:"business_calendar_version"`
|
||||
}
|
||||
|
||||
func encodeSupportPolicy(policy SupportPolicy) (*supportPolicyDocument, error) {
|
||||
requestWindowSeconds := int64(policy.requestWindow / time.Second)
|
||||
if requestWindowSeconds < 1 || policy.requestWindow%time.Second != 0 || requestWindowSeconds > 1<<31-1 {
|
||||
return nil, fmt.Errorf("encodeSupportPolicy - request window must fit whole int32 seconds: %w", ErrInvalidSupportPolicy)
|
||||
}
|
||||
return &supportPolicyDocument{
|
||||
SupportResponseDays: pointer(policy.supportResponseDays),
|
||||
ComplaintResponseDays: pointer(policy.complaintResponseDays),
|
||||
ManualAssessmentResponseDays: pointer(policy.manualAssessmentResponseDays),
|
||||
AppealResponseDays: pointer(policy.appealResponseDays),
|
||||
MaxRequestsPerWindow: pointer(policy.maxRequestsPerWindow),
|
||||
RequestWindowSeconds: pointer(int32(requestWindowSeconds)),
|
||||
MaxAppealsPerTarget: pointer(policy.maxAppealsPerTarget),
|
||||
PauseWhenWaitingForUser: pointer(policy.pauseWhenWaitingForUser),
|
||||
BusinessCalendarVersion: pointer(policy.businessCalendarVersion),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// decodeSupportPolicy reads every required support field. Unknown fields are
|
||||
// rejected by the enclosing product-policy decoder, which uses
|
||||
// DisallowUnknownFields.
|
||||
func decodeSupportPolicy(reader *documentReader, document *supportPolicyDocument) SupportPolicy {
|
||||
return SupportPolicy{
|
||||
supportResponseDays: require(reader, "support.support_response_business_days", document.SupportResponseDays),
|
||||
complaintResponseDays: require(reader, "support.complaint_response_business_days", document.ComplaintResponseDays),
|
||||
manualAssessmentResponseDays: require(reader, "support.manual_assessment_response_business_days", document.ManualAssessmentResponseDays),
|
||||
appealResponseDays: require(reader, "support.appeal_response_business_days", document.AppealResponseDays),
|
||||
maxRequestsPerWindow: require(reader, "support.max_requests_per_window", document.MaxRequestsPerWindow),
|
||||
requestWindow: time.Duration(require(reader, "support.request_window_seconds", document.RequestWindowSeconds)) * time.Second,
|
||||
maxAppealsPerTarget: require(reader, "support.max_appeals_per_target", document.MaxAppealsPerTarget),
|
||||
pauseWhenWaitingForUser: require(reader, "support.pause_when_waiting_for_user", document.PauseWhenWaitingForUser),
|
||||
businessCalendarVersion: require(reader, "support.business_calendar_version", document.BusinessCalendarVersion),
|
||||
}
|
||||
}
|
||||
|
||||
// decodeOptionalSupportPolicy preserves immutable legacy documents that were
|
||||
// published before the support section existed. It never fills an omitted
|
||||
// section with demo values.
|
||||
func decodeOptionalSupportPolicy(reader *documentReader, document *supportPolicyDocument) *SupportPolicy {
|
||||
if document == nil {
|
||||
return nil
|
||||
}
|
||||
policy := decodeSupportPolicy(reader, document)
|
||||
return &policy
|
||||
}
|
||||
|
||||
// Validate rejects an absent or unsupported support-policy section. Product
|
||||
// policies may leave the optional section nil only for immutable legacy
|
||||
// documents; policy creation uses an explicit SupportPolicy value.
|
||||
func (policy SupportPolicy) Validate() error {
|
||||
if policy.IsZero() {
|
||||
return ErrInvalidSupportPolicy
|
||||
}
|
||||
_, err := NewSupportPolicy(SupportPolicyInput{
|
||||
SupportResponseDays: policy.supportResponseDays,
|
||||
ComplaintResponseDays: policy.complaintResponseDays,
|
||||
ManualAssessmentResponseDays: policy.manualAssessmentResponseDays,
|
||||
AppealResponseDays: policy.appealResponseDays,
|
||||
MaxRequestsPerWindow: policy.maxRequestsPerWindow,
|
||||
RequestWindow: policy.requestWindow,
|
||||
MaxAppealsPerTarget: policy.maxAppealsPerTarget,
|
||||
PauseWhenWaitingForUser: policy.pauseWhenWaitingForUser,
|
||||
BusinessCalendarVersion: policy.businessCalendarVersion,
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user