Commit d58b7592 authored by ale's avatar ale

Treat domains that have acceptMail=true in the database as valid

parent 1f663e6f
Pipeline #6353 passed with stages
in 1 minute and 32 seconds
......@@ -348,6 +348,29 @@ func (v *validationContext) isAllowedDomain(rtype string) ValidatorFunc {
}
}
func (v *validationContext) isAllowedEmailDomain() ValidatorFunc {
return func(rctx *RequestContext, value string) error {
// Static lookup first.
if v.domains.IsAllowedDomain(rctx, ResourceTypeEmail, value) {
return nil
}
// Dynamic lookup for hosted domains in the database
// that have AcceptMail=true.
if tx, err := v.backend.NewTransaction(); err == nil {
// Ignore the error in FindResource() since we're going to fail close anyway.
// nolint: errcheck
rsrc, _ := tx.FindResource(rctx.Context, FindResourceRequest{Type: ResourceTypeDomain, Name: value})
if rsrc != nil && rsrc.Website.AcceptMail {
return nil
}
}
return errors.New("unavailable domain")
}
}
func (v *validationContext) isAvailableEmailAddr() ValidatorFunc {
return func(rctx *RequestContext, value string) error {
rel := relatedEmails(rctx.Context, v.domains, value)
......@@ -456,7 +479,7 @@ func (v *validationContext) validHostedEmail() ValidatorFunc {
maxLength(v.config.MaxUsernameLen),
notInSet(v.config.forbiddenUsernames),
),
allOf(v.isAllowedDomain(ResourceTypeEmail)),
allOf(v.isAllowedEmailDomain()),
)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment