Monorepo for Tangled tangled.org

appview: use explicit TANGLED_PDS_HANDLE_SUFFIX for tngl.sh user check #1150

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

also fix the isTnglHandle logic a bit.

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

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mgs6m7kcv522
+19 -30
Diff #3
+1
appview/config/config.go
··· 90 90 91 91 type PdsConfig struct { 92 92 Host string `env:"HOST, default=https://tngl.sh"` 93 + UserDomain string `env:"USER_DOMAIN, default=.tngl.sh"` 93 94 AdminSecret string `env:"ADMIN_SECRET"` 94 95 } 95 96
+1
appview/pages/funcmap.go
··· 494 494 {"Name": "hooks", "Icon": "webhook"}, 495 495 {"Name": "sites", "Icon": "globe"}, 496 496 }, 497 + "PdsUserDomain": p.pdsCfg.UserDomain, 497 498 } 498 499 }, 499 500 }
+2 -1
appview/pages/pages.go
··· 42 42 cache *TmplCache[string, *template.Template] 43 43 44 44 avatar config.AvatarConfig 45 + pdsCfg config.PdsConfig 45 46 resolver *idresolver.Resolver 46 47 db *db.DB 47 48 dev bool ··· 67 68 cache: NewTmplCache[string, *template.Template](), 68 69 dev: config.Core.Dev, 69 70 avatar: config.Avatar, 71 + pdsCfg: config.Pds, 70 72 rctx: rctx, 71 73 resolver: res, 72 74 db: database, ··· 425 427 PunchcardPreference models.PunchcardPreference 426 428 IsTnglSh bool 427 429 IsDeactivated bool 428 - PdsDomain string 429 430 HandleOpen bool 430 431 } 431 432
+2 -2
appview/pages/templates/user/settings/profile.html
··· 63 63 <input type="hidden" name="type" value="subdomain"> 64 64 <div class="flex items-stretch rounded border border-gray-200 dark:border-gray-600 overflow-hidden focus-within:ring-1 focus-within:ring-blue-500 dark:bg-gray-700"> 65 65 <input type="text" name="handle" placeholder="username" class="flex-1 px-2 py-1.5 bg-transparent dark:text-white border-0 focus:outline-none focus:ring-0 min-w-0" required> 66 - <span class="px-2 py-1.5 bg-gray-100 dark:bg-gray-600 text-gray-500 dark:text-gray-300 select-none whitespace-nowrap border-l border-gray-200 dark:border-gray-600 content-center">.{{ .PdsDomain }}</span> 66 + <span class="px-2 py-1.5 bg-gray-100 dark:bg-gray-600 text-gray-500 dark:text-gray-300 select-none whitespace-nowrap border-l border-gray-200 dark:border-gray-600 content-center">{{ const.PdsUserDomain }}</span> 67 67 </div> 68 68 <div class="flex gap-2 pt-2"> 69 69 <button type="button" popovertarget="change-handle-modal" popovertargetaction="hide" class="btn w-1/2 flex items-center gap-2 text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"> ··· 104 104 </button> 105 105 </div> 106 106 </form> 107 - <a href="#" id="switch-to-subdomain" class="text-sm text-gray-400 underline hover:text-gray-600 dark:hover:text-gray-300">use a {{ .PdsDomain }} subdomain instead</a> 107 + <a href="#" id="switch-to-subdomain" class="text-sm text-gray-400 underline hover:text-gray-600 dark:hover:text-gray-300">use a {{ const.PdsUserDomain }} subdomain instead</a> 108 108 </div> 109 109 <div id="handle-error" class="text-red-500 dark:text-red-400 text-sm empty:hidden"></div> 110 110 <div id="handle-success" class="text-green-500 dark:text-green-400 text-sm empty:hidden"></div>
+13 -27
appview/settings/settings.go
··· 94 94 95 95 func (s *Settings) sitesSettings(w http.ResponseWriter, r *http.Request) { 96 96 user := s.OAuth.GetMultiAccountUser(r) 97 - did := s.OAuth.GetDid(r) 98 97 99 - claim, err := db.GetActiveDomainClaimForDid(s.Db, did) 98 + claim, err := db.GetActiveDomainClaimForDid(s.Db, user.Active.Did) 100 99 if err != nil { 101 100 s.Logger.Error("failed to get domain claim", "err", err) 102 101 claim = nil ··· 104 103 105 104 // determine whether the active account has a tngl.sh handle, in which 106 105 // case their sites domain is automatically their handle domain. 107 - pdsDomain := strings.TrimPrefix(s.Config.Pds.Host, "https://") 108 - pdsDomain = strings.TrimPrefix(pdsDomain, "http://") 109 106 isTnglHandle := false 110 107 for _, acc := range user.Accounts { 111 - if acc.Did == did && strings.HasSuffix(acc.Handle, "."+pdsDomain) { 112 - isTnglHandle = true 108 + if acc.Did == user.Active.Did { 109 + isTnglHandle = strings.HasSuffix(acc.Handle, s.Config.Pds.UserDomain) 113 110 break 114 111 } 115 112 } ··· 174 171 } 175 172 176 173 func (s *Settings) releaseSitesDomain(w http.ResponseWriter, r *http.Request) { 177 - did := s.OAuth.GetDid(r) 174 + user := s.OAuth.GetMultiAccountUser(r) 178 175 domain := strings.TrimSpace(r.FormValue("domain")) 179 176 180 177 if domain == "" { ··· 182 179 return 183 180 } 184 181 185 - pdsDomain := strings.TrimPrefix(s.Config.Pds.Host, "https://") 186 - pdsDomain = strings.TrimPrefix(pdsDomain, "http://") 187 - user := s.OAuth.GetMultiAccountUser(r) 188 182 for _, acc := range user.Accounts { 189 - if acc.Did == did && strings.HasSuffix(acc.Handle, "."+pdsDomain) { 190 - if strings.HasSuffix(domain, "."+pdsDomain) { 183 + if acc.Did == user.Active.Did { 184 + if strings.HasSuffix(acc.Handle, s.Config.Pds.UserDomain) { 191 185 s.Pages.Notice(w, "settings-sites-error", "Your tngl.sh domain is tied to your handle and cannot be released here.") 192 186 return 193 187 } 188 + break 194 189 } 195 190 } 196 191 197 - if err := db.ReleaseDomain(s.Db, did, domain); err != nil { 192 + if err := db.ReleaseDomain(s.Db, user.Active.Did, domain); err != nil { 198 193 s.Logger.Error("releasing domain", "err", err) 199 194 s.Pages.Notice(w, "settings-sites-error", "Unable to release domain. Make sure it belongs to your account.") 200 195 return ··· 202 197 203 198 // Clean up all site data for this DID asynchronously. 204 199 if s.CfClient.Enabled() { 205 - siteConfigs, err := db.GetRepoSiteConfigsForDid(s.Db, did) 200 + siteConfigs, err := db.GetRepoSiteConfigsForDid(s.Db, user.Active.Did) 206 201 if err != nil { 207 202 s.Logger.Error("releaseSitesDomain: fetching site configs for cleanup", "err", err) 208 203 } 209 204 210 - if err := db.DeleteRepoSiteConfigsForDid(s.Db, did); err != nil { 205 + if err := db.DeleteRepoSiteConfigsForDid(s.Db, user.Active.Did); err != nil { 211 206 s.Logger.Error("releaseSitesDomain: deleting site configs from db", "err", err) 212 207 } 213 208 ··· 216 211 217 212 // Delete each repo's R2 objects. 218 213 for _, sc := range siteConfigs { 219 - if err := sites.Delete(ctx, s.CfClient, did, sc.RepoName); err != nil { 220 - s.Logger.Error("releaseSitesDomain: R2 delete failed", "did", did, "repo", sc.RepoName, "err", err) 214 + if err := sites.Delete(ctx, s.CfClient, user.Active.Did, sc.RepoName); err != nil { 215 + s.Logger.Error("releaseSitesDomain: R2 delete failed", "did", user.Active.Did, "repo", sc.RepoName, "err", err) 221 216 } 222 217 } 223 218 ··· 263 258 PunchcardPreference: punchcardPreferences, 264 259 IsTnglSh: s.Config.Pds.IsTnglShUser(user.Pds()), 265 260 IsDeactivated: isDeactivated, 266 - PdsDomain: s.pdsDomain(), 267 261 HandleOpen: r.URL.Query().Get("handle") == "1", 268 262 }) 269 263 } ··· 720 714 } 721 715 } 722 716 723 - func (s *Settings) pdsDomain() string { 724 - parsed, err := url.Parse(s.Config.Pds.Host) 725 - if err != nil { 726 - return s.Config.Pds.Host 727 - } 728 - return parsed.Hostname() 729 - } 730 - 731 717 func (s *Settings) elevateForHandle(w http.ResponseWriter, r *http.Request) { 732 718 user := s.OAuth.GetMultiAccountUser(r) 733 719 if !s.Config.Pds.IsTnglShUser(user.Pds()) { ··· 778 764 s.Pages.Notice(w, "handle-error", "Invalid handle. Use only lowercase letters, digits, and hyphens.") 779 765 return 780 766 } 781 - newHandle = handleInput + "." + s.pdsDomain() 767 + newHandle = handleInput + s.Config.Pds.UserDomain 782 768 case "custom": 783 769 newHandle = handleInput 784 770 default:

History

4 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview: use explicit TANGLED_PDS_USER_DOMAIN for user handle check
2/3 failed, 1/3 success
expand
no conflicts, ready to merge
expand 0 comments
1 commit
expand
appview: use explicit TANGLED_PDS_USER_DOMAIN for user handle check
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview: use explicit TANGLED_PDS_USER_DOMAIN for user handle check
expand 0 comments
1 commit
expand
appview: use explicit TANGLED_PDS_HANDLE_SUFFIX for tngl.sh user check
expand 1 comment

lgtm barring merge conflicts!