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 #8
+48 -47
appview/pulls/pulls.go
··· 923 923 fromFork := r.FormValue("fork") 924 924 sourceBranch := r.FormValue("sourceBranch") 925 925 patch := r.FormValue("patch") 926 + userDid := syntax.DID(user.Active.Did) 926 927 927 928 if targetBranch == "" { 928 929 s.pages.Notice(w, "pull", "Target branch is required.") ··· 930 931 } 931 932 932 933 // Determine PR type based on input parameters 933 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 934 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(userDid.String(), f.Knot, f.DidSlashRepo())} 934 935 isPushAllowed := roles.IsPushAllowed() 935 936 isBranchBased := isPushAllowed && sourceBranch != "" && fromFork == "" 936 937 isForkBased := fromFork != "" && sourceBranch != "" ··· 1008 1009 s.pages.Notice(w, "pull", "This knot doesn't support branch-based pull requests. Try another way?") 1009 1010 return 1010 1011 } 1011 - s.handleBranchBasedPull(w, r, f, user, title, body, targetBranch, sourceBranch, isStacked) 1012 + s.handleBranchBasedPull(w, r, f, userDid, title, body, targetBranch, sourceBranch, isStacked) 1012 1013 } else if isForkBased { 1013 1014 if !caps.PullRequests.ForkSubmissions { 1014 1015 s.pages.Notice(w, "pull", "This knot doesn't support fork-based pull requests. Try another way?") 1015 1016 return 1016 1017 } 1017 - s.handleForkBasedPull(w, r, f, user, fromFork, title, body, targetBranch, sourceBranch, isStacked) 1018 + s.handleForkBasedPull(w, r, f, userDid, fromFork, title, body, targetBranch, sourceBranch, isStacked) 1018 1019 } else if isPatchBased { 1019 1020 if !caps.PullRequests.PatchSubmissions { 1020 1021 s.pages.Notice(w, "pull", "This knot doesn't support patch-based pull requests. Send your patch over email.") 1021 1022 return 1022 1023 } 1023 - s.handlePatchBasedPull(w, r, f, user, title, body, targetBranch, patch, isStacked) 1024 + s.handlePatchBasedPull(w, r, f, userDid, title, body, targetBranch, patch, isStacked) 1024 1025 } 1025 1026 return 1026 1027 } ··· 1030 1031 w http.ResponseWriter, 1031 1032 r *http.Request, 1032 1033 repo *models.Repo, 1033 - user *oauth.MultiAccountUser, 1034 + userDid syntax.DID, 1034 1035 title, 1035 1036 body, 1036 1037 targetBranch, ··· 1084 1085 Sha: comparison.Rev2, 1085 1086 } 1086 1087 1087 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1088 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1088 1089 } 1089 1090 1090 - func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, user *oauth.MultiAccountUser, title, body, targetBranch, patch string, isStacked bool) { 1091 + func (s *Pulls) handlePatchBasedPull(w http.ResponseWriter, r *http.Request, repo *models.Repo, userDid syntax.DID, title, body, targetBranch, patch string, isStacked bool) { 1091 1092 if err := s.validator.ValidatePatch(&patch); err != nil { 1092 1093 s.logger.Error("patch validation failed", "err", err) 1093 1094 s.pages.Notice(w, "pull", "Invalid patch format. Please provide a valid diff.") 1094 1095 return 1095 1096 } 1096 1097 1097 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1098 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, "", "", nil, nil, isStacked) 1098 1099 } 1099 1100 1100 - 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) { 1101 + 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) { 1101 1102 repoString := strings.SplitN(forkRepo, "/", 2) 1102 1103 forkOwnerDid := repoString[0] 1103 1104 repoName := repoString[1] ··· 1199 1200 Sha: sourceRev, 1200 1201 } 1201 1202 1202 - s.createPullRequest(w, r, repo, user, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1203 + s.createPullRequest(w, r, repo, userDid, title, body, targetBranch, patch, combined, sourceRev, pullSource, recordPullSource, isStacked) 1203 1204 } 1204 1205 1205 1206 func (s *Pulls) createPullRequest( 1206 1207 w http.ResponseWriter, 1207 1208 r *http.Request, 1208 1209 repo *models.Repo, 1209 - user *oauth.MultiAccountUser, 1210 + userDid syntax.DID, 1210 1211 title, body, targetBranch string, 1211 1212 patch string, 1212 1213 combined string, ··· 1221 1222 w, 1222 1223 r, 1223 1224 repo, 1224 - user, 1225 + userDid, 1225 1226 targetBranch, 1226 1227 patch, 1227 1228 sourceRev, ··· 1278 1279 Title: title, 1279 1280 Body: body, 1280 1281 TargetBranch: targetBranch, 1281 - OwnerDid: user.Active.Did, 1282 + OwnerDid: userDid.String(), 1282 1283 RepoAt: repo.RepoAt(), 1283 1284 Rkey: rkey, 1284 1285 Mentions: mentions, ··· 1310 1311 1311 1312 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1312 1313 Collection: tangled.RepoPullNSID, 1313 - Repo: user.Active.Did, 1314 + Repo: userDid.String(), 1314 1315 Rkey: rkey, 1315 1316 Record: &lexutil.LexiconTypeDecoder{ 1316 1317 Val: &tangled.RepoPull{ ··· 1347 1348 w http.ResponseWriter, 1348 1349 r *http.Request, 1349 1350 repo *models.Repo, 1350 - user *oauth.MultiAccountUser, 1351 + userDid syntax.DID, 1351 1352 targetBranch string, 1352 1353 patch string, 1353 1354 sourceRev string, ··· 1378 1379 1379 1380 // build a stack out of this patch 1380 1381 stackId := uuid.New() 1381 - stack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pullSource, stackId.String()) 1382 + stack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pullSource, stackId.String()) 1382 1383 if err != nil { 1383 1384 log.Println("failed to create stack", err) 1384 1385 s.pages.Notice(w, "pull", fmt.Sprintf("Failed to create stack: %v", err)) ··· 1415 1416 }) 1416 1417 } 1417 1418 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 1418 - Repo: user.Active.Did, 1419 + Repo: userDid.String(), 1419 1420 Writes: writes, 1420 1421 }) 1421 1422 if err != nil { ··· 1669 1670 return 1670 1671 } 1671 1672 1672 - f, err := s.repoResolver.Resolve(r) 1673 - if err != nil { 1674 - log.Println("failed to get repo and knot", err) 1673 + if user == nil || user.Active.Did != pull.OwnerDid { 1674 + log.Println("unauthorized user") 1675 + w.WriteHeader(http.StatusUnauthorized) 1675 1676 return 1676 1677 } 1677 1678 1678 - if user.Active.Did != pull.OwnerDid { 1679 - log.Println("unauthorized user") 1680 - w.WriteHeader(http.StatusUnauthorized) 1679 + f, err := s.repoResolver.Resolve(r) 1680 + if err != nil { 1681 + log.Println("failed to get repo and knot", err) 1681 1682 return 1682 1683 } 1683 1684 1684 1685 patch := r.FormValue("patch") 1685 1686 1686 - s.resubmitPullHelper(w, r, f, user, pull, patch, "", "") 1687 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, "", "") 1687 1688 } 1688 1689 1689 1690 func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { ··· 1696 1697 return 1697 1698 } 1698 1699 1699 - f, err := s.repoResolver.Resolve(r) 1700 - if err != nil { 1701 - log.Println("failed to get repo and knot", err) 1700 + if user == nil || user.Active.Did != pull.OwnerDid { 1701 + log.Println("unauthorized user") 1702 + w.WriteHeader(http.StatusUnauthorized) 1702 1703 return 1703 1704 } 1704 1705 1705 - if user.Active.Did != pull.OwnerDid { 1706 - log.Println("unauthorized user") 1707 - w.WriteHeader(http.StatusUnauthorized) 1706 + f, err := s.repoResolver.Resolve(r) 1707 + if err != nil { 1708 + log.Println("failed to get repo and knot", err) 1708 1709 return 1709 1710 } 1710 1711 ··· 1748 1749 patch := comparison.FormatPatchRaw 1749 1750 combined := comparison.CombinedPatchRaw 1750 1751 1751 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1752 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1752 1753 } 1753 1754 1754 1755 func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { ··· 1761 1762 return 1762 1763 } 1763 1764 1764 - f, err := s.repoResolver.Resolve(r) 1765 - if err != nil { 1766 - log.Println("failed to get repo and knot", err) 1765 + if user == nil || user.Active.Did != pull.OwnerDid { 1766 + log.Println("unauthorized user") 1767 + w.WriteHeader(http.StatusUnauthorized) 1767 1768 return 1768 1769 } 1769 1770 1770 - if user.Active.Did != pull.OwnerDid { 1771 - log.Println("unauthorized user") 1772 - w.WriteHeader(http.StatusUnauthorized) 1771 + f, err := s.repoResolver.Resolve(r) 1772 + if err != nil { 1773 + log.Println("failed to get repo and knot", err) 1773 1774 return 1774 1775 } 1775 1776 ··· 1845 1846 patch := comparison.FormatPatchRaw 1846 1847 combined := comparison.CombinedPatchRaw 1847 1848 1848 - s.resubmitPullHelper(w, r, f, user, pull, patch, combined, sourceRev) 1849 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1849 1850 } 1850 1851 1851 1852 func (s *Pulls) resubmitPullHelper( 1852 1853 w http.ResponseWriter, 1853 1854 r *http.Request, 1854 1855 repo *models.Repo, 1855 - user *oauth.MultiAccountUser, 1856 + userDid syntax.DID, 1856 1857 pull *models.Pull, 1857 1858 patch string, 1858 1859 combined string, ··· 1860 1861 ) { 1861 1862 if pull.IsStacked() { 1862 1863 log.Println("resubmitting stacked PR") 1863 - s.resubmitStackedPullHelper(w, r, repo, user, pull, patch, pull.StackId) 1864 + s.resubmitStackedPullHelper(w, r, repo, userDid, pull, patch, pull.StackId) 1864 1865 return 1865 1866 } 1866 1867 ··· 1908 1909 return 1909 1910 } 1910 1911 1911 - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Active.Did, pull.Rkey) 1912 + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, userDid.String(), pull.Rkey) 1912 1913 if err != nil { 1913 1914 // failed to get record 1914 1915 s.pages.Notice(w, "resubmit-error", "Failed to update pull, no record found on PDS.") ··· 1931 1932 1932 1933 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1933 1934 Collection: tangled.RepoPullNSID, 1934 - Repo: user.Active.Did, 1935 + Repo: userDid.String(), 1935 1936 Rkey: pull.Rkey, 1936 1937 SwapRecord: ex.Cid, 1937 1938 Record: &lexutil.LexiconTypeDecoder{ ··· 1958 1959 w http.ResponseWriter, 1959 1960 r *http.Request, 1960 1961 repo *models.Repo, 1961 - user *oauth.MultiAccountUser, 1962 + userDid syntax.DID, 1962 1963 pull *models.Pull, 1963 1964 patch string, 1964 1965 stackId string, ··· 1966 1967 targetBranch := pull.TargetBranch 1967 1968 1968 1969 origStack, _ := r.Context().Value("stack").(models.Stack) 1969 - newStack, err := s.newStack(r.Context(), repo, user, targetBranch, patch, pull.PullSource, stackId) 1970 + newStack, err := s.newStack(r.Context(), repo, userDid, targetBranch, patch, pull.PullSource, stackId) 1970 1971 if err != nil { 1971 1972 log.Println("failed to create resubmitted stack", err) 1972 1973 s.pages.Notice(w, "pull-merge-error", "Failed to merge pull request. Try again later.") ··· 2148 2149 } 2149 2150 2150 2151 _, err = comatproto.RepoApplyWrites(r.Context(), client, &comatproto.RepoApplyWrites_Input{ 2151 - Repo: user.Active.Did, 2152 + Repo: userDid.String(), 2152 2153 Writes: writes, 2153 2154 }) 2154 2155 if err != nil { ··· 2427 2428 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", ownerSlashRepo, pull.PullId)) 2428 2429 } 2429 2430 2430 - func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, user *oauth.MultiAccountUser, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2431 + func (s *Pulls) newStack(ctx context.Context, repo *models.Repo, userDid syntax.DID, targetBranch, patch string, pullSource *models.PullSource, stackId string) (models.Stack, error) { 2431 2432 formatPatches, err := patchutil.ExtractPatches(patch) 2432 2433 if err != nil { 2433 2434 return nil, fmt.Errorf("Failed to extract patches: %v", err) ··· 2463 2464 Title: title, 2464 2465 Body: body, 2465 2466 TargetBranch: targetBranch, 2466 - OwnerDid: user.Active.Did, 2467 + OwnerDid: userDid.String(), 2467 2468 RepoAt: repo.RepoAt(), 2468 2469 Rkey: rkey, 2469 2470 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