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 #2
+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
··· 230 230 } 231 231 232 232 type LoginParams struct { 233 - ReturnUrl string 234 - ErrorCode string 235 - AddAccount bool 236 - LoggedInUser *oauth.MultiAccountUser 233 + ReturnUrl string 234 + ErrorCode string 235 + AddAccount bool 236 + Accounts []oauth.AccountInfo 237 237 } 238 238 239 239 func (p *Pages) Login(w io.Writer, params LoginParams) error {
+2 -3
appview/pages/templates/user/login.html
··· 31 31 </div> 32 32 {{ end }} 33 33 34 - {{ if and .LoggedInUser .LoggedInUser.Accounts }} 35 - {{ $accounts := .LoggedInUser.Accounts }} 34 + {{ if .Accounts }} 36 35 <div class="my-4 border border-gray-200 dark:border-gray-700 rounded overflow-hidden"> 37 36 <div class="px-3 py-2 bg-gray-50 dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700"> 38 37 <span class="text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide font-medium">Saved accounts</span> 39 38 </div> 40 39 <div class="divide-y divide-gray-200 dark:divide-gray-700"> 41 - {{ range $accounts }} 40 + {{ range .Accounts }} 42 41 <div class="flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-gray-700"> 43 42 <button 44 43 type="button"
+1 -1
appview/pulls/pulls.go
··· 191 191 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 192 192 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 193 193 resubmitResult := pages.Unknown 194 - if user != nil && user.Active != nil && user.Active.Did == pull.OwnerDid { 194 + if user != nil && user.Active.Did == pull.OwnerDid { 195 195 resubmitResult = s.resubmitCheck(r, f, pull, stack) 196 196 } 197 197
+1 -1
appview/reporesolver/resolver.go
··· 69 69 repoAt := repo.RepoAt() 70 70 isStarred := false 71 71 roles := repoinfo.RolesInRepo{} 72 - if user != nil && user.Active != nil { 72 + if user != nil { 73 73 isStarred = db.GetStarStatus(rr.execer, user.Active.Did, repoAt) 74 74 roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) 75 75 }
+6 -16
appview/state/login.go
··· 5 5 "net/http" 6 6 "strings" 7 7 8 - "tangled.org/core/appview/oauth" 9 8 "tangled.org/core/appview/pages" 10 9 ) 11 10 ··· 18 17 errorCode := r.URL.Query().Get("error") 19 18 addAccount := r.URL.Query().Get("mode") == "add_account" 20 19 21 - user := s.oauth.GetMultiAccountUser(r) 22 - if user == nil { 23 - registry := s.oauth.GetAccounts(r) 24 - if len(registry.Accounts) > 0 { 25 - user = &oauth.MultiAccountUser{ 26 - Active: nil, 27 - Accounts: registry.Accounts, 28 - } 29 - } 30 - } 20 + registry := s.oauth.GetAccounts(r) 31 21 s.pages.Login(w, pages.LoginParams{ 32 - ReturnUrl: returnURL, 33 - ErrorCode: errorCode, 34 - AddAccount: addAccount, 35 - LoggedInUser: user, 22 + ReturnUrl: returnURL, 23 + ErrorCode: errorCode, 24 + AddAccount: addAccount, 25 + Accounts: registry.Accounts, 36 26 }) 37 27 case http.MethodPost: 38 28 handle := r.FormValue("handle") ··· 80 70 l := s.logger.With("handler", "Logout") 81 71 82 72 currentUser := s.oauth.GetMultiAccountUser(r) 83 - if currentUser == nil || currentUser.Active == nil { 73 + if currentUser == nil { 84 74 s.pages.HxRedirect(w, "/login") 85 75 return 86 76 }
+1 -1
appview/state/state.go
··· 248 248 filtered := false 249 249 250 250 var userDid string 251 - if user != nil && user.Active != nil { 251 + if user != nil { 252 252 userDid = user.Active.Did 253 253 } 254 254 timeline, err := db.MakeTimeline(s.db, 50, userDid, filtered)

History

3 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/{pages,state}: simplify LoginPage params
2/3 failed, 1/3 success
expand
merge conflicts detected
expand
  • appview/pages/templates/user/login.html:33
  • appview/state/profile.go:817
  • appview/pages/templates/user/login.html:31
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