package store import ( "regexp" "time" ) // ContractDocument is a workspace's own filled contract document (0027): a // PDF in the document bucket, made by staff from the released master and // the workspace's details. Rows are never changed; a corrected document is a // new row, and the newest per tenant and kind is the current one. type ContractDocument struct { ID int64 `json:"id"` TenantID string `json:"tenant_id"` Kind string `json:"doc_kind"` // avv Version string `json:"version"` // version of the master it was filled from SHA256 string `json:"sha256"` ObjectKey string `json:"-"` // ValuesSHA256 is the digest of the details filled in; the values // themselves are not kept here. ValuesSHA256 string `json:"values_sha256"` CreatedBy string `json:"created_by"` // Keycloak sub of the staff member CreatedAt time.Time `json:"created_at"` } // ContractDocumentAVV is the only kind a workspace has its own copy of. const ContractDocumentAVV = "avv" var ( contractVersionRe = regexp.MustCompile(`^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$`) hexDigestRe = regexp.MustCompile(`^[0-9a-f]{64}$`) ) // validContractDocument mirrors the CHECK constraints of 0027. func validContractDocument(d ContractDocument) bool { return d.Kind == ContractDocumentAVV && contractVersionRe.MatchString(d.Version) && hexDigestRe.MatchString(d.SHA256) && hexDigestRe.MatchString(d.ValuesSHA256) && d.ObjectKey != "" && len(d.ObjectKey) <= 512 && d.CreatedBy != "" && len(d.CreatedBy) <= 200 }