Range-diff rd-5
- title
- feat: static assets folder
- description
-
Patch equal - old #1
66cafc6- new #1
cc56ea1
- title
- fix(cli): access control for removing patchsets
- description
-
Patch removed - old #2
5e76ed3- new #0
(none)
- title
- review: typo and future enhancement comment
- description
-
Patch added - old #0
(none)- new #2
ef749a4
1: 66cafc6 = 1: cc56ea1 feat: static assets folder
2: 5e76ed3 < -: ------- fix(cli): access control for removing patchsets
old
old:
cli.go
new:cli.go
if err != nil { return err } - return pr.DeletePatchsetByID(patchsetID) + + patchset, err := pr.GetPatchsetByID(patchsetID) + if err != nil { + return err + } + + user, err := pr.GetUserByID(patchset.UserID) + if err != nil { + return err + } + + pk := sesh.PublicKey() + isAdmin := be.IsAdmin(pk) + isContrib := pubkey == user.Pubkey + if !isAdmin && !isContrib { + return fmt.Errorf("you are not authorized to delete a patchset") + } + + err = pr.DeletePatchsetByID(patchsetID) + if err != nil { + return err + } + wish.Printf(sesh, "successfully removed patchset: %d\n", patchsetID) + return nil }, }, }, return err } - user, err := pr.UpsertUser(pubkey, userName) + patchReq, err := pr.GetPatchRequestByID(prID) if err != nil { return err } - patchReq, err := pr.GetPatchRequestByID(prID) + user, err := pr.GetUserByID(patchReq.UserID) if err != nil { return err } + pk := sesh.PublicKey() - isContrib := be.Pubkey(pk) == user.Pubkey + isContrib := pubkey == user.Pubkey isAdmin := be.IsAdmin(pk) if !isAdmin && !isContrib { return fmt.Errorf("you are not authorized to change PR status") return err } - user, err := pr.UpsertUser(pubkey, userName) + user, err := pr.GetUserByID(patchReq.UserID) if err != nil { return err } pk := sesh.PublicKey() - isContrib := be.Pubkey(pk) == user.Pubkey + isContrib := pubkey == user.Pubkey isAdmin := be.IsAdmin(pk) if !isAdmin && !isContrib { return fmt.Errorf("you are not authorized to change PR status")
new
old
old:
pr.go
new:pr.go
GetPatchRequests() ([]*PatchRequest, error) GetPatchRequestsByRepoID(repoID string) ([]*PatchRequest, error) GetPatchsetsByPrID(prID int64) ([]*Patchset, error) + GetPatchsetByID(patchsetID int64) (*Patchset, error) GetLatestPatchsetByPrID(prID int64) (*Patchset, error) GetPatchesByPatchsetID(prID int64) ([]*Patch, error) UpdatePatchRequestStatus(prID, userID int64, status string) error return patchsets, nil } +func (pr PrCmd) GetPatchsetByID(patchsetID int64) (*Patchset, error) { + var patchset Patchset + err := pr.Backend.DB.Get( + &patchset, + "SELECT * FROM patchsets WHERE id=?", + patchsetID, + ) + return &patchset, err +} + func (pr PrCmd) GetLatestPatchsetByPrID(prID int64) (*Patchset, error) { patchsets, err := pr.GetPatchsetsByPrID(prID) if err != nil {
new
-: ------- > 2: ef749a4 review: typo and future enhancement comment