git-pr
created pr with
3.1
added 3.2
1: 3b99dc0 < -: ------- feat: static assets
2: 8919af5 ! 1: 66cafc6 feat: static assets folder
3: 7346122 ! 2: 5e76ed3 fix(cli): access control for removing patchsets
4: d8792d5 < -: ------- feat: static folder
pr_reviewed
changed status to
reviewed
added 3.4
1: cc56ea1 = 1: 0467f9e feat: static assets folder
2: ef749a4 = 2: da1730f review: typo and future enhancement comment
-: ------- > 3: c038404 refactor: per-file override for static folder
changed status to
accepted
cmds
checkout latest patchset:
ssh pr.pico.sh print 3 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 3.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 3set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 3set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 3
Patchset
3.2
fix(cli): access control for removing patchsets
Eric Bower
2024-07-19T16:20:18ZI also fixed some other access control issues for changing PR status.
Semantic diff summary
1 added,
4 modified,
0 signature changed,
0 removed
across 2 analyzed files
+30
-6
cli.go
#
| ... | ... | @@ -213,7 +213,30 @@ Here's how it works: | |
| 213 | 213 | if err != nil { | |
| 214 | 214 | return err | |
| 215 | 215 | } | |
| 216 | - | return pr.DeletePatchsetByID(patchsetID) | |
| 216 | + | ||
| 217 | + | patchset, err := pr.GetPatchsetByID(patchsetID) | |
| 218 | + | if err != nil { | |
| 219 | + | return err | |
| 220 | + | } | |
| 221 | + | ||
| 222 | + | user, err := pr.GetUserByID(patchset.UserID) | |
| 223 | + | if err != nil { | |
| 224 | + | return err | |
| 225 | + | } | |
| 226 | + | ||
| 227 | + | pk := sesh.PublicKey() | |
| 228 | + | isAdmin := be.IsAdmin(pk) | |
| 229 | + | isContrib := pubkey == user.Pubkey | |
| 230 | + | if !isAdmin && !isContrib { | |
| 231 | + | return fmt.Errorf("you are not authorized to delete a patchset") | |
| 232 | + | } | |
| 233 | + | ||
| 234 | + | err = pr.DeletePatchsetByID(patchsetID) | |
| 235 | + | if err != nil { | |
| 236 | + | return err | |
| 237 | + | } | |
| 238 | + | wish.Printf(sesh, "successfully removed patchset: %d\n", patchsetID) | |
| 239 | + | return nil | |
| 217 | 240 | }, | |
| 218 | 241 | }, | |
| 219 | 242 | }, |
| ... | ... | @@ -597,17 +620,18 @@ Here's how it works: | |
| 597 | 620 | return err | |
| 598 | 621 | } | |
| 599 | 622 | ||
| 600 | - | user, err := pr.UpsertUser(pubkey, userName) | |
| 623 | + | patchReq, err := pr.GetPatchRequestByID(prID) | |
| 601 | 624 | if err != nil { | |
| 602 | 625 | return err | |
| 603 | 626 | } | |
| 604 | 627 | ||
| 605 | - | patchReq, err := pr.GetPatchRequestByID(prID) | |
| 628 | + | user, err := pr.GetUserByID(patchReq.UserID) | |
| 606 | 629 | if err != nil { | |
| 607 | 630 | return err | |
| 608 | 631 | } | |
| 632 | + | ||
| 609 | 633 | pk := sesh.PublicKey() | |
| 610 | - | isContrib := be.Pubkey(pk) == user.Pubkey | |
| 634 | + | isContrib := pubkey == user.Pubkey | |
| 611 | 635 | isAdmin := be.IsAdmin(pk) | |
| 612 | 636 | if !isAdmin && !isContrib { | |
| 613 | 637 | return fmt.Errorf("you are not authorized to change PR status") |
| ... | ... | @@ -645,13 +669,13 @@ Here's how it works: | |
| 645 | 669 | return err | |
| 646 | 670 | } | |
| 647 | 671 | ||
| 648 | - | user, err := pr.UpsertUser(pubkey, userName) | |
| 672 | + | user, err := pr.GetUserByID(patchReq.UserID) | |
| 649 | 673 | if err != nil { | |
| 650 | 674 | return err | |
| 651 | 675 | } | |
| 652 | 676 | ||
| 653 | 677 | pk := sesh.PublicKey() | |
| 654 | - | isContrib := be.Pubkey(pk) == user.Pubkey | |
| 678 | + | isContrib := pubkey == user.Pubkey | |
| 655 | 679 | isAdmin := be.IsAdmin(pk) | |
| 656 | 680 | if !isAdmin && !isContrib { | |
| 657 | 681 | return fmt.Errorf("you are not authorized to change PR status") |
+11
-0
pr.go
#
| ... | ... | @@ -34,6 +34,7 @@ type GitPatchRequest interface { | |
| 34 | 34 | GetPatchRequests() ([]*PatchRequest, error) | |
| 35 | 35 | GetPatchRequestsByRepoID(repoID string) ([]*PatchRequest, error) | |
| 36 | 36 | GetPatchsetsByPrID(prID int64) ([]*Patchset, error) | |
| 37 | + | GetPatchsetByID(patchsetID int64) (*Patchset, error) | |
| 37 | 38 | GetLatestPatchsetByPrID(prID int64) (*Patchset, error) | |
| 38 | 39 | GetPatchesByPatchsetID(prID int64) ([]*Patch, error) | |
| 39 | 40 | UpdatePatchRequestStatus(prID, userID int64, status string) error |
| ... | ... | @@ -234,6 +235,16 @@ func (pr PrCmd) GetPatchsetsByPrID(prID int64) ([]*Patchset, error) { | |
| 234 | 235 | return patchsets, nil | |
| 235 | 236 | } | |
| 236 | 237 | ||
| 238 | + | func (pr PrCmd) GetPatchsetByID(patchsetID int64) (*Patchset, error) { | |
| 239 | + | var patchset Patchset | |
| 240 | + | err := pr.Backend.DB.Get( | |
| 241 | + | &patchset, | |
| 242 | + | "SELECT * FROM patchsets WHERE id=?", | |
| 243 | + | patchsetID, | |
| 244 | + | ) | |
| 245 | + | return &patchset, err | |
| 246 | + | } | |
| 247 | + | ||
| 237 | 248 | func (pr PrCmd) GetLatestPatchsetByPrID(prID int64) (*Patchset, error) { | |
| 238 | 249 | patchsets, err := pr.GetPatchsetsByPrID(prID) | |
| 239 | 250 | if err != nil { |