diff options
Diffstat (limited to 'routers/private')
-rw-r--r-- | routers/private/hook_post_receive.go | 26 | ||||
-rw-r--r-- | routers/private/hook_verification_test.go | 4 | ||||
-rw-r--r-- | routers/private/serv.go | 8 |
3 files changed, 19 insertions, 19 deletions
diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 8b1e849e7a..e8bef7d6c1 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -207,25 +207,19 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { return } - cols := make([]string, 0, 2) - - if isPrivate.Has() { + // FIXME: these options are not quite right, for example: changing visibility should do more works than just setting the is_private flag + // These options should only be used for "push-to-create" + if isPrivate.Has() && repo.IsPrivate != isPrivate.Value() { + // TODO: it needs to do more work repo.IsPrivate = isPrivate.Value() - cols = append(cols, "is_private") + if err = repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "is_private"); err != nil { + ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{Err: "Failed to change visibility"}) + } } - - if isTemplate.Has() { + if isTemplate.Has() && repo.IsTemplate != isTemplate.Value() { repo.IsTemplate = isTemplate.Value() - cols = append(cols, "is_template") - } - - if len(cols) > 0 { - if err := repo_model.UpdateRepositoryCols(ctx, repo, cols...); err != nil { - log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err) - ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ - Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err), - }) - return + if err = repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "is_template"); err != nil { + ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{Err: "Failed to change template status"}) } } } diff --git a/routers/private/hook_verification_test.go b/routers/private/hook_verification_test.go index f6c2e1087f..8653e34daa 100644 --- a/routers/private/hook_verification_test.go +++ b/routers/private/hook_verification_test.go @@ -18,7 +18,9 @@ func TestVerifyCommits(t *testing.T) { unittest.PrepareTestEnv(t) gitRepo, err := git.OpenRepository(t.Context(), testReposDir+"repo1_hook_verification") - defer gitRepo.Close() + if err != nil { + defer gitRepo.Close() + } assert.NoError(t, err) objectFormat, err := gitRepo.GetObjectFormat() diff --git a/routers/private/serv.go b/routers/private/serv.go index 37fbc0730c..b879be0dc2 100644 --- a/routers/private/serv.go +++ b/routers/private/serv.go @@ -81,6 +81,7 @@ func ServCommand(ctx *context.PrivateContext) { ownerName := ctx.PathParam("owner") repoName := ctx.PathParam("repo") mode := perm.AccessMode(ctx.FormInt("mode")) + verb := ctx.FormString("verb") // Set the basic parts of the results to return results := private.ServCommandResults{ @@ -295,8 +296,11 @@ func ServCommand(ctx *context.PrivateContext) { return } } else { - // Because of the special ref "refs/for" we will need to delay write permission check - if git.DefaultFeatures().SupportProcReceive && unitType == unit.TypeCode { + // Because of the special ref "refs/for" (AGit) we will need to delay write permission check, + // AGit flow needs to write its own ref when the doer has "reader" permission (allowing to create PR). + // The real permission check is done in HookPreReceive (routers/private/hook_pre_receive.go). + // Here it should relax the permission check for "git push (git-receive-pack)", but not for others like LFS operations. + if git.DefaultFeatures().SupportProcReceive && unitType == unit.TypeCode && verb == git.CmdVerbReceivePack { mode = perm.AccessModeRead } |