add ActionsGeneralSettingsPost

This commit is contained in:
Zettat123 2024-11-20 13:03:23 +08:00
parent 833def96cf
commit f73073df41
3 changed files with 41 additions and 6 deletions

View File

@ -6,18 +6,46 @@ package setting
import (
"net/http"
repo_model "code.gitea.io/gitea/models/repo"
unit_model "code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/services/context"
)
const (
tplRepoActionsGeneral base.TplName = "repo/settings/actions"
tplRepoActionsGeneralSettings base.TplName = "repo/settings/actions"
)
func ActionsGeneral(ctx *context.Context) {
func ActionsGeneralSettings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("actions.general")
ctx.Data["PageType"] = "general"
ctx.Data["PageIsActionsSettingsGeneral"] = true
ctx.HTML(http.StatusOK, tplRepoActionsGeneral)
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
if err != nil {
ctx.ServerError("GetUnit", err)
return
}
actionsCfg := actionsUnit.ActionsConfig()
ctx.Data["AccessibleFromOtherRepos"] = actionsCfg.AccessbleFromOtherRepos
ctx.HTML(http.StatusOK, tplRepoActionsGeneralSettings)
}
func ActionsGeneralSettingsPost(ctx *context.Context) {
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
if err != nil {
ctx.ServerError("GetUnit", err)
return
}
actionsCfg := actionsUnit.ActionsConfig()
actionsCfg.AccessbleFromOtherRepos = ctx.FormBool("actions_accessible_from_other_repositories")
if err := repo_model.UpdateRepoUnit(ctx, actionsUnit); err != nil {
ctx.ServerError("UpdateRepoUnit", err)
return
}
ctx.Redirect(ctx.Repo.RepoLink + "/settings/actions/general")
}

View File

@ -1133,7 +1133,9 @@ func registerRoutes(m *web.Router) {
addSettingsRunnersRoutes()
addSettingsSecretsRoutes()
addSettingsVariablesRoutes()
m.Get("/general", repo_setting.ActionsGeneral)
m.Combo("/general").
Get(repo_setting.ActionsGeneralSettings).
Post(repo_setting.ActionsGeneralSettingsPost)
}, actions.MustEnableActions)
// the follow handler must be under "settings", otherwise this incomplete repo can't be accessed
m.Group("/migrate", func() {

View File

@ -3,14 +3,19 @@
{{ctx.Locale.Tr "actions.general.settings"}}
</h4>
<div class="ui attached segment">
<form class="ui form" method="post">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div id="actions_accessible_from_other_repositories_box" class="field">
<div class="ui checkbox">
<input id="actions_accessible_from_other_repositories" name="actions_accessible_from_other_repositories" type="checkbox">
<input id="actions_accessible_from_other_repositories" name="actions_accessible_from_other_repositories" type="checkbox" {{if .AccessibleFromOtherRepos}}checked{{end}}>
<label>{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories" .Owner.Name}}</label>
<p class="help">{{ctx.Locale.Tr "actions.general.actions_accessible_from_other_repositories_desc" .Owner.Name}}</p>
</div>
</div>
<div class="divider"></div>
<div class="field">
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
</div>
</form>
</div>
</div>