repos / git-pr

a self-hosted git collaboration server
git clone https://github.com/picosh/git-pr.git

commit
47d3799
parent
1d9f49e
author
Eric Bower
date
2024-06-22 21:13:06 -0400 EDT
chore: cleanup
2 files changed,  +14, -6
M cli.go
M backend.go
+8, -0
 1@@ -31,6 +31,10 @@ func (be *Backend) Pubkey(pk ssh.PublicKey) string {
 2 	return gossh.FingerprintSHA256(pk)
 3 }
 4 
 5+func (be *Backend) KeysEqual(pka, pkb string) bool {
 6+	return pka == pkb
 7+}
 8+
 9 func (be *Backend) IsAdmin(pk ssh.PublicKey) bool {
10 	for _, apk := range be.Cfg.Admins {
11 		if ssh.KeysEqual(pk, apk) {
12@@ -39,3 +43,7 @@ func (be *Backend) IsAdmin(pk ssh.PublicKey) bool {
13 	}
14 	return false
15 }
16+
17+func (be *Backend) IsPrOwner(pka, pkb string) bool {
18+	return be.KeysEqual(pka, pkb)
19+}
M cli.go
+6, -6
 1@@ -478,15 +478,15 @@ Here's how it works:
 2 							if err != nil {
 3 								return err
 4 							}
 5-							isAdmin := be.IsAdmin(sesh.PublicKey())
 6-							isReview := cCtx.Bool("review")
 7-							isReplace := cCtx.Bool("force")
 8-							var req PatchRequest
 9-							err = be.DB.Get(&req, "SELECT * FROM patch_requests WHERE id=?", prID)
10+							prq, err := pr.GetPatchRequestByID(prID)
11 							if err != nil {
12 								return err
13 							}
14-							isPrOwner := req.Pubkey == be.Pubkey(sesh.PublicKey())
15+
16+							isAdmin := be.IsAdmin(sesh.PublicKey())
17+							isReview := cCtx.Bool("review")
18+							isReplace := cCtx.Bool("force")
19+							isPrOwner := be.IsPrOwner(prq.Pubkey, be.Pubkey(sesh.PublicKey()))
20 							if !isAdmin && !isPrOwner {
21 								return fmt.Errorf("unauthorized, you are not the owner of this PR")
22 							}