Monorepo for Tangled tangled.org

appview/pulls: remove dependencies to oauth.MultiAccountUser #1021

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

In most helper methods, DID is enough. Don't pass entire session info.

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/3mdcq5ouzke22
+48 -47
Diff #2
+48 -47
appview/pulls/pulls.go
··· 849 849 fromFork := r.FormValue("fork") 850 850 sourceBranch := r.FormValue("sourceBranch") 851 851 patch := r.FormValue("patch") 852 + userDid := syntax.DID(user.Active.Did) 852 853 853 854 if targetBranch == "" { 854 855 s.pages.Notice(w, "pull", "Target branch is required.") ··· 856 857 } 857 858 858 859 // Determine PR type based on input parameters 859 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 860 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(userDid.String(), f.Knot, f.DidSlashRepo())} 860 861 isPushAllowed := roles.IsPushAllowed() 861 862 isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 862 863 isForkBased := fromFork != "" && sourceBranch != "" ··· 934 935 s.pages.Notice(w, "pull", "This knot doesn't support branch-based pull requests. Try another way?") 935 936 return 936 937 } 937 - s.handleBranchBasedPull(w, r, f, user, title, body, targetBranch, sourceBranch, isStacked) 938 + s.handleBranchBasedPull(w, r, f, userDid, title, body, targetBranch, sourceBranch, isStacked) 938 939 } else if isForkBased { 939 940 if !caps.PullRequests.ForkSubmissions { 940 941 s.pages.Notice(w, "pull", "This knot doesn't support fork-based pull requests. Try another way?") 941 942 return 942 943 } 943 - s.handleForkBasedPull(w, r, f, user, fromFork, title, body, targetBranch, sourceBranch, isStacked) 944 + s.handleForkBasedPull(w, r, f, userDid, fromFork, title, body, targetBranch, sourceBranch, isStacked) 944 945 } else if isPatchBased { 945 946 if !caps.PullRequests.PatchSubmissions { 946 947 s.pages.Notice(w, "pull", "This knot doesn't support patch-based pull requests. Send your patch over email.") 947 948 return 948 949 } 949 - s.handlePatchBasedPull(w, r, f, user, title, body, targetBranch, patch, isStacked) 950 + s.handlePatchBasedPull(w, r, f, userDid, title, body, targetBranch, patch, isStacked) 950 951 } 951 952 return 952 953 } ··· 956 957 w http.ResponseWriter, 957 958 r *http.Request, 958 959 repo *models.Repo, 959 - user *oauth.MultiAccountUser, 960 + userDid syntax.DID, 960 961 title, 961 962 body, 962 963 targetBranch, ··· 1010 1011 Sha: comparison.Rev2, 1011 1012 } 1012 1013 1013 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1014 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1014 1015 } 1015 1016 1016 - func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, title, body, targetBranch, patch string, isStacked bool) { 1017 + func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, title, body, targetBranch, patch string, isStacked bool) { 1017 1018 if err := s.validator.ValidatePatch(&patch); err != nil { 1018 1019 s.logger.Error("patch validation failed", "err", err) 1019 1020 s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.") 1020 1021 return 1021 1022 } 1022 1023 1023 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1024 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1024 1025 } 1025 1026 1026 - func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, forkRepo string, title, body, targetBranch, sourceBranch string, isStacked bool) { 1027 + func (s *Pulls) handleForkBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, forkRepo string, title, body, targetBranch, sourceBranch string, isStacked bool) { 1027 1028 repoString := strings.SplitN(forkRepo, "/", 2) 1028 1029 forkOwnerDid := repoString[0] 1029 1030 repoName := repoString[1] ··· 1125 1126 Sha: sourceRev, 1126 1127 } 1127 1128 1128 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1129 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1129 1130 } 1130 1131 1131 1132 func (s *Pulls) createPullRequest( 1132 1133 w http.ResponseWriter, 1133 1134 r *http.Request, 1134 1135 repo *models.Repo, 1135 - user *oauth.MultiAccountUser, 1136 + userDid syntax.DID, 1136 1137 title, body, targetBranch string, 1137 1138 patch string, 1138 1139 combined string, ··· 1147 1148 w, 1148 1149 r, 1149 1150 repo, 1150 - user, 1151 + userDid, 1151 1152 targetBranch, 1152 1153 patch, 1153 1154 sourceRev, ··· 1204 1205 Title: title, 1205 1206 Body: body, 1206 1207 TargetBranch: targetBranch, 1207 - OwnerDid: user.Active.Did, 1208 + OwnerDid: userDid.String(), 1208 1209 RepoAt: repo.RepoAt(), 1209 1210 Rkey: rkey, 1210 1211 Mentions: mentions, ··· 1236 1237 1237 1238 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1238 1239 Collection: tangled.RepoPullNSID, 1239 - Repo: user.Active.Did, 1240 + Repo: userDid.String(), 1240 1241 Rkey: rkey, 1241 1242 Record: &lexutil.LexiconTypeDecoder{ 1242 1243 Val: &tangled.RepoPull{ ··· 1273 1274 w http.ResponseWriter, 1274 1275 r *http.Request, 1275 1276 repo *models.Repo, 1276 - user *oauth.MultiAccountUser, 1277 + userDid syntax.DID, 1277 1278 targetBranch string, 1278 1279 patch string, 1279 1280 sourceRev string, ··· 1304 1305 1305 1306 // build a stack out of this patch 1306 1307 stackId := uuid.New() 1307 - stack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pullSource, stackId.String()) 1308 + stack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pullSource, stackId.String()) 1308 1309 if err != nil { 1309 1310 log.Println("failed to create stack", err) 1310 1311 s.pages.Notice(w, "pull", fmt.Sprintf("Failed to create stack: %v", err)) ··· 1341 1342 }) 1342 1343 } 1343 1344 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 1344 - Repo: user.Active.Did, 1345 + Repo: userDid.String(), 1345 1346 Writes: writes, 1346 1347 }) 1347 1348 if err != nil { ··· 1625 1626 return 1626 1627 } 1627 1628 1628 - f, err := s.repoResolver.Resolve(r) 1629 - if err != nil { 1630 - log.Println("failed to get repo and knot", err) 1629 + if user == nil || user.Active.Did != pull.OwnerDid { 1630 + log.Println("unauthorized user") 1631 + w.WriteHeader(http.StatusUnauthorized) 1631 1632 return 1632 1633 } 1633 1634 1634 - if user.Active.Did != pull.OwnerDid { 1635 - log.Println("unauthorized user") 1636 - w.WriteHeader(http.StatusUnauthorized) 1635 + f, err := s.repoResolver.Resolve(r) 1636 + if err != nil { 1637 + log.Println("failed to get repo and knot", err) 1637 1638 return 1638 1639 } 1639 1640 1640 1641 patch := r.FormValue("patch") 1641 1642 1642 - s.resubmitPullHelper(w, r, f, user, pull, patch, "", "") 1643 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, "", "") 1643 1644 } 1644 1645 1645 1646 func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { ··· 1652 1653 return 1653 1654 } 1654 1655 1655 - f, err := s.repoResolver.Resolve(r) 1656 - if err != nil { 1657 - log.Println("failed to get repo and knot", err) 1656 + if user == nil || user.Active.Did != pull.OwnerDid { 1657 + log.Println("unauthorized user") 1658 + w.WriteHeader(http.StatusUnauthorized) 1658 1659 return 1659 1660 } 1660 1661 1661 - if user.Active.Did != pull.OwnerDid { 1662 - log.Println("unauthorized user") 1663 - w.WriteHeader(http.StatusUnauthorized) 1662 + f, err := s.repoResolver.Resolve(r) 1663 + if err != nil { 1664 + log.Println("failed to get repo and knot", err) 1664 1665 return 1665 1666 } 1666 1667 ··· 1704 1705 patch := comparison.FormatPatchRaw 1705 1706 combined := comparison.CombinedPatchRaw 1706 1707 1707 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1708 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1708 1709 } 1709 1710 1710 1711 func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { ··· 1717 1718 return 1718 1719 } 1719 1720 1720 - f, err := s.repoResolver.Resolve(r) 1721 - if err != nil { 1722 - log.Println("failed to get repo and knot", err) 1721 + if user == nil || user.Active.Did != pull.OwnerDid { 1722 + log.Println("unauthorized user") 1723 + w.WriteHeader(http.StatusUnauthorized) 1723 1724 return 1724 1725 } 1725 1726 1726 - if user.Active.Did != pull.OwnerDid { 1727 - log.Println("unauthorized user") 1728 - w.WriteHeader(http.StatusUnauthorized) 1727 + f, err := s.repoResolver.Resolve(r) 1728 + if err != nil { 1729 + log.Println("failed to get repo and knot", err) 1729 1730 return 1730 1731 } 1731 1732 ··· 1801 1802 patch := comparison.FormatPatchRaw 1802 1803 combined := comparison.CombinedPatchRaw 1803 1804 1804 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1805 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1805 1806 } 1806 1807 1807 1808 func (s *Pulls) resubmitPullHelper( 1808 1809 w http.ResponseWriter, 1809 1810 r *http.Request, 1810 1811 repo *models.Repo, 1811 - user *oauth.MultiAccountUser, 1812 + userDid syntax.DID, 1812 1813 pull *models.Pull, 1813 1814 patch string, 1814 1815 combined string, ··· 1816 1817 ) { 1817 1818 if pull.IsStacked() { 1818 1819 log.Println("resubmitting stacked PR") 1819 - s.resubmitStackedPullHelper(w, r, repo, user, pull, patch, pull.StackId) 1820 + s.resubmitStackedPullHelper(w, r, repo, userDid, pull, patch, pull.StackId) 1820 1821 return 1821 1822 } 1822 1823 ··· 1864 1865 return 1865 1866 } 1866 1867 1867 - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Active.Did, pull.Rkey) 1868 + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, userDid.String(), pull.Rkey) 1868 1869 if err != nil { 1869 1870 // failed to get record 1870 1871 s.pages.Notice(w, "resubmit-error", "Failed to update pull, no record found on PDS.") ··· 1884 1885 1885 1886 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1886 1887 Collection: tangled.RepoPullNSID, 1887 - Repo: user.Active.Did, 1888 + Repo: userDid.String(), 1888 1889 Rkey: pull.Rkey, 1889 1890 SwapRecord: ex.Cid, 1890 1891 Record: &lexutil.LexiconTypeDecoder{ ··· 1911 1912 w http.ResponseWriter, 1912 1913 r *http.Request, 1913 1914 repo *models.Repo, 1914 - user *oauth.MultiAccountUser, 1915 + userDid syntax.DID, 1915 1916 pull *models.Pull, 1916 1917 patch string, 1917 1918 stackId string, ··· 1919 1920 targetBranch := pull.TargetBranch 1920 1921 1921 1922 origStack, _ := r.Context().Value("stack").(models.Stack) 1922 - newStack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pull.PullSource, stackId) 1923 + newStack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pull.PullSource, stackId) 1923 1924 if err != nil { 1924 1925 log.Println("failed to create resubmitted stack", err) 1925 1926 s.pages.Notice(w, "pull-merge-error", "Failed to merge pull request. Try again later.") ··· 2101 2102 } 2102 2103 2103 2104 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 2104 - Repo: user.Active.Did, 2105 + Repo: userDid.String(), 2105 2106 Writes: writes, 2106 2107 }) 2107 2108 if err != nil { ··· 2380 2381 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId)) 2381 2382 } 2382 2383 2383 - func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, user *oauth.MultiAccountUser, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2384 + func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, userDid syntax.DID, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2384 2385 formatPatches, err := patchutil.ExtractPatches(patch) 2385 2386 if err != nil { 2386 2387 return nil, fmt.Errorf("Failed to extract patches: %v", err) ··· 2416 2417 Title: title, 2417 2418 Body: body, 2418 2419 TargetBranch: targetBranch, 2419 - OwnerDid: user.Active.Did, 2420 + OwnerDid: userDid.String(), 2420 2421 RepoAt: repo.RepoAt(), 2421 2422 Rkey: rkey, 2422 2423 Mentions: mentions,

History

3 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 timeout, 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
  • appview/pages/templates/user/login.html:93
expand 0 comments
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 failed, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 failed, 1/3 success
expand
expand 0 comments