Merge pull request #566 from arisudesu-forks/loop-extract

Extract mapping lookup from loop
This commit is contained in:
Max Mazurov 2023-03-12 14:09:31 +03:00 committed by GitHub
commit ca44d0e036
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,14 +9,10 @@ import (
) )
func AuthorizeEmailUse(ctx context.Context, username string, addrs []string, mapping module.Table) (bool, error) { func AuthorizeEmailUse(ctx context.Context, username string, addrs []string, mapping module.Table) (bool, error) {
for _, addr := range addrs {
_, domain, err := address.Split(addr)
if err != nil {
return false, fmt.Errorf("authz: %w", err)
}
var validEmails []string var validEmails []string
if multi, ok := mapping.(module.MultiTable); ok { if multi, ok := mapping.(module.MultiTable); ok {
var err error
validEmails, err = multi.LookupMulti(ctx, username) validEmails, err = multi.LookupMulti(ctx, username)
if err != nil { if err != nil {
return false, fmt.Errorf("authz: %w", err) return false, fmt.Errorf("authz: %w", err)
@ -31,6 +27,12 @@ func AuthorizeEmailUse(ctx context.Context, username string, addrs []string, map
} }
} }
for _, addr := range addrs {
_, domain, err := address.Split(addr)
if err != nil {
return false, fmt.Errorf("authz: %w", err)
}
for _, ent := range validEmails { for _, ent := range validEmails {
if ent == domain || ent == "*" || ent == addr { if ent == domain || ent == "*" || ent == addr {
return true, nil return true, nil