Skip to content

Commit ae5f917

Browse files
committed
allow plat admins to update webhooks on owner's behalf
1 parent 264369f commit ae5f917

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

api/repo.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,6 @@ func UpdateRepo(c *gin.Context) {
774774
if !r.GetAllowPull() && !r.GetAllowPush() &&
775775
!r.GetAllowDeploy() && !r.GetAllowTag() &&
776776
!r.GetAllowComment() {
777-
r.SetAllowPull(true)
778777
r.SetAllowPush(true)
779778
}
780779

@@ -832,6 +831,17 @@ func UpdateRepo(c *gin.Context) {
832831

833832
// if repo has no hook deliveries, skip webhook update
834833
if lastHook.GetWebhookID() != 0 {
834+
// if user is platform admin, fetch the repo owner token to make changes to webhook
835+
if u.GetAdmin() {
836+
u, err = database.FromContext(c).GetUser(r.GetUserID())
837+
if err != nil {
838+
retErr := fmt.Errorf("unable to get repo owner of %s for platform admin webhook update: %w", r.GetFullName(), err)
839+
840+
util.HandleError(c, http.StatusInternalServerError, retErr)
841+
842+
return
843+
}
844+
}
835845
// update webhook with new events
836846
err = scm.FromContext(c).Update(u, r, lastHook.GetWebhookID())
837847
if err != nil {

0 commit comments

Comments
 (0)