45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package protected_terms
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
|
frameworkvalidators "gitea.maximumdirect.net/eric/audita/internal/framework/validators"
|
|
validatormetadata "gitea.maximumdirect.net/eric/audita/internal/validators/metadata"
|
|
)
|
|
|
|
const Key = "protected_terms"
|
|
|
|
func New() (contracts.Validator, error) {
|
|
return validatormetadata.Wrap(validator{}, validatormetadata.ExecutionClassDeterministic), nil
|
|
}
|
|
|
|
func NewGlossaryStage() (contracts.Validator, error) {
|
|
return validatormetadata.Wrap(validator{glossaryStage: true}, validatormetadata.ExecutionClassDeterministic), nil
|
|
}
|
|
|
|
type validator struct {
|
|
glossaryStage bool
|
|
}
|
|
|
|
func (v validator) Name() string {
|
|
return Key
|
|
}
|
|
|
|
func (v validator) Validate(_ context.Context, req contracts.ValidationRequest) (frameworkvalidators.Result, error) {
|
|
if !v.glossaryStage && req.ModuleKey == "glossary" {
|
|
decisions := make([]frameworkvalidators.Decision, 0, len(req.CandidateProposal))
|
|
for _, c := range req.CandidateProposal {
|
|
decisions = append(decisions, frameworkvalidators.Decision{
|
|
ProposalIndex: c.ProposalIndex,
|
|
Approved: true,
|
|
ReasonCode: frameworkvalidators.ReasonApproved,
|
|
Message: "approved",
|
|
})
|
|
}
|
|
return frameworkvalidators.Result{ValidatorName: Key, Decisions: decisions}, nil
|
|
}
|
|
|
|
return frameworkvalidators.ValidateProtectedTerms(req, v.glossaryStage)
|
|
}
|