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
···
TagsTrunc []*types.TagReference
BranchesTrunc []types.Branch
// ForkInfo *types.ForkInfo
-
HTMLReadme template.HTML
-
Raw bool
-
EmailToDidOrHandle map[string]string
-
VerifiedCommits commitverify.VerifiedCommits
-
Languages []types.RepoLanguageDetails
-
Pipelines map[string]models.Pipeline
-
NeedsKnotUpgrade bool
types.RepoIndexResponse
}
···
}
type RepoLogParams struct {
-
LoggedInUser *oauth.User
-
RepoInfo repoinfo.RepoInfo
-
TagMap map[string][]string
types.RepoLogResponse
-
Active string
-
EmailToDidOrHandle map[string]string
-
VerifiedCommits commitverify.VerifiedCommits
-
Pipelines map[string]models.Pipeline
}
func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error {
···
}
type RepoCommitParams struct {
-
LoggedInUser *oauth.User
-
RepoInfo repoinfo.RepoInfo
-
Active string
-
EmailToDidOrHandle map[string]string
-
Pipeline *models.Pipeline
-
DiffOpts types.DiffOpts
// singular because it's always going to be just one
VerifiedCommit commitverify.VerifiedCommits
···
TagsTrunc []*types.TagReference
BranchesTrunc []types.Branch
// ForkInfo *types.ForkInfo
+
HTMLReadme template.HTML
+
Raw bool
+
EmailToDid map[string]string
+
VerifiedCommits commitverify.VerifiedCommits
+
Languages []types.RepoLanguageDetails
+
Pipelines map[string]models.Pipeline
+
NeedsKnotUpgrade bool
types.RepoIndexResponse
}
···
}
type RepoLogParams struct {
+
LoggedInUser *oauth.User
+
RepoInfo repoinfo.RepoInfo
+
TagMap map[string][]string
+
Active string
+
EmailToDid map[string]string
+
VerifiedCommits commitverify.VerifiedCommits
+
Pipelines map[string]models.Pipeline
+
types.RepoLogResponse
}
func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error {
···
}
type RepoCommitParams struct {
+
LoggedInUser *oauth.User
+
RepoInfo repoinfo.RepoInfo
+
Active string
+
EmailToDid map[string]string
+
Pipeline *models.Pipeline
+
DiffOpts types.DiffOpts
// singular because it's always going to be just one
VerifiedCommit commitverify.VerifiedCommits
+11 -11
appview/pages/templates/repo/commit.html
···
</div>
</div>
-
<div class="flex items-center space-x-2">
-
<p class="text-sm text-gray-500 dark:text-gray-300">
-
{{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }}
-
{{ if $didOrHandle }}
-
<a href="/{{ $didOrHandle }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $didOrHandle }}</a>
{{ else }}
<a href="mailto:{{ $commit.Author.Email }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $commit.Author.Name }}</a>
{{ end }}
<span class="px-1 select-none before:content-['\00B7']"></span>
{{ template "repo/fragments/time" $commit.Author.When }}
<span class="px-1 select-none before:content-['\00B7']"></span>
-
</p>
-
<p class="flex items-center text-sm text-gray-500 dark:text-gray-300">
<a href="/{{ $repo }}/commit/{{ $commit.This }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.This 0 8 }}</a>
{{ if $commit.Parent }}
-
{{ i "arrow-left" "w-3 h-3 mx-1" }}
-
<a href="/{{ $repo }}/commit/{{ $commit.Parent }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.Parent 0 8 }}</a>
{{ end }}
</p>
···
<div class="mb-1">This commit was signed with the committer's <span class="text-green-600 font-semibold">known signature</span>.</div>
<div class="flex items-center gap-2 my-2">
{{ i "user" "w-4 h-4" }}
-
{{ $committerDidOrHandle := index $.EmailToDidOrHandle $commit.Committer.Email }}
-
<a href="/{{ $committerDidOrHandle }}">{{ template "user/fragments/picHandleLink" $committerDidOrHandle }}</a>
</div>
<div class="my-1 pt-2 text-xs border-t border-gray-200 dark:border-gray-700">
<div class="text-gray-600 dark:text-gray-300">SSH Key Fingerprint:</div>
···
</div>
</div>
+
<div class="flex flex-wrap items-center space-x-2">
+
<p class="flex flex-wrap items-center gap-2 text-sm text-gray-500 dark:text-gray-300">
+
{{ $did := index $.EmailToDid $commit.Author.Email }}
+
{{ if $did }}
+
{{ template "user/fragments/picHandleLink" $did }}
{{ else }}
<a href="mailto:{{ $commit.Author.Email }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ $commit.Author.Name }}</a>
{{ end }}
+
<span class="px-1 select-none before:content-['\00B7']"></span>
{{ template "repo/fragments/time" $commit.Author.When }}
<span class="px-1 select-none before:content-['\00B7']"></span>
<a href="/{{ $repo }}/commit/{{ $commit.This }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.This 0 8 }}</a>
+
{{ if $commit.Parent }}
+
{{ i "arrow-left" "w-3 h-3 mx-1" }}
+
<a href="/{{ $repo }}/commit/{{ $commit.Parent }}" class="no-underline hover:underline text-gray-500 dark:text-gray-300">{{ slice $commit.Parent 0 8 }}</a>
{{ end }}
</p>
···
<div class="mb-1">This commit was signed with the committer's <span class="text-green-600 font-semibold">known signature</span>.</div>
<div class="flex items-center gap-2 my-2">
{{ i "user" "w-4 h-4" }}
+
{{ $committerDid := index $.EmailToDid $commit.Committer.Email }}
+
{{ template "user/fragments/picHandleLink" $committerDid }}
</div>
<div class="my-1 pt-2 text-xs border-t border-gray-200 dark:border-gray-700">
<div class="text-gray-600 dark:text-gray-300">SSH Key Fingerprint:</div>
+3 -13
appview/pages/templates/repo/index.html
···
class="mx-1 before:content-['·'] before:select-none"
></span>
<span>
-
{{ $didOrHandle := index $.EmailToDidOrHandle .Author.Email }}
-
<a
-
href="{{ if $didOrHandle }}
-
/{{ $didOrHandle }}
-
{{ else }}
-
mailto:{{ .Author.Email }}
-
{{ end }}"
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
-
>{{ if $didOrHandle }}
-
{{ template "user/fragments/picHandleLink" $didOrHandle }}
-
{{ else }}
-
{{ .Author.Name }}
-
{{ end }}</a
-
>
</span>
<div class="inline-block px-1 select-none after:content-['·']"></div>
{{ template "repo/fragments/time" .Committer.When }}
···
class="mx-1 before:content-['·'] before:select-none"
></span>
<span>
+
{{ $did := index $.EmailToDid .Author.Email }}
+
<a href="{{ if $did }}/{{ resolve $did }}{{ else }}mailto:{{ .Author.Email }}{{ end }}"
class="text-gray-500 dark:text-gray-400 no-underline hover:underline"
+
>{{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ .Author.Name }}{{ end }}</a>
</span>
<div class="inline-block px-1 select-none after:content-['·']"></div>
{{ template "repo/fragments/time" .Committer.When }}
+6 -6
appview/pages/templates/repo/log.html
···
{{ $messageParts := splitN $commit.Message "\n\n" 2 }}
<div class="{{ $grid }} py-3">
<div class="align-top truncate col-span-2">
-
{{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }}
-
{{ if $didOrHandle }}
-
{{ template "user/fragments/picHandleLink" $didOrHandle }}
{{ else }}
<a href="mailto:{{ $commit.Author.Email }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $commit.Author.Name }}</a>
{{ end }}
···
</span>
<span class="mx-2 before:content-['·'] before:select-none"></span>
<span>
-
{{ $didOrHandle := index $.EmailToDidOrHandle $commit.Author.Email }}
-
<a href="{{ if $didOrHandle }}/{{ $didOrHandle }}{{ else }}mailto:{{ $commit.Author.Email }}{{ end }}"
class="text-gray-500 dark:text-gray-400 no-underline hover:underline">
-
{{ if $didOrHandle }}{{ template "user/fragments/picHandleLink" $didOrHandle }}{{ else }}{{ $commit.Author.Name }}{{ end }}
</a>
</span>
<div class="inline-block px-1 select-none after:content-['·']"></div>
···
{{ $messageParts := splitN $commit.Message "\n\n" 2 }}
<div class="{{ $grid }} py-3">
<div class="align-top truncate col-span-2">
+
{{ $did := index $.EmailToDid $commit.Author.Email }}
+
{{ if $did }}
+
{{ template "user/fragments/picHandleLink" $did }}
{{ else }}
<a href="mailto:{{ $commit.Author.Email }}" class="text-gray-700 dark:text-gray-300 no-underline hover:underline">{{ $commit.Author.Name }}</a>
{{ end }}
···
</span>
<span class="mx-2 before:content-['·'] before:select-none"></span>
<span>
+
{{ $did := index $.EmailToDid $commit.Author.Email }}
+
<a href="{{ if $did }}/{{ $did }}{{ else }}mailto:{{ $commit.Author.Email }}{{ end }}"
class="text-gray-500 dark:text-gray-400 no-underline hover:underline">
+
{{ if $did }}{{ template "user/fragments/picHandleLink" $did }}{{ else }}{{ $commit.Author.Name }}{{ end }}
</a>
</span>
<div class="inline-block px-1 select-none after:content-['·']"></div>
+5 -5
appview/repo/index.go
···
CommitsTrunc: commitsTrunc,
TagsTrunc: tagsTrunc,
// ForkInfo: forkInfo, // TODO: reinstate this after xrpc properly lands
-
BranchesTrunc: branchesTrunc,
-
EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap),
-
VerifiedCommits: vc,
-
Languages: languageInfo,
-
Pipelines: pipelines,
})
}
···
CommitsTrunc: commitsTrunc,
TagsTrunc: tagsTrunc,
// ForkInfo: forkInfo, // TODO: reinstate this after xrpc properly lands
+
BranchesTrunc: branchesTrunc,
+
EmailToDid: emailToDidMap,
+
VerifiedCommits: vc,
+
Languages: languageInfo,
+
Pipelines: pipelines,
})
}
+8 -8
appview/repo/repo.go
···
}
rp.pages.RepoLog(w, pages.RepoLogParams{
-
LoggedInUser: user,
-
TagMap: tagMap,
-
RepoInfo: repoInfo,
-
RepoLogResponse: xrpcResp,
-
EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap),
-
VerifiedCommits: vc,
-
Pipelines: pipelines,
})
}
···
LoggedInUser: user,
RepoInfo: f.RepoInfo(user),
RepoCommitResponse: result,
-
EmailToDidOrHandle: emailToDidOrHandle(rp, emailToDidMap),
VerifiedCommit: vc,
Pipeline: pipeline,
DiffOpts: diffOpts,
···
}
rp.pages.RepoLog(w, pages.RepoLogParams{
+
LoggedInUser: user,
+
TagMap: tagMap,
+
RepoInfo: repoInfo,
+
RepoLogResponse: xrpcResp,
+
EmailToDid: emailToDidMap,
+
VerifiedCommits: vc,
+
Pipelines: pipelines,
})
}
···
LoggedInUser: user,
RepoInfo: f.RepoInfo(user),
RepoCommitResponse: result,
+
EmailToDid: emailToDidMap,
VerifiedCommit: vc,
Pipeline: pipeline,
DiffOpts: diffOpts,
-35
appview/repo/repo_util.go
···
package repo
import (
-
"context"
"crypto/rand"
-
"fmt"
"math/big"
"slices"
"sort"
···
return
}
-
// emailToDidOrHandle takes an emailToDidMap from db.GetEmailToDid
-
// and resolves all dids to handles and returns a new map[string]string
-
func emailToDidOrHandle(r *Repo, emailToDidMap map[string]string) map[string]string {
-
if emailToDidMap == nil {
-
return nil
-
}
-
-
var dids []string
-
for _, v := range emailToDidMap {
-
dids = append(dids, v)
-
}
-
resolvedIdents := r.idResolver.ResolveIdents(context.Background(), dids)
-
-
didHandleMap := make(map[string]string)
-
for _, identity := range resolvedIdents {
-
if !identity.Handle.IsInvalidHandle() {
-
didHandleMap[identity.DID.String()] = fmt.Sprintf("@%s", identity.Handle.String())
-
} else {
-
didHandleMap[identity.DID.String()] = identity.DID.String()
-
}
-
}
-
-
// Create map of email to didOrHandle for commit display
-
emailToDidOrHandle := make(map[string]string)
-
for email, did := range emailToDidMap {
-
if didOrHandle, ok := didHandleMap[did]; ok {
-
emailToDidOrHandle[email] = didOrHandle
-
}
-
}
-
-
return emailToDidOrHandle
-
}
-
func randomString(n int) string {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
result := make([]byte, n)
···
package repo
import (
"crypto/rand"
"math/big"
"slices"
"sort"
···
return
}
func randomString(n int) string {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
result := make([]byte, n)