From b412a0d1a3f69d1d884c03ae6ef1fa95d9d6c7ae Mon Sep 17 00:00:00 2001 From: tjh Date: Tue, 30 Sep 2025 13:08:18 +0100 Subject: [PATCH] appview: associate users to commits by did Change-Id: rwuynyxyuoxxzmmszytuonrkmmymupzn Enables commit verification for users using a DID in place of an email address. Signed-off-by: tjh --- appview/db/email.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/appview/db/email.go b/appview/db/email.go index 2ace1fdf..becf34a5 100644 --- a/appview/db/email.go +++ b/appview/db/email.go @@ -71,8 +71,8 @@ func GetDidForEmail(e Execer, em string) (string, error) { return did, nil } -func GetEmailToDid(e Execer, ems []string, isVerifiedFilter bool) (map[string]string, error) { - if len(ems) == 0 { +func GetEmailToDid(e Execer, emails []string, isVerifiedFilter bool) (map[string]string, error) { + if len(emails) == 0 { return make(map[string]string), nil } @@ -81,14 +81,20 @@ func GetEmailToDid(e Execer, ems []string, isVerifiedFilter bool) (map[string]st verifiedFilter = 1 } + assoc := make(map[string]string) + // Create placeholders for the IN clause - placeholders := make([]string, len(ems)) - args := make([]any, len(ems)+1) + placeholders := make([]string, 0, len(emails)) + args := make([]any, 1, len(emails)+1) args[0] = verifiedFilter - for i, em := range ems { - placeholders[i] = "?" - args[i+1] = em + for _, email := range emails { + if strings.HasPrefix(email, "did:") { + assoc[email] = email + continue + } + placeholders = append(placeholders, "?") + args = append(args, email) } query := ` @@ -105,8 +111,6 @@ func GetEmailToDid(e Execer, ems []string, isVerifiedFilter bool) (map[string]st } defer rows.Close() - assoc := make(map[string]string) - for rows.Next() { var email, did string if err := rows.Scan(&email, &did); err != nil { -- 2.51.0