Skip to content

Commit aac4916

Browse files
committed
move 'enable actions' to general page
1 parent 72ab4ba commit aac4916

File tree

7 files changed

+65
-31
lines changed

7 files changed

+65
-31
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3911,13 +3911,13 @@ logs.always_auto_scroll = Always auto scroll logs
39113911
logs.always_expand_running = Always expand running logs
39123912

39133913
general = General
3914+
general.enable_actions = Enable Actions
39143915
general.collaborative_owners_management = Collaborative Owners Management
39153916
general.collaborative_owners_management_help = A collaborative owner is a user or an organization whose private repository has access to the actions and workflows of this repository.
39163917
general.add_collaborative_owner = Add Collaborative Owner
39173918
general.collaborative_owner_not_exist = The collaborative owner does not exist.
39183919
general.remove_collaborative_owner = Remove Collaborative Owner
39193920
general.remove_collaborative_owner_desc = Removing a collaborative owner will prevent the repositories of the owner from accessing the actions in this repository. Continue?
3920-
general.collaborative_owner_not_required = The actions and workflows of a public repository are always accessible to other repositories. You do not need to specify collaborative owners.
39213921

39223922
[projects]
39233923
deleted.display_name = Deleted Project

routers/web/repo/setting/actions.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/templates"
1515
"code.gitea.io/gitea/modules/util"
1616
"code.gitea.io/gitea/services/context"
17+
repo_service "code.gitea.io/gitea/services/repository"
1718
)
1819

