appview/repo: remove EmailToDidOrHandle #732

merged
opened by oppi.li targeting master from push-msnlwkzsyxws

we no longer resolve handles from DIDs at the handlers, we do this dynamically when rendering the templates. EmailToDidOrHandle did not follow this pattern.

there were a few negative side effects from this: the tinyAvatar helper requires that the input be a DID; and not a handle. when a handle is passed, it results in a different default color for users without profile pictures; resulting in different colors in repo-log versus, say, the topbar.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+54 -98
appview
+21 -20
appview/pages/pages.go
··· 660 TagsTrunc []*types.TagReference 661 BranchesTrunc []types.Branch 662 // ForkInfo *types.ForkInfo 663 - HTMLReadme template.HTML 664 - Raw bool 665 - EmailToDidOrHandle map[string]string 666 - VerifiedCommits commitverify.VerifiedCommits 667 - Languages []types.RepoLanguageDetails 668 - Pipelines map[string]models.Pipeline 669 - NeedsKnotUpgrade bool 670 types.RepoIndexResponse 671 } 672 ··· 701 } 702 703 type RepoLogParams struct { 704 - LoggedInUser *oauth.User 705 - RepoInfo repoinfo.RepoInfo 706 - TagMap map[string][]string 707 types.RepoLogResponse 708 - Active string 709 - EmailToDidOrHandle map[string]string 710 - VerifiedCommits commitverify.VerifiedCommits 711 - Pipelines map[string]models.Pipeline 712 } 713 714 func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { ··· 717 } 718 719 type RepoCommitParams struct { 720 - LoggedInUser *oauth.User 721 - RepoInfo repoinfo.RepoInfo 722 - Active string 723 - EmailToDidOrHandle map[string]string 724 - Pipeline *models.Pipeline 725 - DiffOpts types.DiffOpts 726 727 // singular because it's always going to be just one 728 VerifiedCommit commitverify.VerifiedCommits
··· 660 TagsTrunc []*types.TagReference 661 BranchesTrunc []types.Branch 662 // ForkInfo *types.ForkInfo 663 + HTMLReadme template.HTML 664 + Raw bool 665 + EmailToDid map[string]string 666 + VerifiedCommits commitverify.VerifiedCommits 667 + Languages []types.RepoLanguageDetails 668 + Pipelines map[string]models.Pipeline 669 + NeedsKnotUpgrade bool 670 types.RepoIndexResponse 671 } 672 ··· 701 } 702 703 type RepoLogParams struct { 704 + LoggedInUser *oauth.User 705 + RepoInfo repoinfo.RepoInfo 706 + TagMap map[string][]string 707 + Active string 708 + EmailToDid map[string]string 709 + VerifiedCommits commitverify.VerifiedCommits 710 + Pipelines map[string]models.Pipeline 711 + 712 types.RepoLogResponse 713 } 714 715 func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { ··· 718 } 719 720 type RepoCommitParams struct { 721 + LoggedInUser *oauth.User 722 + RepoInfo repoinfo.RepoInfo 723 + Active string 724 + EmailToDid map[string]string 725 + Pipeline *models.Pipeline 726 + DiffOpts types.DiffOpts 727 728 // singular because it's always going to be just one 729 VerifiedCommit commitverify.VerifiedCommits
+11 -11
appview/pages/templates/repo/commit.html
··· 24 </div> 25 </div> 26 27 - <div class="flex items-center space-x-2"> 28 - <p class="text-sm text-gray-500 dark:text-gray-300"> 29 - {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} 30 31 - {{ if $didOrHandle }} 32 - <a href="/{{ $didOrHandle }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $didOrHandle }}</a> 33 {{ else }} 34 <a href="mailto:{{ $commit.Author.Email }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $commit.Author.Name }}</a> 35 {{ end }} 36 <span class="px-1 select-none before:content-['\00B7']"></span> 37 {{ template "repo/fragments/time" $commit.Author.When }} 38 <span class="px-1 select-none before:content-['\00B7']"></span> 39 - </p> 40 41 - <p class="flex items-center text-sm text-gray-500 dark:text-gray-300"> 42 <a href="/{{ $repo }}/commit/{{ $commit.This }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.This 0 8 }}</a> 43 {{ if $commit.Parent }} 44 - {{ i "arrow-left" "w-3 h-3 mx-1" }} 45 - <a href="/{{ $repo }}/commit/{{ $commit.Parent }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.Parent 0 8 }}</a> 46 {{ end }} 47 </p> 48 ··· 58 <div class="mb-1">This commit was signed with the committer's <span class="text-green-600 font-semibold">known signature</span>.</div> 59 <div class="flex items-center gap-2 my-2"> 60 {{ i "user" "w-4 h-4" }} 61 - {{ $committerDidOrHandle := index $.EmailToDidOrHandle $commit.Committer.Email }} 62 - <a href="/{{ $committerDidOrHandle }}">{{ template "user/fragments/picHandleLink" $committerDidOrHandle }}</a> 63 </div> 64 <div class="my-1 pt-2 text-xs border-t border-gray-200 dark:border-gray-700"> 65 <div class="text-gray-600 dark:text-gray-300">SSH Key Fingerprint:</div>
··· 24 </div> 25 </div> 26 27 + <div class="flex flex-wrap items-center space-x-2"> 28 + <p class="flex flex-wrap items-center gap-2 text-sm text-gray-500 dark:text-gray-300"> 29 + {{ $did := index $.EmailToDid $commit.Author.Email }} 30 31 + {{ if $did }} 32 + {{ template "user/fragments/picHandleLink" $did }} 33 {{ else }} 34 <a href="mailto:{{ $commit.Author.Email }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $commit.Author.Name }}</a> 35 {{ end }} 36 + 37 <span class="px-1 select-none before:content-['\00B7']"></span> 38 {{ template "repo/fragments/time" $commit.Author.When }} 39 <span class="px-1 select-none before:content-['\00B7']"></span> 40 41 <a href="/{{ $repo }}/commit/{{ $commit.This }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.This 0 8 }}</a> 42 + 43 {{ if $commit.Parent }} 44 + {{ i "arrow-left" "w-3 h-3 mx-1" }} 45 + <a href="/{{ $repo }}/commit/{{ $commit.Parent }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.Parent 0 8 }}</a> 46 {{ end }} 47 </p> 48 ··· 58 <div class="mb-1">This commit was signed with the committer's <span class="text-green-600 font-semibold">known signature</span>.</div> 59 <div class="flex items-center gap-2 my-2"> 60 {{ i "user" "w-4 h-4" }} 61 + {{ $committerDid := index $.EmailToDid $commit.Committer.Email }} 62 + {{ template "user/fragments/picHandleLink" $committerDid }} 63 </div> 64 <div class="my-1 pt-2 text-xs border-t border-gray-200 dark:border-gray-700"> 65 <div class="text-gray-600 dark:text-gray-300">SSH Key Fingerprint:</div>
+3 -13
appview/pages/templates/repo/index.html
··· 222 class="mx-1 before:content-['·'] before:select-none" 223 ></span> 224 <span> 225 - {{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }} 226 - <a 227 - href="{{ if $didOrHandle }} 228 - /{{ $didOrHandle }} 229 - {{ else }} 230 - mailto:{{ .Author.Email }} 231 - {{ end }}" 232 class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 233 - >{{ if $didOrHandle }} 234 - {{ template "user/fragments/picHandleLink" $didOrHandle }} 235 - {{ else }} 236 - {{ .Author.Name }} 237 - {{ end }}</a 238 - > 239 </span> 240 <div class="inline-block px-1 select-none after:content-['·']"></div> 241 {{ template "repo/fragments/time" .Committer.When }}
··· 222 class="mx-1 before:content-['·'] before:select-none" 223 ></span> 224 <span> 225 + {{ $did := index $.EmailToDid .Author.Email }} 226 + <a href="{{ if $did }}/{{ resolve $did }}{{ else }}mailto:{{ .Author.Email }}{{ end }}" 227 class="text-gray-500 dark:text-gray-400 no-underline hover:underline" 228 + >{{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ .Author.Name }}{{ end }}</a> 229 </span> 230 <div class="inline-block px-1 select-none after:content-['·']"></div> 231 {{ template "repo/fragments/time" .Committer.When }}
+6 -6
appview/pages/templates/repo/log.html
··· 27 {{ $messageParts := splitN $commit.Message "\n\n" 2 }} 28 <div class="{{ $grid }} py-3"> 29 <div class="align-top truncate col-span-2"> 30 - {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} 31 - {{ if $didOrHandle }} 32 - {{ template "user/fragments/picHandleLink" $didOrHandle }} 33 {{ else }} 34 <a href="mailto:{{ $commit.Author.Email }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $commit.Author.Name }}</a> 35 {{ end }} ··· 153 </span> 154 <span class="mx-2 before:content-['·'] before:select-none"></span> 155 <span> 156 - {{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }} 157 - <a href="{{ if $didOrHandle }}/{{ $didOrHandle }}{{ else }}mailto:{{ $commit.Author.Email }}{{ end }}" 158 class="text-gray-500 dark:text-gray-400 no-underline hover:underline"> 159 - {{ if $didOrHandle }}{{ template "user/fragments/picHandleLink" $didOrHandle }}{{ else }}{{ $commit.Author.Name }}{{ end }} 160 </a> 161 </span> 162 <div class="inline-block px-1 select-none after:content-['·']"></div>
··· 27 {{ $messageParts := splitN $commit.Message "\n\n" 2 }} 28 <div class="{{ $grid }} py-3"> 29 <div class="align-top truncate col-span-2"> 30 + {{ $did := index $.EmailToDid $commit.Author.Email }} 31 + {{ if $did }} 32 + {{ template "user/fragments/picHandleLink" $did }} 33 {{ else }} 34 <a href="mailto:{{ $commit.Author.Email }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $commit.Author.Name }}</a> 35 {{ end }} ··· 153 </span> 154 <span class="mx-2 before:content-['·'] before:select-none"></span> 155 <span> 156 + {{ $did := index $.EmailToDid $commit.Author.Email }} 157 + <a href="{{ if $did }}/{{ $did }}{{ else }}mailto:{{ $commit.Author.Email }}{{ end }}" 158 class="text-gray-500 dark:text-gray-400 no-underline hover:underline"> 159 + {{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ $commit.Author.Name }}{{ end }} 160 </a> 161 </span> 162 <div class="inline-block px-1 select-none after:content-['·']"></div>
+5 -5
appview/repo/index.go
··· 154 CommitsTrunc: commitsTrunc, 155 TagsTrunc: tagsTrunc, 156 // ForkInfo: forkInfo, // TODO: reinstate this after xrpc properly lands 157 - BranchesTrunc: branchesTrunc, 158 - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), 159 - VerifiedCommits: vc, 160 - Languages: languageInfo, 161 - Pipelines: pipelines, 162 }) 163 } 164
··· 154 CommitsTrunc: commitsTrunc, 155 TagsTrunc: tagsTrunc, 156 // ForkInfo: forkInfo, // TODO: reinstate this after xrpc properly lands 157 + BranchesTrunc: branchesTrunc, 158 + EmailToDid: emailToDidMap, 159 + VerifiedCommits: vc, 160 + Languages: languageInfo, 161 + Pipelines: pipelines, 162 }) 163 } 164
+8 -8
appview/repo/repo.go
··· 242 } 243 244 rp.pages.RepoLog(w, pages.RepoLogParams{ 245 - LoggedInUser: user, 246 - TagMap: tagMap, 247 - RepoInfo: repoInfo, 248 - RepoLogResponse: xrpcResp, 249 - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), 250 - VerifiedCommits: vc, 251 - Pipelines: pipelines, 252 }) 253 } 254 ··· 422 LoggedInUser: user, 423 RepoInfo: f.RepoInfo(user), 424 RepoCommitResponse: result, 425 - EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap), 426 VerifiedCommit: vc, 427 Pipeline: pipeline, 428 DiffOpts: diffOpts,
··· 242 } 243 244 rp.pages.RepoLog(w, pages.RepoLogParams{ 245 + LoggedInUser: user, 246 + TagMap: tagMap, 247 + RepoInfo: repoInfo, 248 + RepoLogResponse: xrpcResp, 249 + EmailToDid: emailToDidMap, 250 + VerifiedCommits: vc, 251 + Pipelines: pipelines, 252 }) 253 } 254 ··· 422 LoggedInUser: user, 423 RepoInfo: f.RepoInfo(user), 424 RepoCommitResponse: result, 425 + EmailToDid: emailToDidMap, 426 VerifiedCommit: vc, 427 Pipeline: pipeline, 428 DiffOpts: diffOpts,
-35
appview/repo/repo_util.go
··· 1 package repo 2 3 import ( 4 - "context" 5 "crypto/rand" 6 - "fmt" 7 "math/big" 8 "slices" 9 "sort" ··· 92 return 93 } 94 95 - // emailToDidOrHandle takes an emailToDidMap from db.GetEmailToDid 96 - // and resolves all dids to handles and returns a new map[string]string 97 - func emailToDidOrHandle(r *Repo, emailToDidMap map[string]string) map[string]string { 98 - if emailToDidMap == nil { 99 - return nil 100 - } 101 - 102 - var dids []string 103 - for _, v := range emailToDidMap { 104 - dids = append(dids, v) 105 - } 106 - resolvedIdents := r.idResolver.ResolveIdents(context.Background(), dids) 107 - 108 - didHandleMap := make(map[string]string) 109 - for _, identity := range resolvedIdents { 110 - if !identity.Handle.IsInvalidHandle() { 111 - didHandleMap[identity.DID.String()] = fmt.Sprintf("@%s", identity.Handle.String()) 112 - } else { 113 - didHandleMap[identity.DID.String()] = identity.DID.String() 114 - } 115 - } 116 - 117 - // Create map of email to didOrHandle for commit display 118 - emailToDidOrHandle := make(map[string]string) 119 - for email, did := range emailToDidMap { 120 - if didOrHandle, ok := didHandleMap[did]; ok { 121 - emailToDidOrHandle[email] = didOrHandle 122 - } 123 - } 124 - 125 - return emailToDidOrHandle 126 - } 127 - 128 func randomString(n int) string { 129 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 130 result := make([]byte, n)
··· 1 package repo 2 3 import ( 4 "crypto/rand" 5 "math/big" 6 "slices" 7 "sort" ··· 90 return 91 } 92 93 func randomString(n int) string { 94 const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 95 result := make([]byte, n)