Skip to content

Commit 98ef79d

Browse files
authored
allow action user have read permission in public repo like other user (#36095)
related #28187 --------- Signed-off-by: a1012112796 <[email protected]>
1 parent b41ccb0 commit 98ef79d

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

models/perm/access/repo_permission.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,14 @@ func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Reposito
276276
if !actionsCfg.IsCollaborativeOwner(taskRepo.OwnerID) || !taskRepo.IsPrivate {
277277
// The task repo can access the current repo only if the task repo is private and
278278
// the owner of the task repo is a collaborative owner of the current repo.
279-
// FIXME allow public repo read access if tokenless pull is enabled
280279
// FIXME should owner's visibility also be considered here?
280+
281+
// check permission like simple user but limit to read-only
282+
perm, err = GetUserRepoPermission(ctx, repo, user_model.NewActionsUser())
283+
if err != nil {
284+
return perm, err
285+
}
286+
perm.AccessMode = min(perm.AccessMode, perm_model.AccessModeRead)
281287
return perm, nil
282288
}
283289
accessMode = perm_model.AccessModeRead
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package integration
5+
6+
import (
7+
"net/http"
8+
"testing"
9+
10+
"code.gitea.io/gitea/modules/setting"
11+
api "code.gitea.io/gitea/modules/structs"
12+
"code.gitea.io/gitea/modules/test"
13+
"code.gitea.io/gitea/tests"
14+
15+
"github.com/stretchr/testify/assert"
16+
)
17+
18+
func testActionUserSignIn(t *testing.T) {
19+
req := NewRequest(t, "GET", "/api/v1/user").
20+
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
21+
resp := MakeRequest(t, req, http.StatusOK)
22+
23+
var u api.User
24+
DecodeJSON(t, resp, &u)
25+
assert.Equal(t, "gitea-actions", u.UserName)
26+
}
27+
28+
func testActionUserAccessPublicRepo(t *testing.T) {
29+
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md").
30+
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
31+
resp := MakeRequest(t, req, http.StatusOK)
32+
assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type"))
33+
34+
defer test.MockVariableValue(&setting.Service.RequireSignInViewStrict, true)()
35+
36+
req = NewRequestf(t, "GET", "/api/v1/repos/user2/repo1/raw/README.md").
37+
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
38+
resp = MakeRequest(t, req, http.StatusOK)
39+
assert.Equal(t, "file", resp.Header().Get("x-gitea-object-type"))
40+
}
41+
42+
func testActionUserNoAccessOtherPrivateRepo(t *testing.T) {
43+
req := NewRequestf(t, "GET", "/api/v1/repos/user2/repo2/raw/README.md").
44+
AddTokenAuth("8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
45+
MakeRequest(t, req, http.StatusNotFound)
46+
}
47+
48+
func TestActionUserAccessPermission(t *testing.T) {
49+
defer tests.PrepareTestEnv(t)()
50+
51+
t.Run("ActionUserSignIn", testActionUserSignIn)
52+
t.Run("ActionUserAccessPublicRepo", testActionUserAccessPublicRepo)
53+
t.Run("ActionUserNoAccessOtherPrivateRepo", testActionUserNoAccessOtherPrivateRepo)
54+
}

0 commit comments

Comments
 (0)