Skip to content

Commit be50c51

Browse files
committed
fix
1 parent 740b6e1 commit be50c51

File tree

8 files changed

+19
-49
lines changed

8 files changed

+19
-49
lines changed

models/unit/unit.go

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,18 @@ const (
3232
TypeActions // 10 Actions
3333
)
3434

35-
// Value returns integer value for unit type
35+
// Value returns integer value for unit type (used by template)
3636
func (u Type) Value() int {
3737
return int(u)
3838
}
3939

40-
func (u Type) String() string {
41-
switch u {
42-
case TypeCode:
43-
return "TypeCode"
44-
case TypeIssues:
45-
return "TypeIssues"
46-
case TypePullRequests:
47-
return "TypePullRequests"
48-
case TypeReleases:
49-
return "TypeReleases"
50-
case TypeUncyclo:
51-
return "TypeUncyclo"
52-
case TypeExternalUncyclo:
53-
return "TypeExternalUncyclo"
54-
case TypeExternalTracker:
55-
return "TypeExternalTracker"
56-
case TypeProjects:
57-
return "TypeProjects"
58-
case TypePackages:
59-
return "TypePackages"
60-
case TypeActions:
61-
return "TypeActions"
62-
}
63-
return fmt.Sprintf("Unknown Type %d", u)
64-
}
65-
6640
func (u Type) LogString() string {
67-
return fmt.Sprintf("<UnitType:%d:%s>", u, u.String())
41+
unit, ok := Units[u]
42+
unitName := "unknown"
43+
if ok {
44+
unitName = unit.NameKey
45+
}
46+
return fmt.Sprintf("<UnitType:%d:%s>", u, unitName)
6847
}
6948

