Skip to content

Commit f73073d

Browse files
committed
add ActionsGeneralSettingsPost
1 parent 833def9 commit f73073d

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

routers/web/repo/setting/actions.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,46 @@ package setting
66
import (
77
"net/http"
88

9+
repo_model "code.gitea.io/gitea/models/repo"
10+
unit_model "code.gitea.io/gitea/models/unit"
911
"code.gitea.io/gitea/modules/base"
1012
"code.gitea.io/gitea/services/context"
1113
)
1214

1315
const (
14-
tplRepoActionsGeneral base.TplName = "repo/settings/actions"
16+
tplRepoActionsGeneralSettings base.TplName = "repo/settings/actions"
1517
)
1618

17-
func ActionsGeneral(ctx *context.Context) {
19+
func ActionsGeneralSettings(ctx *context.Context) {
1820
ctx.Data["Title"] = ctx.Tr("actions.general")
1921
ctx.Data["PageType"] = "general"
2022
ctx.Data["PageIsActionsSettingsGeneral"] = true
2123

22-
ctx.HTML(http.StatusOK, tplRepoActionsGeneral)
24+
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
25+
if err != nil {
26+
ctx.ServerError("GetUnit", err)
27+
return
28+
}
29+
actionsCfg := actionsUnit.ActionsConfig()
30+
31+
ctx.Data["AccessibleFromOtherRepos"] = actionsCfg.AccessbleFromOtherRepos
32+
33+
ctx.HTML(http.StatusOK, tplRepoActionsGeneralSettings)
34+
}
35+
36+
func ActionsGeneralSettingsPost(ctx *context.Context) {
37+
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
38+
if err != nil {
39+
ctx.ServerError("GetUnit", err)
40+
return
41+
}
42+
actionsCfg := actionsUnit.ActionsConfig()
43+
actionsCfg.AccessbleFromOtherRepos = ctx.FormBool("actions_accessible_from_other_repositories")
44+
45+
if err := repo_model.UpdateRepoUnit(ctx, actionsUnit); err != nil {
46+
ctx.ServerError("UpdateRepoUnit", err)
47+
return
48+
}
49+
50+
ctx.Redirect(ctx.Repo.RepoLink + "/settings/actions/general")
2351
}

routers/web/web.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,9 @@ func registerRoutes(m *web.Router) {
11331133
addSettingsRunnersRoutes()
11341134
addSettingsSecretsRoutes()
11351135
addSettingsVariablesRoutes()
1136-
m.Get("/general", repo_setting.ActionsGeneral)
1136+
m.Combo("/general").
1137+
Get(repo_setting.ActionsGeneralSettings).
1138+
Post(repo_setting.ActionsGeneralSettingsPost)
11371139
}, actions.MustEnableActions)
11381140
// the follow handler must be under "settings", otherwise this incomplete repo can't be accessed
11391141
m.Group("/migrate", func() {

templates/repo/settings/actions_general.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
{{ctx.Locale.Tr "actions.general.settings"}}
44
</h4>
55
<div class="ui attached segment">
6-
<form class="ui form" method="post">
6+
<form class="ui form" action="{{.Link}}" method="post">
7+
{{.CsrfTokenHtml}}
78
<div id="actions_accessible_from_other_repositories_box" class="field">
89
<div class="ui checkbox">
9-
<input id="actions_accessible_from_other_repositories" name="actions_accessible_from_other_repositories" type="checkbox">
10+
<input id="actions_accessible_from_other_repositories" name="actions_accessible_from_other_repositories" type="checkbox" {{if .AccessibleFromOtherRepos}}checked{{end}}>
1011
<label>{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories" .Owner.Name}}</label>
1112
<p class="help">{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories_desc" .Owner.Name}}</p>
1213
</div>
1314
</div>
15+
<div class="divider"></div>
16+
<div class="field">
17+
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
18+
</div>
1419
</form>
1520
</div>
1621
</div>

0 commit comments

Comments
 (0)