From fc0602b6883c8dc52cc659291dcba6d840ac3445 Mon Sep 17 00:00:00 2001 From: Lewis Date: Sat, 10 Jan 2026 10:29:26 +0200 Subject: [PATCH] pages: support MultiAccountUser in templates and params Change-Id: lmkokpswyvslnxvnwoszqxrqlylmwyxl --- appview/pages/funcmap.go | 10 ++ appview/pages/pages.go | 134 +++++++++--------- .../templates/layouts/fragments/topbar.html | 60 ++++++-- appview/pages/templates/user/login.html | 53 +++++++ 4 files changed, 180 insertions(+), 77 deletions(-) diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index 14fdb009..78189296 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -28,6 +28,7 @@ import ( emoji "github.com/yuin/goldmark-emoji" "tangled.org/core/appview/filetree" "tangled.org/core/appview/models" + "tangled.org/core/appview/oauth" "tangled.org/core/appview/pages/markup" "tangled.org/core/crypto" ) @@ -385,6 +386,15 @@ func (p *Pages) funcMap() template.FuncMap { } return fp }, + "otherAccounts": func(activeDid string, accounts []oauth.AccountInfo) []oauth.AccountInfo { + result := make([]oauth.AccountInfo, 0, len(accounts)) + for _, acc := range accounts { + if acc.Did != activeDid { + result = append(result, acc) + } + } + return result + }, } } diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 7e806392..59f94db3 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -215,8 +215,10 @@ func (p *Pages) Favicon(w io.Writer) error { } type LoginParams struct { - ReturnUrl string - ErrorCode string + ReturnUrl string + ErrorCode string + AddAccount bool + LoggedInUser *oauth.MultiAccountUser } func (p *Pages) Login(w io.Writer, params LoginParams) error { @@ -236,7 +238,7 @@ func (p *Pages) CompleteSignup(w io.Writer) error { } type TermsOfServiceParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Content template.HTML } @@ -264,7 +266,7 @@ func (p *Pages) TermsOfService(w io.Writer, params TermsOfServiceParams) error { } type PrivacyPolicyParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Content template.HTML } @@ -292,7 +294,7 @@ func (p *Pages) PrivacyPolicy(w io.Writer, params PrivacyPolicyParams) error { } type BrandParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser } func (p *Pages) Brand(w io.Writer, params BrandParams) error { @@ -300,7 +302,7 @@ func (p *Pages) Brand(w io.Writer, params BrandParams) error { } type TimelineParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Timeline []models.TimelineEvent Repos []models.Repo GfiLabel *models.LabelDefinition @@ -311,7 +313,7 @@ func (p *Pages) Timeline(w io.Writer, params TimelineParams) error { } type GoodFirstIssuesParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Issues []models.Issue RepoGroups []*models.RepoGroup LabelDefs map[string]*models.LabelDefinition @@ -324,7 +326,7 @@ func (p *Pages) GoodFirstIssues(w io.Writer, params GoodFirstIssuesParams) error } type UserProfileSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Tabs []map[string]any Tab string } @@ -334,7 +336,7 @@ func (p *Pages) UserProfileSettings(w io.Writer, params UserProfileSettingsParam } type NotificationsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Notifications []*models.NotificationWithEntity UnreadCount int Page pagination.Page @@ -362,7 +364,7 @@ func (p *Pages) NotificationCount(w io.Writer, params NotificationCountParams) e } type UserKeysSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser PubKeys []models.PublicKey Tabs []map[string]any Tab string @@ -373,7 +375,7 @@ func (p *Pages) UserKeysSettings(w io.Writer, params UserKeysSettingsParams) err } type UserEmailsSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Emails []models.Email Tabs []map[string]any Tab string @@ -384,7 +386,7 @@ func (p *Pages) UserEmailsSettings(w io.Writer, params UserEmailsSettingsParams) } type UserNotificationSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Preferences *models.NotificationPreferences Tabs []map[string]any Tab string @@ -404,7 +406,7 @@ func (p *Pages) UpgradeBanner(w io.Writer, params UpgradeBannerParams) error { } type KnotsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Registrations []models.Registration Tabs []map[string]any Tab string @@ -415,7 +417,7 @@ func (p *Pages) Knots(w io.Writer, params KnotsParams) error { } type KnotParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Registration *models.Registration Members []string Repos map[string][]models.Repo @@ -437,7 +439,7 @@ func (p *Pages) KnotListing(w io.Writer, params KnotListingParams) error { } type SpindlesParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Spindles []models.Spindle Tabs []map[string]any Tab string @@ -458,7 +460,7 @@ func (p *Pages) SpindleListing(w io.Writer, params SpindleListingParams) error { } type SpindleDashboardParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Spindle models.Spindle Members []string Repos map[string][]models.Repo @@ -471,7 +473,7 @@ func (p *Pages) SpindleDashboard(w io.Writer, params SpindleDashboardParams) err } type NewRepoParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Knots []string } @@ -480,7 +482,7 @@ func (p *Pages) NewRepo(w io.Writer, params NewRepoParams) error { } type ForkRepoParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Knots []string RepoInfo repoinfo.RepoInfo } @@ -518,7 +520,7 @@ func (p *ProfileCard) GetTabs() [][]any { } type ProfileOverviewParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Repos []models.Repo CollaboratingRepos []models.Repo ProfileTimeline *models.ProfileTimeline @@ -532,7 +534,7 @@ func (p *Pages) ProfileOverview(w io.Writer, params ProfileOverviewParams) error } type ProfileReposParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Repos []models.Repo Card *ProfileCard Active string @@ -544,7 +546,7 @@ func (p *Pages) ProfileRepos(w io.Writer, params ProfileReposParams) error { } type ProfileStarredParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Repos []models.Repo Card *ProfileCard Active string @@ -556,7 +558,7 @@ func (p *Pages) ProfileStarred(w io.Writer, params ProfileStarredParams) error { } type ProfileStringsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Strings []models.String Card *ProfileCard Active string @@ -569,7 +571,7 @@ func (p *Pages) ProfileStrings(w io.Writer, params ProfileStringsParams) error { type FollowCard struct { UserDid string - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser FollowStatus models.FollowStatus FollowersCount int64 FollowingCount int64 @@ -577,7 +579,7 @@ type FollowCard struct { } type ProfileFollowersParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Followers []FollowCard Card *ProfileCard Active string @@ -589,7 +591,7 @@ func (p *Pages) ProfileFollowers(w io.Writer, params ProfileFollowersParams) err } type ProfileFollowingParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Following []FollowCard Card *ProfileCard Active string @@ -610,7 +612,7 @@ func (p *Pages) FollowFragment(w io.Writer, params FollowFragmentParams) error { } type EditBioParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Profile *models.Profile } @@ -619,7 +621,7 @@ func (p *Pages) EditBioFragment(w io.Writer, params EditBioParams) error { } type EditPinsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Profile *models.Profile AllRepos []PinnedRepo } @@ -644,7 +646,7 @@ func (p *Pages) StarBtnFragment(w io.Writer, params StarBtnFragmentParams) error } type RepoIndexParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string TagMap map[string][]string @@ -693,7 +695,7 @@ func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error { } type RepoLogParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo TagMap map[string][]string Active string @@ -710,7 +712,7 @@ func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error { } type RepoCommitParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string EmailToDid map[string]string @@ -729,7 +731,7 @@ func (p *Pages) RepoCommit(w io.Writer, params RepoCommitParams) error { } type RepoTreeParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string BreadCrumbs [][]string @@ -784,7 +786,7 @@ func (p *Pages) RepoTree(w io.Writer, params RepoTreeParams) error { } type RepoBranchesParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string types.RepoBranchesResponse @@ -796,7 +798,7 @@ func (p *Pages) RepoBranches(w io.Writer, params RepoBranchesParams) error { } type RepoTagsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string types.RepoTagsResponse @@ -810,7 +812,7 @@ func (p *Pages) RepoTags(w io.Writer, params RepoTagsParams) error { } type RepoArtifactParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Artifact models.Artifact } @@ -820,7 +822,7 @@ func (p *Pages) RepoArtifactFragment(w io.Writer, params RepoArtifactParams) err } type RepoBlobParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string BreadCrumbs [][]string @@ -844,7 +846,7 @@ type Collaborator struct { } type RepoSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Collaborators []Collaborator Active string @@ -863,7 +865,7 @@ func (p *Pages) RepoSettings(w io.Writer, params RepoSettingsParams) error { } type RepoGeneralSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Labels []models.LabelDefinition DefaultLabels []models.LabelDefinition @@ -881,7 +883,7 @@ func (p *Pages) RepoGeneralSettings(w io.Writer, params RepoGeneralSettingsParam } type RepoAccessSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string Tabs []map[string]any @@ -895,7 +897,7 @@ func (p *Pages) RepoAccessSettings(w io.Writer, params RepoAccessSettingsParams) } type RepoPipelineSettingsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string Tabs []map[string]any @@ -911,7 +913,7 @@ func (p *Pages) RepoPipelineSettings(w io.Writer, params RepoPipelineSettingsPar } type RepoIssuesParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string Issues []models.Issue @@ -928,7 +930,7 @@ func (p *Pages) RepoIssues(w io.Writer, params RepoIssuesParams) error { } type RepoSingleIssueParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string Issue *models.Issue @@ -947,7 +949,7 @@ func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error } type EditIssueParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue Action string @@ -971,7 +973,7 @@ func (p *Pages) ThreadReactionFragment(w io.Writer, params ThreadReactionFragmen } type RepoNewIssueParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue // existing issue if any -- passed when editing Active string @@ -985,7 +987,7 @@ func (p *Pages) RepoNewIssue(w io.Writer, params RepoNewIssueParams) error { } type EditIssueCommentParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue Comment *models.IssueComment @@ -996,7 +998,7 @@ func (p *Pages) EditIssueCommentFragment(w io.Writer, params EditIssueCommentPar } type ReplyIssueCommentPlaceholderParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue Comment *models.IssueComment @@ -1007,7 +1009,7 @@ func (p *Pages) ReplyIssueCommentPlaceholderFragment(w io.Writer, params ReplyIs } type ReplyIssueCommentParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue Comment *models.IssueComment @@ -1018,7 +1020,7 @@ func (p *Pages) ReplyIssueCommentFragment(w io.Writer, params ReplyIssueCommentP } type IssueCommentBodyParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Issue *models.Issue Comment *models.IssueComment @@ -1029,7 +1031,7 @@ func (p *Pages) IssueCommentBodyFragment(w io.Writer, params IssueCommentBodyPar } type RepoNewPullParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Branches []types.Branch Strategy string @@ -1046,7 +1048,7 @@ func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error { } type RepoPullsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pulls []*models.Pull Active string @@ -1081,7 +1083,7 @@ func (r ResubmitResult) Unknown() bool { } type RepoSinglePullParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Active string Pull *models.Pull @@ -1106,7 +1108,7 @@ func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { } type RepoPullPatchParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pull *models.Pull Stack models.Stack @@ -1123,7 +1125,7 @@ func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error } type RepoPullInterdiffParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pull *models.Pull Round int @@ -1176,7 +1178,7 @@ func (p *Pages) PullCompareForkBranchesFragment(w io.Writer, params PullCompareF } type PullResubmitParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pull *models.Pull SubmissionId int @@ -1187,7 +1189,7 @@ func (p *Pages) PullResubmitFragment(w io.Writer, params PullResubmitParams) err } type PullActionsParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pull *models.Pull RoundNumber int @@ -1202,7 +1204,7 @@ func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error } type PullNewCommentParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pull *models.Pull RoundNumber int @@ -1213,7 +1215,7 @@ func (p *Pages) PullNewCommentFragment(w io.Writer, params PullNewCommentParams) } type RepoCompareParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Forks []models.Repo Branches []types.Branch @@ -1232,7 +1234,7 @@ func (p *Pages) RepoCompare(w io.Writer, params RepoCompareParams) error { } type RepoCompareNewParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Forks []models.Repo Branches []types.Branch @@ -1249,7 +1251,7 @@ func (p *Pages) RepoCompareNew(w io.Writer, params RepoCompareNewParams) error { } type RepoCompareAllowPullParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Base string Head string @@ -1269,7 +1271,7 @@ func (p *Pages) RepoCompareDiffFragment(w io.Writer, params RepoCompareDiffFragm } type LabelPanelParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Defs map[string]*models.LabelDefinition Subject string @@ -1281,7 +1283,7 @@ func (p *Pages) LabelPanel(w io.Writer, params LabelPanelParams) error { } type EditLabelPanelParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Defs map[string]*models.LabelDefinition Subject string @@ -1293,7 +1295,7 @@ func (p *Pages) EditLabelPanel(w io.Writer, params EditLabelPanelParams) error { } type PipelinesParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pipelines []models.Pipeline Active string @@ -1336,7 +1338,7 @@ func (p *Pages) LogLine(w io.Writer, params LogLineParams) error { } type WorkflowParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser RepoInfo repoinfo.RepoInfo Pipeline models.Pipeline Workflow string @@ -1350,7 +1352,7 @@ func (p *Pages) Workflow(w io.Writer, params WorkflowParams) error { } type PutStringParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Action string // this is supplied in the case of editing an existing string @@ -1362,7 +1364,7 @@ func (p *Pages) PutString(w io.Writer, params PutStringParams) error { } type StringsDashboardParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Card ProfileCard Strings []models.String } @@ -1372,7 +1374,7 @@ func (p *Pages) StringsDashboard(w io.Writer, params StringsDashboardParams) err } type StringTimelineParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser Strings []models.String } @@ -1381,7 +1383,7 @@ func (p *Pages) StringsTimeline(w io.Writer, params StringTimelineParams) error } type SingleStringParams struct { - LoggedInUser *oauth.User + LoggedInUser *oauth.MultiAccountUser ShowRendered bool RenderToggle bool RenderedContents template.HTML diff --git a/appview/pages/templates/layouts/fragments/topbar.html b/appview/pages/templates/layouts/fragments/topbar.html index dcba4bec..c9c87427 100644 --- a/appview/pages/templates/layouts/fragments/topbar.html +++ b/appview/pages/templates/layouts/fragments/topbar.html @@ -49,7 +49,7 @@ {{ define "profileDropdown" }} diff --git a/appview/pages/templates/user/login.html b/appview/pages/templates/user/login.html index 4420cdb8..03cc7f71 100644 --- a/appview/pages/templates/user/login.html +++ b/appview/pages/templates/user/login.html @@ -20,6 +20,56 @@

tightly-knit social coding.

+ + {{ if .AddAccount }} +
+ {{ i "user-plus" "w-4 h-4" }} +
+
Add another account
+

Sign in with a different account to add it to your account list.

+
+
+ {{ end }} + + {{ if and .LoggedInUser .LoggedInUser.Accounts }} + {{ $accounts := .LoggedInUser.Accounts }} + {{ if $accounts }} +
+
+ Saved accounts +
+
+ {{ range $accounts }} +
+ + +
+ {{ end }} +
+
+ {{ end }} + {{ end }} +
+