Skip to content

Commit 833def9

Browse files
committed
actions from private repos
1 parent 5eb0ee4 commit 833def9

File tree

8 files changed

+63
-4
lines changed

8 files changed

+63
-4
lines changed

models/repo/repo_unit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
169169
}
170170

171171
type ActionsConfig struct {
172-
DisabledWorkflows []string
172+
DisabledWorkflows []string
173+
AccessbleFromOtherRepos bool
173174
}
174175

175176
func (cfg *ActionsConfig) EnableWorkflow(file string) {

options/locale/locale_en-US.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,6 +3751,11 @@ variables.creation.success = The variable "%s" has been added.
37513751
variables.update.failed = Failed to edit variable.
37523752
variables.update.success = The variable has been edited.
37533753

3754+
general = General
3755+
general.settings = Actions General Settings
3756+
general.actions_accessible_from_other_repositories = Accessible from repositories owned by '%s'
3757+
general.actions_accessible_from_other_repositories_desc = Workflows in other repositories that are owned by the user '%s' can access the actions and reusable workflows in this repository. Access is allowed only from private repositories.
3758+
37543759
[projects]
37553760
deleted.display_name = Deleted Project
37563761
type-1.display_name = Individual Project

routers/web/repo/githttp.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ func httpBase(ctx *context.Context) *serviceHandler {
195195
return nil
196196
}
197197
if task.RepoID != repo.ID {
198-
ctx.PlainText(http.StatusForbidden, "User permission denied")
199-
return nil
198+
taskRepo, err := repo_model.GetRepositoryByID(ctx, task.RepoID)
199+
if err != nil {
200+
ctx.ServerError("GetRepositoryByID", err)
201+
return nil
202+
}
203+
actionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
204+
if !taskRepo.IsPrivate || taskRepo.OwnerID != repo.OwnerID || !actionsCfg.AccessbleFromOtherRepos {
205+
ctx.PlainText(http.StatusForbidden, "User permission denied")
206+
return nil
207+
}
200208
}
201209

202210
if task.IsForkPullRequest {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package setting
5+
6+
import (
7+
"net/http"
8+
9+
"code.gitea.io/gitea/modules/base"
10+
"code.gitea.io/gitea/services/context"
11+
)
12+
13+
const (
14+
tplRepoActionsGeneral base.TplName = "repo/settings/actions"
15+
)
16+
17+
func ActionsGeneral(ctx *context.Context) {
18+
ctx.Data["Title"] = ctx.Tr("actions.general")
19+
ctx.Data["PageType"] = "general"
20+
ctx.Data["PageIsActionsSettingsGeneral"] = true
21+
22+
ctx.HTML(http.StatusOK, tplRepoActionsGeneral)
23+
}

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ func registerRoutes(m *web.Router) {
11331133
addSettingsRunnersRoutes()
11341134
addSettingsSecretsRoutes()
11351135
addSettingsVariablesRoutes()
1136+
m.Get("/general", repo_setting.ActionsGeneral)
11361137
}, actions.MustEnableActions)
11371138
// the follow handler must be under "settings", otherwise this incomplete repo can't be accessed
11381139
m.Group("/migrate", func() {

templates/repo/settings/actions.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
{{template "shared/secrets/add_list" .}}
77
{{else if eq .PageType "variables"}}
88
{{template "shared/variables/variable_list" .}}
9+
{{else if eq .PageType "general"}}
10+
{{template "repo/settings/actions_general" .}}
911
{{end}}
1012
</div>
1113
{{template "repo/settings/layout_footer" .}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="repo-setting-content">
2+
<h4 class="ui top attached header">
3+
{{ctx.Locale.Tr "actions.general.settings"}}
4+
</h4>
5+
<div class="ui attached segment">
6+
<form class="ui form" method="post">
7+
<div id="actions_accessible_from_other_repositories_box" class="field">
8+
<div class="ui checkbox">
9+
<input id="actions_accessible_from_other_repositories" name="actions_accessible_from_other_repositories" type="checkbox">
10+
<label>{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories" .Owner.Name}}</label>
11+
<p class="help">{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories_desc" .Owner.Name}}</p>
12+
</div>
13+
</div>
14+
</form>
15+
</div>
16+
</div>

templates/repo/settings/navbar.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{{end}}
3535
{{end}}
3636
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
37-
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
37+
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables .PageIsActionsSettingsGeneral}}open{{end}}>
3838
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
3939
<div class="menu">
4040
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.RepoLink}}/settings/actions/runners">
@@ -46,6 +46,9 @@
4646
<a class="{{if .PageIsSharedSettingsVariables}}active {{end}}item" href="{{.RepoLink}}/settings/actions/variables">
4747
{{ctx.Locale.Tr "actions.variables"}}
4848
</a>
49+
<a class="{{if .PageIsActionsSettingsGeneral}}active {{end}}item" href="{{.RepoLink}}/settings/actions/general">
50+
{{ctx.Locale.Tr "actions.general"}}
51+
</a>
4952
</div>
5053
</details>
5154
{{end}}

0 commit comments

Comments
 (0)