Monorepo for Tangled tangled.org

appview/{pages,state}: simplify LoginPage params #1023

open opened by boltless.me targeting master from sl/uvpzuszrulvq

We don't need to pass full MultiAccountUser here. just []AccountInfo should be enough. This way, we can make MultiAccountUser to always hold an active user.

Signed-off-by: Seongmin Lee git@boltless.me

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mdcq5ouz7x22
+17 -49
Diff #8
+2 -5
appview/oauth/accounts.go
··· 23 23 } 24 24 25 25 type MultiAccountUser struct { 26 - Active *User 26 + Active User 27 27 Accounts []AccountInfo 28 28 } 29 29 30 30 func (m *MultiAccountUser) Did() string { 31 - if m.Active == nil { 32 - return "" 33 - } 34 31 return m.Active.Did 35 32 } 36 33 ··· 122 119 123 120 registry := o.GetAccounts(r) 124 121 return &MultiAccountUser{ 125 - Active: &User{ 122 + Active: User{ 126 123 Did: sess.Data.AccountDID.String(), 127 124 }, 128 125 Accounts: registry.Accounts,
-18
appview/oauth/accounts_test.go
··· 210 210 } 211 211 }) 212 212 } 213 - 214 - func TestMultiAccountUser_Did(t *testing.T) { 215 - t.Run("with active user", func(t *testing.T) { 216 - user := &MultiAccountUser{ 217 - Active: &User{Did: "did:plc:test"}, 218 - } 219 - if user.Did() != "did:plc:test" { 220 - t.Errorf("Did() = %s, want did:plc:test", user.Did()) 221 - } 222 - }) 223 - 224 - t.Run("with nil active", func(t *testing.T) { 225 - user := &MultiAccountUser{Active: nil} 226 - if user.Did() != "" { 227 - t.Errorf("Did() = %s, want empty string", user.Did()) 228 - } 229 - }) 230 - }
+4 -4
appview/pages/pages.go
··· 309 309 } 310 310 311 311 type LoginParams struct { 312 - ReturnUrl string 313 - ErrorCode string 314 - AddAccount bool 315 - LoggedInUser *oauth.MultiAccountUser 312 + ReturnUrl string 313 + ErrorCode string 314 + AddAccount bool 315 + Accounts []oauth.AccountInfo 316 316 } 317 317 318 318 func (p *Pages) Login(w io.Writer, params LoginParams) error {
+2 -3
appview/pages/templates/user/login.html
··· 11 11 </div> 12 12 {{ end }} 13 13 14 - {{ if and .LoggedInUser .LoggedInUser.Accounts }} 15 - {{ $accounts := .LoggedInUser.Accounts }} 14 + {{ if .Accounts }} 16 15 <div class="my-4 border border-gray-200 dark:border-gray-700 rounded overflow-hidden"> 17 16 <div class="px-3 py-2 bg-gray-50 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700"> 18 17 <span class="text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide font-medium">Saved accounts</span> 19 18 </div> 20 19 <div class="divide-y divide-gray-200 dark:divide-gray-700"> 21 - {{ range $accounts }} 20 + {{ range .Accounts }} 22 21 <div class="flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-gray-700"> 23 22 <button 24 23 type="button"
+1 -1
appview/pulls/pulls.go
··· 198 198 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 199 199 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 200 200 resubmitResult := pages.Unknown 201 - if user != nil && user.Active != nil && user.Active.Did == pull.OwnerDid { 201 + if user != nil && user.Active.Did == pull.OwnerDid { 202 202 resubmitResult = s.resubmitCheck(r, f, pull, stack) 203 203 } 204 204
+1 -1
appview/reporesolver/resolver.go
··· 75 75 repoAt := repo.RepoAt() 76 76 isStarred := false 77 77 roles := repoinfo.RolesInRepo{} 78 - if user != nil && user.Active != nil { 78 + if user != nil { 79 79 isStarred = db.GetStarStatus(rr.execer, user.Active.Did, repoAt) 80 80 roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) 81 81 }
+6 -16
appview/state/login.go
··· 9 9 10 10 comatproto "github.com/bluesky-social/indigo/api/atproto" 11 11 "github.com/bluesky-social/indigo/xrpc" 12 - "tangled.org/core/appview/oauth" 13 12 "tangled.org/core/appview/pages" 14 13 ) 15 14 ··· 22 21 errorCode := r.URL.Query().Get("error") 23 22 addAccount := r.URL.Query().Get("mode") == "add_account" 24 23 25 - user := s.oauth.GetMultiAccountUser(r) 26 - if user == nil { 27 - registry := s.oauth.GetAccounts(r) 28 - if len(registry.Accounts) > 0 { 29 - user = &oauth.MultiAccountUser{ 30 - Active: nil, 31 - Accounts: registry.Accounts, 32 - } 33 - } 34 - } 24 + registry := s.oauth.GetAccounts(r) 35 25 s.pages.Login(w, pages.LoginParams{ 36 - ReturnUrl: returnURL, 37 - ErrorCode: errorCode, 38 - AddAccount: addAccount, 39 - LoggedInUser: user, 26 + ReturnUrl: returnURL, 27 + ErrorCode: errorCode, 28 + AddAccount: addAccount, 29 + Accounts: registry.Accounts, 40 30 }) 41 31 case http.MethodPost: 42 32 handle := r.FormValue("handle") ··· 120 110 l := s.logger.With("handler", "Logout") 121 111 122 112 currentUser := s.oauth.GetMultiAccountUser(r) 123 - if currentUser == nil || currentUser.Active == nil { 113 + if currentUser == nil { 124 114 s.pages.HxRedirect(w, "/login") 125 115 return 126 116 }
+1 -1
appview/state/timeline.go
··· 47 47 filtered := false 48 48 49 49 var userDid string 50 - if user != nil && user.Active != nil { 50 + if user != nil { 51 51 userDid = user.Active.Did 52 52 } 53 53 timeline, err := db.MakeTimeline(s.db, 50, userDid, filtered)

History

9 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 timeout, 1/3 success
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
3/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
3/3 success
expand
expand 0 comments
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
expand 0 comments