7049
var (
@@ -119,7 +98,7 @@ func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type {
11998
units = make([]Type, 0, len(settingDefaultUnits))
12099
for _, settingUnit := range settingDefaultUnits {
121100
if !settingUnit.CanBeDefault() {
122-
log.Warn("Not allowed as default unit: %s", settingUnit.String())
101+
log.Warn("Not allowed as default unit: %s", settingUnit.LogString())
123102
continue
124103
}
125104
units = append(units, settingUnit)

services/context/context.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,9 @@ func Contexter() func(next http.Handler) http.Handler {
210210
// FIXME: do we really always need these setting? There should be someway to have to avoid having to always set these
211211
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
212212
ctx.Data["DisableStars"] = setting.Repository.DisableStars
213-
ctx.Data["EnableActions"] = setting.Actions.Enabled
213+
ctx.Data["EnableActions"] = setting.Actions.Enabled && !unit.TypeActions.UnitGlobalDisabled()
214214

215215
ctx.Data["ManifestData"] = setting.ManifestData
216-
217-
ctx.Data["UnitUncycloGlobalDisabled"] = unit.TypeUncyclo.UnitGlobalDisabled()
218-
ctx.Data["UnitIssuesGlobalDisabled"] = unit.TypeIssues.UnitGlobalDisabled()
219-
ctx.Data["UnitPullsGlobalDisabled"] = unit.TypePullRequests.UnitGlobalDisabled()
220-
ctx.Data["UnitProjectsGlobalDisabled"] = unit.TypeProjects.UnitGlobalDisabled()
221-
ctx.Data["UnitActionsGlobalDisabled"] = unit.TypeActions.UnitGlobalDisabled()
222-
223216
ctx.Data["AllLangs"] = translation.AllLangs()
224217

225218
next.ServeHTTP(ctx.Resp, ctx.Req)

templates/base/head_navbar.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
{{if and .IsSigned .MustChangePassword}}
3636
{{/* No links */}}
3737
{{else if .IsSigned}}
38-
{{if not .UnitIssuesGlobalDisabled}}
38+
{{if not ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled}}
3939
<a class="item{{if .PageIsIssues}} active{{end}}" href="{{AppSubUrl}}/issues">{{ctx.Locale.Tr "issues"}}</a>
4040
{{end}}
41-
{{if not .UnitPullsGlobalDisabled}}
41+
{{if not ctx.Consts.RepoUnitTypePullRequests.UnitGlobalDisabled}}
4242
<a class="item{{if .PageIsPulls}} active{{end}}" href="{{AppSubUrl}}/pulls">{{ctx.Locale.Tr "pull_requests"}}</a>
4343
{{end}}
44-
{{if not (and .UnitIssuesGlobalDisabled .UnitPullsGlobalDisabled)}}
44+
{{if not (and ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled ctx.Consts.RepoUnitTypePullRequests.UnitGlobalDisabled)}}
4545
{{if .ShowMilestonesDashboardPage}}
4646
<a class="item{{if .PageIsMilestonesDashboard}} active{{end}}" href="{{AppSubUrl}}/milestones">{{ctx.Locale.Tr "milestones"}}</a>
4747
{{end}}

templates/repo/header.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
</a>
163163
{{end}}
164164

165-
{{if and .EnableActions (not .UnitActionsGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
165+
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
166166
<a class="{{if .PageIsActions}}active {{end}}item" href="{{.RepoLink}}/actions">
167167
{{svg "octicon-play"}} {{ctx.Locale.Tr "actions.actions"}}
168168
{{if .Repository.NumOpenActionRuns}}
@@ -178,7 +178,7 @@
178178
{{end}}
179179

180180
{{$projectsUnit := .Repository.MustGetUnit $.Context ctx.Consts.RepoUnitTypeProjects}}
181-
{{if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeProjects) ($projectsUnit.ProjectsConfig.IsProjectsAllowed "repo")}}
181+
{{if and (not ctx.Consts.RepoUnitTypeProjects.UnitGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeProjects) ($projectsUnit.ProjectsConfig.IsProjectsAllowed "repo")}}
182182
<a href="{{.RepoLink}}/projects" class="{{if .IsProjectsPage}}active {{end}}item">
183183
{{svg "octicon-project"}} {{ctx.Locale.Tr "repo.project_board"}}
184184
{{if .Repository.NumOpenProjects}}

templates/repo/issue/view_content/comments.tmpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@
574574
{{template "repo/commits_list_small" dict "comment" . "root" $}}
575575
{{end}}
576576
{{else if eq .Type 30}}
577-
{{if not $.UnitProjectsGlobalDisabled}}
578577
<div class="timeline-item event" id="{{.HashTag}}">
579578
<span class="badge">{{svg "octicon-project"}}</span>
580579
{{template "shared/user/avatarlink" dict "user" .Poster}}
@@ -599,7 +598,6 @@
599598
{{end}}
600599
</span>
601600
</div>
602-
{{end}}
603601
{{else if eq .Type 32}}
604602
<div class="timeline-item-group">
605603
<div class="timeline-item event" id="{{.HashTag}}">

templates/repo/issue/view_content/context_menu.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{if not .ctxData.Repository.IsArchived}}
1616
{{$needDivider = true}}
1717
<div class="item context js-aria-clickable quote-reply {{if .diff}}quote-reply-diff{{end}}" data-target="{{.item.HashTag}}-raw">{{ctx.Locale.Tr "repo.issues.context.quote_reply"}}</div>
18-
{{if not .ctxData.UnitIssuesGlobalDisabled}}
18+
{{if not ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled}}
1919
<div class="item context js-aria-clickable reference-issue" data-target="{{.item.HashTag}}-raw" data-modal="#reference-issue-modal" data-poster="{{.item.Poster.GetDisplayName}}" data-poster-username="{{.item.Poster.Name}}" data-reference="{{$referenceUrl}}">{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}</div>
2020
{{end}}
2121
{{if or .ctxData.Permission.IsAdmin .IsCommentPoster .ctxData.HasIssuesOrPullsWritePermission}}

templates/repo/settings/navbar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</a>
3636
{{end}}
3737
{{end}}
38-
{{if and .EnableActions (not .UnitActionsGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
38+
{{if and .EnableActions (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
3939
<details class="item toggleable-item" {{if or .PageIsSharedSettingsRunners .PageIsSharedSettingsSecrets .PageIsSharedSettingsVariables}}open{{end}}>
4040
<summary>{{ctx.Locale.Tr "actions.actions"}}</summary>
4141
<div class="menu">

templates/user/dashboard/navbar.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@
8181
<a class="{{if .PageIsNews}}active {{end}}item tw-ml-auto" href="{{.ContextUser.DashboardLink}}{{if .Team}}/{{PathEscape .Team.Name}}{{end}}">
8282
{{svg "octicon-rss"}}&nbsp;{{ctx.Locale.Tr "activities"}}
8383
</a>
84-
{{if not .UnitIssuesGlobalDisabled}}
84+
{{if not ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled}}
8585
<a class="{{if .PageIsIssues}}active {{end}}item" href="{{.ContextUser.OrganisationLink}}/issues{{if .Team}}/{{PathEscape .Team.Name}}{{end}}">
8686
{{svg "octicon-issue-opened"}}&nbsp;{{ctx.Locale.Tr "issues"}}
8787
</a>
8888
{{end}}
89-
{{if not .UnitPullsGlobalDisabled}}
89+
{{if not ctx.Consts.RepoUnitTypePullRequests.UnitGlobalDisabled}}
9090
<a class="{{if .PageIsPulls}}active {{end}}item" href="{{.ContextUser.OrganisationLink}}/pulls{{if .Team}}/{{PathEscape .Team.Name}}{{end}}">
9191
{{svg "octicon-git-pull-request"}}&nbsp;{{ctx.Locale.Tr "pull_requests"}}
9292
</a>
9393
{{end}}
94-
{{if and .ShowMilestonesDashboardPage (not (and .UnitIssuesGlobalDisabled .UnitPullsGlobalDisabled))}}
94+
{{if and .ShowMilestonesDashboardPage (not (and ctx.Consts.RepoUnitTypeIssues.UnitGlobalDisabled ctx.Consts.RepoUnitTypePullRequests.UnitGlobalDisabled))}}
9595
<a class="{{if .PageIsMilestonesDashboard}}active {{end}}item" href="{{.ContextUser.OrganisationLink}}/milestones{{if .Team}}/{{PathEscape .Team.Name}}{{end}}">
9696
{{svg "octicon-milestone"}}&nbsp;{{ctx.Locale.Tr "milestones"}}
9797
</a>

0 commit comments

Comments
 (0)