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 #6
+48 -47
appview/pulls/pulls.go
··· 920 920 fromFork := r.FormValue("fork") 921 921 sourceBranch := r.FormValue("sourceBranch") 922 922 patch := r.FormValue("patch") 923 + userDid := syntax.DID(user.Active.Did) 923 924 924 925 if targetBranch == "" { 925 926 s.pages.Notice(w, "pull", "Target branch is required.") ··· 927 928 } 928 929 929 930 // Determine PR type based on input parameters 930 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 931 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(userDid.String(), f.Knot, f.DidSlashRepo())} 931 932 isPushAllowed := roles.IsPushAllowed() 932 933 isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 933 934 isForkBased := fromFork != "" && sourceBranch != "" ··· 1005 1006 s.pages.Notice(w, "pull", "This knot doesn't support branch-based pull requests. Try another way?") 1006 1007 return 1007 1008 } 1008 - s.handleBranchBasedPull(w, r, f, user, title, body, targetBranch, sourceBranch, isStacked) 1009 + s.handleBranchBasedPull(w, r, f, userDid, title, body, targetBranch, sourceBranch, isStacked) 1009 1010 } else if isForkBased { 1010 1011 if !caps.PullRequests.ForkSubmissions { 1011 1012 s.pages.Notice(w, "pull", "This knot doesn't support fork-based pull requests. Try another way?") 1012 1013 return 1013 1014 } 1014 - s.handleForkBasedPull(w, r, f, user, fromFork, title, body, targetBranch, sourceBranch, isStacked) 1015 + s.handleForkBasedPull(w, r, f, userDid, fromFork, title, body, targetBranch, sourceBranch, isStacked) 1015 1016 } else if isPatchBased { 1016 1017 if !caps.PullRequests.PatchSubmissions { 1017 1018 s.pages.Notice(w, "pull", "This knot doesn't support patch-based pull requests. Send your patch over email.") 1018 1019 return 1019 1020 } 1020 - s.handlePatchBasedPull(w, r, f, user, title, body, targetBranch, patch, isStacked) 1021 + s.handlePatchBasedPull(w, r, f, userDid, title, body, targetBranch, patch, isStacked) 1021 1022 } 1022 1023 return 1023 1024 } ··· 1027 1028 w http.ResponseWriter, 1028 1029 r *http.Request, 1029 1030 repo *models.Repo, 1030 - user *oauth.MultiAccountUser, 1031 + userDid syntax.DID, 1031 1032 title, 1032 1033 body, 1033 1034 targetBranch, ··· 1081 1082 Sha: comparison.Rev2, 1082 1083 } 1083 1084 1084 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1085 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1085 1086 } 1086 1087 1087 - func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, title, body, targetBranch, patch string, isStacked bool) { 1088 + func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, title, body, targetBranch, patch string, isStacked bool) { 1088 1089 if err := s.validator.ValidatePatch(&patch); err != nil { 1089 1090 s.logger.Error("patch validation failed", "err", err) 1090 1091 s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.") 1091 1092 return 1092 1093 } 1093 1094 1094 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1095 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1095 1096 } 1096 1097 1097 - 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) { 1098 + 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) { 1098 1099 repoString := strings.SplitN(forkRepo, "/", 2) 1099 1100 forkOwnerDid := repoString[0] 1100 1101 repoName := repoString[1] ··· 1196 1197 Sha: sourceRev, 1197 1198 } 1198 1199 1199 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1200 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1200 1201 } 1201 1202 1202 1203 func (s *Pulls) createPullRequest( 1203 1204 w http.ResponseWriter, 1204 1205 r *http.Request, 1205 1206 repo *models.Repo, 1206 - user *oauth.MultiAccountUser, 1207 + userDid syntax.DID, 1207 1208 title, body, targetBranch string, 1208 1209 patch string, 1209 1210 combined string, ··· 1218 1219 w, 1219 1220 r, 1220 1221 repo, 1221 - user, 1222 + userDid, 1222 1223 targetBranch, 1223 1224 patch, 1224 1225 sourceRev, ··· 1275 1276 Title: title, 1276 1277 Body: body, 1277 1278 TargetBranch: targetBranch, 1278 - OwnerDid: user.Active.Did, 1279 + OwnerDid: userDid.String(), 1279 1280 RepoAt: repo.RepoAt(), 1280 1281 Rkey: rkey, 1281 1282 Mentions: mentions, ··· 1307 1308 1308 1309 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1309 1310 Collection: tangled.RepoPullNSID, 1310 - Repo: user.Active.Did, 1311 + Repo: userDid.String(), 1311 1312 Rkey: rkey, 1312 1313 Record: &lexutil.LexiconTypeDecoder{ 1313 1314 Val: &tangled.RepoPull{ ··· 1344 1345 w http.ResponseWriter, 1345 1346 r *http.Request, 1346 1347 repo *models.Repo, 1347 - user *oauth.MultiAccountUser, 1348 + userDid syntax.DID, 1348 1349 targetBranch string, 1349 1350 patch string, 1350 1351 sourceRev string, ··· 1375 1376 1376 1377 // build a stack out of this patch 1377 1378 stackId := uuid.New() 1378 - stack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pullSource, stackId.String()) 1379 + stack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pullSource, stackId.String()) 1379 1380 if err != nil { 1380 1381 log.Println("failed to create stack", err) 1381 1382 s.pages.Notice(w, "pull", fmt.Sprintf("Failed to create stack: %v", err)) ··· 1412 1413 }) 1413 1414 } 1414 1415 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 1415 - Repo: user.Active.Did, 1416 + Repo: userDid.String(), 1416 1417 Writes: writes, 1417 1418 }) 1418 1419 if err != nil { ··· 1666 1667 return 1667 1668 } 1668 1669 1669 - f, err := s.repoResolver.Resolve(r) 1670 - if err != nil { 1671 - log.Println("failed to get repo and knot", err) 1670 + if user == nil || user.Active.Did != pull.OwnerDid { 1671 + log.Println("unauthorized user") 1672 + w.WriteHeader(http.StatusUnauthorized) 1672 1673 return 1673 1674 } 1674 1675 1675 - if user.Active.Did != pull.OwnerDid { 1676 - log.Println("unauthorized user") 1677 - w.WriteHeader(http.StatusUnauthorized) 1676 + f, err := s.repoResolver.Resolve(r) 1677 + if err != nil { 1678 + log.Println("failed to get repo and knot", err) 1678 1679 return 1679 1680 } 1680 1681 1681 1682 patch := r.FormValue("patch") 1682 1683 1683 - s.resubmitPullHelper(w, r, f, user, pull, patch, "", "") 1684 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, "", "") 1684 1685 } 1685 1686 1686 1687 func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { ··· 1693 1694 return 1694 1695 } 1695 1696 1696 - f, err := s.repoResolver.Resolve(r) 1697 - if err != nil { 1698 - log.Println("failed to get repo and knot", err) 1697 + if user == nil || user.Active.Did != pull.OwnerDid { 1698 + log.Println("unauthorized user") 1699 + w.WriteHeader(http.StatusUnauthorized) 1699 1700 return 1700 1701 } 1701 1702 1702 - if user.Active.Did != pull.OwnerDid { 1703 - log.Println("unauthorized user") 1704 - w.WriteHeader(http.StatusUnauthorized) 1703 + f, err := s.repoResolver.Resolve(r) 1704 + if err != nil { 1705 + log.Println("failed to get repo and knot", err) 1705 1706 return 1706 1707 } 1707 1708 ··· 1745 1746 patch := comparison.FormatPatchRaw 1746 1747 combined := comparison.CombinedPatchRaw 1747 1748 1748 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1749 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1749 1750 } 1750 1751 1751 1752 func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { ··· 1758 1759 return 1759 1760 } 1760 1761 1761 - f, err := s.repoResolver.Resolve(r) 1762 - if err != nil { 1763 - log.Println("failed to get repo and knot", err) 1762 + if user == nil || user.Active.Did != pull.OwnerDid { 1763 + log.Println("unauthorized user") 1764 + w.WriteHeader(http.StatusUnauthorized) 1764 1765 return 1765 1766 } 1766 1767 1767 - if user.Active.Did != pull.OwnerDid { 1768 - log.Println("unauthorized user") 1769 - w.WriteHeader(http.StatusUnauthorized) 1768 + f, err := s.repoResolver.Resolve(r) 1769 + if err != nil { 1770 + log.Println("failed to get repo and knot", err) 1770 1771 return 1771 1772 } 1772 1773 ··· 1842 1843 patch := comparison.FormatPatchRaw 1843 1844 combined := comparison.CombinedPatchRaw 1844 1845 1845 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1846 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1846 1847 } 1847 1848 1848 1849 func (s *Pulls) resubmitPullHelper( 1849 1850 w http.ResponseWriter, 1850 1851 r *http.Request, 1851 1852 repo *models.Repo, 1852 - user *oauth.MultiAccountUser, 1853 + userDid syntax.DID, 1853 1854 pull *models.Pull, 1854 1855 patch string, 1855 1856 combined string, ··· 1857 1858 ) { 1858 1859 if pull.IsStacked() { 1859 1860 log.Println("resubmitting stacked PR") 1860 - s.resubmitStackedPullHelper(w, r, repo, user, pull, patch, pull.StackId) 1861 + s.resubmitStackedPullHelper(w, r, repo, userDid, pull, patch, pull.StackId) 1861 1862 return 1862 1863 } 1863 1864 ··· 1905 1906 return 1906 1907 } 1907 1908 1908 - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Active.Did, pull.Rkey) 1909 + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, userDid.String(), pull.Rkey) 1909 1910 if err != nil { 1910 1911 // failed to get record 1911 1912 s.pages.Notice(w, "resubmit-error", "Failed to update pull, no record found on PDS.") ··· 1928 1929 1929 1930 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1930 1931 Collection: tangled.RepoPullNSID, 1931 - Repo: user.Active.Did, 1932 + Repo: userDid.String(), 1932 1933 Rkey: pull.Rkey, 1933 1934 SwapRecord: ex.Cid, 1934 1935 Record: &lexutil.LexiconTypeDecoder{ ··· 1955 1956 w http.ResponseWriter, 1956 1957 r *http.Request, 1957 1958 repo *models.Repo, 1958 - user *oauth.MultiAccountUser, 1959 + userDid syntax.DID, 1959 1960 pull *models.Pull, 1960 1961 patch string, 1961 1962 stackId string, ··· 1963 1964 targetBranch := pull.TargetBranch 1964 1965 1965 1966 origStack, _ := r.Context().Value("stack").(models.Stack) 1966 - newStack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pull.PullSource, stackId) 1967 + newStack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pull.PullSource, stackId) 1967 1968 if err != nil { 1968 1969 log.Println("failed to create resubmitted stack", err) 1969 1970 s.pages.Notice(w, "pull-merge-error", "Failed to merge pull request. Try again later.") ··· 2145 2146 } 2146 2147 2147 2148 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 2148 - Repo: user.Active.Did, 2149 + Repo: userDid.String(), 2149 2150 Writes: writes, 2150 2151 }) 2151 2152 if err != nil { ··· 2424 2425 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId)) 2425 2426 } 2426 2427 2427 - func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, user *oauth.MultiAccountUser, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2428 + func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, userDid syntax.DID, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2428 2429 formatPatches, err := patchutil.ExtractPatches(patch) 2429 2430 if err != nil { 2430 2431 return nil, fmt.Errorf("Failed to extract patches: %v", err) ··· 2460 2461 Title: title, 2461 2462 Body: body, 2462 2463 TargetBranch: targetBranch, 2463 - OwnerDid: user.Active.Did, 2464 + OwnerDid: userDid.String(), 2464 2465 RepoAt: repo.RepoAt(), 2465 2466 Rkey: rkey, 2466 2467 Mentions: mentions,

History

9 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
3/3 success
expand
no conflicts, ready to merge
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
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 timeout, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
1/3 failed, 2/3 success
expand
expand 0 comments
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
3/3 success
expand
expand 0 comments
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 timeout, 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
1 commit
expand
appview/pulls: remove dependencies to oauth.MultiAccountUser
2/3 failed, 1/3 success
expand
expand 0 comments