1920
const tplRepoActionsGeneralSettings templates.TplName = "repo/settings/actions"
@@ -23,12 +24,17 @@ func ActionsGeneralSettings(ctx *context.Context) {
2324
ctx.Data["PageType"] = "general"
2425
ctx.Data["PageIsActionsSettingsGeneral"] = true
2526

27+
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
28+
if err != nil && !repo_model.IsErrUnitTypeNotExist(err) {
29+
ctx.ServerError("GetUnit", err)
30+
return
31+
}
32+
if actionsUnit == nil { // no actions unit
33+
ctx.HTML(http.StatusOK, tplRepoActionsGeneralSettings)
34+
return
35+
}
36+
2637
if ctx.Repo.Repository.IsPrivate {
27-
actionsUnit, err := ctx.Repo.Repository.GetUnit(ctx, unit_model.TypeActions)
28-
if err != nil {
29-
ctx.ServerError("GetUnit", err)
30-
return
31-
}
3238
collaborativeOwnerIDs := actionsUnit.ActionsConfig().CollaborativeOwnerIDs
3339
collaborativeOwners, err := user_model.GetUsersByIDs(ctx, collaborativeOwnerIDs)
3440
if err != nil {
@@ -41,6 +47,27 @@ func ActionsGeneralSettings(ctx *context.Context) {
4147
ctx.HTML(http.StatusOK, tplRepoActionsGeneralSettings)
4248
}
4349

50+
func ActionsUnitPost(ctx *context.Context) {
51+
redirectURL := ctx.Repo.RepoLink + "/settings/actions/general"
52+
enableActionsUnit := ctx.FormBool("enable_actions")
53+
repo := ctx.Repo.Repository
54+
55+
var err error
56+
if enableActionsUnit && !unit_model.TypeActions.UnitGlobalDisabled() {
57+
err = repo_service.UpdateRepositoryUnits(ctx, repo, []repo_model.RepoUnit{newRepoUnit(repo, unit_model.TypeActions, nil)}, nil)
58+
} else if !unit_model.TypeActions.UnitGlobalDisabled() {
59+
err = repo_service.UpdateRepositoryUnits(ctx, repo, nil, []unit_model.Type{unit_model.TypeActions})
60+
}
61+
62+
if err != nil {
63+
ctx.ServerError("UpdateRepositoryUnits", err)
64+
return
65+
}
66+
67+
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
68+
ctx.Redirect(redirectURL)
69+
}
70+
4471
func AddCollaborativeOwner(ctx *context.Context) {
4572
redirectURL := ctx.Repo.RepoLink + "/settings/actions/general"
4673
name := strings.ToLower(ctx.FormString("collaborative_owner"))

routers/web/repo/setting/setting.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,6 @@ func handleSettingsPostAdvanced(ctx *context.Context) {
614614
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePackages)
615615
}
616616

617-
if form.EnableActions && !unit_model.TypeActions.UnitGlobalDisabled() {
618-
units = append(units, newRepoUnit(repo, unit_model.TypeActions, nil))
619-
} else if !unit_model.TypeActions.UnitGlobalDisabled() {
620-
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeActions)
621-
}
622-
623617
if form.EnablePulls && !unit_model.TypePullRequests.UnitGlobalDisabled() {
624618
units = append(units, newRepoUnit(repo, unit_model.TypePullRequests, &repo_model.PullRequestsConfig{
625619
IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace,

routers/web/web.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,13 +1159,16 @@ func registerWebRoutes(m *web.Router) {
11591159
m.Post("/{lid}/unlock", repo_setting.LFSUnlock)
11601160
})
11611161
})
1162+
m.Group("/actions/general", func() {
1163+
m.Get("", repo_setting.ActionsGeneralSettings)
1164+
m.Post("/actions_unit", repo_setting.ActionsUnitPost)
1165+
})
11621166
m.Group("/actions", func() {
11631167
m.Get("", shared_actions.RedirectToDefaultSetting)
11641168
addSettingsRunnersRoutes()
11651169
addSettingsSecretsRoutes()
11661170
addSettingsVariablesRoutes()
11671171
m.Group("/general", func() {
1168-
m.Get("", repo_setting.ActionsGeneralSettings)
11691172
m.Group("/collaborative_owner", func() {
11701173
m.Post("/add", repo_setting.AddCollaborativeOwner)
11711174
m.Post("/delete", repo_setting.DeleteCollaborativeOwner)

templates/repo/settings/actions_general.tmpl

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
<div class="repo-setting-content">
22
<h4 class="ui top attached header">
3-
{{ctx.Locale.Tr "actions.general.collaborative_owners_management"}}
3+
{{ctx.Locale.Tr "actions.general.enable_actions"}}
44
</h4>
5-
{{if not .Repository.IsPrivate}}
65
<div class="ui attached segment">
7-
{{ctx.Locale.Tr "actions.general.collaborative_owner_not_required"}}
6+
<form class="ui form" action="{{.Link}}/actions_unit" method="post">
7+
{{.CsrfTokenHtml}}
8+
{{$isActionsEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypeActions}}
9+
{{$isActionsGlobalDisabled := ctx.Consts.RepoUnitTypeActions.UnitGlobalDisabled}}
10+
<div class="inline field">
11+
<label>{{ctx.Locale.Tr "actions.actions"}}</label>
12+
<div class="ui checkbox{{if $isActionsGlobalDisabled}} disabled{{end}}"{{if $isActionsGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
13+
<input class="enable-system" name="enable_actions" type="checkbox" {{if $isActionsGlobalDisabled}}disabled{{end}} {{if $isActionsEnabled}}checked{{end}}>
14+
<label>{{ctx.Locale.Tr "repo.settings.actions_desc"}}</label>
15+
</div>
16+
</div>
17+
{{if not $isActionsGlobalDisabled}}
18+
<div class="divider"></div>
19+
<div class="field">
20+
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.update_settings"}}</button>
21+
</div>
22+
{{end}}
23+
</form>
824
</div>
9-
{{else}}
25+
26+
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
27+
<h4 class="ui top attached header">
28+
{{ctx.Locale.Tr "actions.general.collaborative_owners_management"}}
29+
</h4>
30+
{{if .Repository.IsPrivate}}
1031
{{if len .CollaborativeOwners}}
1132
<div class="ui attached segment">
1233
<div class="flex-list">
@@ -42,6 +63,7 @@
4263
{{ctx.Locale.Tr "actions.general.collaborative_owners_management_help"}}
4364
</div>
4465
{{end}}
66+
{{end}}
4567
</div>
4668

4769
<div class="ui g-modal-confirm delete modal">

templates/repo/settings/navbar.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
</a>
3939
{{end}}
4040
{{end}}
41-
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
4241
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables .PageIsActionsSettingsGeneral}}open{{end}}>
4342
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
4443
<div class="menu">
4544
<a class="{{if .PageIsActionsSettingsGeneral}}active {{end}}item" href="{{.RepoLink}}/settings/actions/general">
4645
{{ctx.Locale.Tr "actions.general"}}
4746
</a>
47+
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
4848
<a class="{{if .PageIsSharedSettingsRunners}}active {{end}}item" href="{{.RepoLink}}/settings/actions/runners">
4949
{{ctx.Locale.Tr "actions.runners"}}
5050
</a>
@@ -54,8 +54,8 @@
5454
<a class="{{if .PageIsSharedSettingsVariables}}active {{end}}item" href="{{.RepoLink}}/settings/actions/variables">
5555
{{ctx.Locale.Tr "actions.variables"}}
5656
</a>
57+
{{end}}
5758
</div>
5859
</details>
59-
{{end}}
6060
</div>
6161
</div>

templates/repo/settings/options.tmpl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,18 +509,6 @@
509509
</div>
510510
</div>
511511

512-
{{if .EnableActions}}
513-
{{$isActionsEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypeActions}}
514-
{{$isActionsGlobalDisabled := ctx.Consts.RepoUnitTypeActions.UnitGlobalDisabled}}
515-
<div class="inline field">
516-
<label>{{ctx.Locale.Tr "actions.actions"}}</label>
517-
<div class="ui checkbox{{if $isActionsGlobalDisabled}} disabled{{end}}"{{if $isActionsGlobalDisabled}} data-tooltip-content="{{ctx.Locale.Tr "repo.unit_disabled"}}"{{end}}>
518-
<input class="enable-system" name="enable_actions" type="checkbox" {{if $isActionsEnabled}}checked{{end}}>
519-
<label>{{ctx.Locale.Tr "repo.settings.actions_desc"}}</label>
520-
</div>
521-
</div>
522-
{{end}}
523-
524512
{{if not .IsMirror}}
525513
<div class="divider"></div>
526514
{{$pullRequestEnabled := .Repository.UnitEnabled ctx ctx.Consts.RepoUnitTypePullRequests}}

0 commit comments

Comments
 (0)