Skip to content

Commit 9192fad

Browse files
committed
fix
1 parent 58b204b commit 9192fad

File tree

20 files changed

+356
-350
lines changed

20 files changed

+356
-350
lines changed

routers/web/web.go

Lines changed: 264 additions & 253 deletions
Large diffs are not rendered by default.

services/context/context.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ func NewTemplateContextForWeb(ctx *Context) TemplateContext {
102102
tmplCtx["Locale"] = ctx.Base.Locale
103103
tmplCtx["AvatarUtils"] = templates.NewAvatarUtils(ctx)
104104
tmplCtx["RootData"] = ctx.Data
105+
tmplCtx["Consts"] = map[string]any{
106+
"RepoUnitTypeCode": unit.TypeCode,
107+
"RepoUnitTypeIssues": unit.TypeIssues,
108+
"RepoUnitTypePullRequests": unit.TypePullRequests,
109+
"RepoUnitTypeReleases": unit.TypeReleases,
110+
"RepoUnitTypeWiki": unit.TypeWiki,
111+
"RepoUnitTypeExternalWiki": unit.TypeExternalWiki,
112+
"RepoUnitTypeExternalTracker": unit.TypeExternalTracker,
113+
"RepoUnitTypeProjects": unit.TypeProjects,
114+
"RepoUnitTypePackages": unit.TypePackages,
115+
"RepoUnitTypeActions": unit.TypeActions,
116+
}
105117
return tmplCtx
106118
}
107119

services/context/repo.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ func repoAssignment(ctx *Context, repo *repo_model.Repository) {
383383
ctx.NotFound("no access right", nil)
384384
return
385385
}
386-
ctx.Data["HasAccess"] = true
387386
ctx.Data["Permission"] = &ctx.Repo.Permission
388387

389388
if repo.IsMirror {
@@ -1052,19 +1051,3 @@ func GitHookService() func(ctx *Context) {
10521051
}
10531052
}
10541053
}
1055-
1056-
// UnitTypes returns a middleware to set unit types to context variables.
1057-
func UnitTypes() func(ctx *Context) {
1058-
return func(ctx *Context) {
1059-
ctx.Data["UnitTypeCode"] = unit_model.TypeCode
1060-
ctx.Data["UnitTypeIssues"] = unit_model.TypeIssues
1061-
ctx.Data["UnitTypePullRequests"] = unit_model.TypePullRequests
1062-
ctx.Data["UnitTypeReleases"] = unit_model.TypeReleases
1063-
ctx.Data["UnitTypeWiki"] = unit_model.TypeWiki
1064-
ctx.Data["UnitTypeExternalWiki"] = unit_model.TypeExternalWiki
1065-
ctx.Data["UnitTypeExternalTracker"] = unit_model.TypeExternalTracker
1066-
ctx.Data["UnitTypeProjects"] = unit_model.TypeProjects
1067-
ctx.Data["UnitTypePackages"] = unit_model.TypePackages
1068-
ctx.Data["UnitTypeActions"] = unit_model.TypeActions
1069-
}
1070-
}

templates/explore/navbar.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a class="{{if .PageIsExploreOrganizations}}active {{end}}item" href="{{AppSubUrl}}/explore/organizations">
1212
{{svg "octicon-organization"}} {{ctx.Locale.Tr "explore.organizations"}}
1313
</a>
14-
{{if and (not $.UnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
14+
{{if and (not ctx.Consts.RepoUnitTypeCode.UnitGlobalDisabled) .IsRepoIndexerEnabled}}
1515
<a class="{{if .PageIsExploreCode}}active {{end}}item" href="{{AppSubUrl}}/explore/code">
1616
{{svg "octicon-code"}} {{ctx.Locale.Tr "explore.code"}}
1717
</a>

templates/repo/blame.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</table>
8181
{{end}}{{/* end if .IsFileTooLarge */}}
8282
<div class="code-line-menu tippy-target">
83-
{{if $.Permission.CanRead $.UnitTypeIssues}}
83+
{{if $.Permission.CanRead ctx.Consts.RepoUnitTypeIssues}}
8484
<a class="item ref-in-new-issue" role="menuitem" data-url-issue-new="{{.RepoLink}}/issues/new" data-url-param-body-link="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}" rel="nofollow noindex">{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}</a>
8585
{{end}}
8686
<a class="item copy-line-permalink" role="menuitem" data-url="{{.Repository.Link}}/src/commit/{{PathEscape .CommitID}}/{{PathEscapeSegments .TreePath}}{{if $.HasSourceRenderedToggle}}?display=source{{end}}">{{ctx.Locale.Tr "repo.file_copy_permalink"}}</a>

templates/repo/code_frequency.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{if .Permission.CanRead $.UnitTypeCode}}
1+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-code-frequency-chart"
33
data-locale-loading-title="{{ctx.Locale.Tr "graphs.component_loading" (ctx.Locale.Tr "graphs.code_frequency.what")}}"
44
data-locale-loading-title-failed="{{ctx.Locale.Tr "graphs.component_loading_failed" (ctx.Locale.Tr "graphs.code_frequency.what")}}"

templates/repo/commit_page.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<a class="ui primary tiny button" href="{{.SourcePath}}">
2626
{{ctx.Locale.Tr "repo.diff.browse_source"}}
2727
</a>
28-
{{if and ($.Permission.CanWrite $.UnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}{{- /* */ -}}
28+
{{if and ($.Permission.CanWrite ctx.Consts.RepoUnitTypeCode) (not $.Repository.IsArchived) (not .IsDeleted)}}{{- /* */ -}}
2929
<div class="ui dropdown primary tiny button">
3030
{{ctx.Locale.Tr "repo.commit.operations"}}
3131
{{svg "octicon-triangle-down" 14 "dropdown icon"}}

templates/repo/contributors.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{if .Permission.CanRead $.UnitTypeCode}}
1+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-contributors-chart"
33
data-locale-filter-label="{{ctx.Locale.Tr "repo.contributors.contribution_type.filter_label"}}"
44
data-locale-contribution-type-commits="{{ctx.Locale.Tr "repo.contributors.contribution_type.commits"}}"

templates/repo/graph/commits.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
{{if eq $refGroup "pull"}}
3838
{{if or (not $.HidePRRefs) (SliceUtils.Contains $.SelectedBranches .Name)}}
3939
<!-- it's intended to use issues not pulls, if it's a pull you will get redirected -->
40-
<a class="ui labelled basic tiny button" href="{{$.RepoLink}}/{{if $.Repository.UnitEnabled $.Context $.UnitTypePullRequests}}pulls{{else}}issues{{end}}/{{.ShortName|PathEscape}}">
40+
<a class="ui labelled basic tiny button" href="{{$.RepoLink}}/{{if $.Repository.UnitEnabled $.Context ctx.Consts.RepoUnitTypePullRequests}}pulls{{else}}issues{{end}}/{{.ShortName|PathEscape}}">
4141
{{svg "octicon-git-pull-request"}} #{{.ShortName}}
4242
</a>
4343
{{end}}

templates/repo/header.tmpl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
{{if not $.DisableStars}}
6565
{{template "repo/star_unstar" $}}
6666
{{end}}
67-
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
67+
{{if and (not .IsEmpty) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
6868
<div class="ui labeled button
6969
{{if or (not $.IsSigned) (and (not $.CanSignedUserFork) (not $.UserAndOrgForks))}}
7070
disabled
@@ -131,13 +131,13 @@
131131
<overflow-menu class="ui container secondary pointing tabular top attached borderless menu tw-pt-0 tw-my-0">
132132
{{if not (or .Repository.IsBeingCreated .Repository.IsBroken)}}
133133
<div class="overflow-menu-items">
134-
{{if .Permission.CanRead $.UnitTypeCode}}
134+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
135135
<a class="{{if .PageIsViewCode}}active {{end}}item" href="{{.RepoLink}}{{if and (ne .BranchName .Repository.DefaultBranch) (not $.PageIsWiki)}}/src/{{.BranchNameSubURL}}{{end}}">
136136
{{svg "octicon-code"}} {{ctx.Locale.Tr "repo.code"}}
137137
</a>
138138
{{end}}
139139

140-
{{if .Permission.CanRead $.UnitTypeIssues}}
140+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeIssues}}
141141
<a class="{{if .PageIsIssueList}}active {{end}}item" href="{{.RepoLink}}/issues">
142142
{{svg "octicon-issue-opened"}} {{ctx.Locale.Tr "repo.issues"}}
143143
{{if .Repository.NumOpenIssues}}
@@ -146,13 +146,13 @@
146146
</a>
147147
{{end}}
148148

149-
{{if .Permission.CanRead $.UnitTypeExternalTracker}}
149+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeExternalTracker}}
150150
<a class="{{if .PageIsIssueList}}active {{end}}item" href="{{.RepoExternalIssuesLink}}" target="_blank" rel="noopener noreferrer">
151151
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.issues"}}
152152
</a>
153153
{{end}}
154154

155-
{{if and .Repository.CanEnablePulls (.Permission.CanRead $.UnitTypePullRequests)}}
155+
{{if and .Repository.CanEnablePulls (.Permission.CanRead ctx.Consts.RepoUnitTypePullRequests)}}
156156
<a class="{{if .PageIsPullList}}active {{end}}item" href="{{.RepoLink}}/pulls">
157157
{{svg "octicon-git-pull-request"}} {{ctx.Locale.Tr "repo.pulls"}}
158158
{{if .Repository.NumOpenPulls}}
@@ -161,7 +161,7 @@
161161
</a>
162162
{{end}}
163163

164-
{{if and .EnableActions (not .UnitActionsGlobalDisabled) (.Permission.CanRead $.UnitTypeActions)}}
164+
{{if and .EnableActions (not .UnitActionsGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeActions)}}
165165
<a class="{{if .PageIsActions}}active {{end}}item" href="{{.RepoLink}}/actions">
166166
{{svg "octicon-play"}} {{ctx.Locale.Tr "actions.actions"}}
167167
{{if .Repository.NumOpenActionRuns}}
@@ -170,14 +170,14 @@
170170
</a>
171171
{{end}}
172172

173-
{{if .Permission.CanRead $.UnitTypePackages}}
173+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypePackages}}
174174
<a href="{{.RepoLink}}/packages" class="{{if .IsPackagesPage}}active {{end}}item">
175175
{{svg "octicon-package"}} {{ctx.Locale.Tr "packages.title"}}
176176
</a>
177177
{{end}}
178178

179-
{{$projectsUnit := .Repository.MustGetUnit $.Context $.UnitTypeProjects}}
180-
{{if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead $.UnitTypeProjects) ($projectsUnit.ProjectsConfig.IsProjectsAllowed "repo")}}
179+
{{$projectsUnit := .Repository.MustGetUnit $.Context ctx.Consts.RepoUnitTypeProjects}}
180+
{{if and (not .UnitProjectsGlobalDisabled) (.Permission.CanRead ctx.Consts.RepoUnitTypeProjects) ($projectsUnit.ProjectsConfig.IsProjectsAllowed "repo")}}
181181
<a href="{{.RepoLink}}/projects" class="{{if .IsProjectsPage}}active {{end}}item">
182182
{{svg "octicon-project"}} {{ctx.Locale.Tr "repo.project_board"}}
183183
{{if .Repository.NumOpenProjects}}
@@ -186,7 +186,7 @@
186186
</a>
187187
{{end}}
188188

189-
{{if and (.Permission.CanRead $.UnitTypeReleases) (not .IsEmptyRepo)}}
189+
{{if and (.Permission.CanRead ctx.Consts.RepoUnitTypeReleases) (not .IsEmptyRepo)}}
190190
<a class="{{if or .PageIsReleaseList .PageIsTagList}}active {{end}}item" href="{{.RepoLink}}/releases">
191191
{{svg "octicon-tag"}} {{ctx.Locale.Tr "repo.releases"}}
192192
{{if .NumReleases}}
@@ -195,19 +195,19 @@
195195
</a>
196196
{{end}}
197197

198-
{{if .Permission.CanRead $.UnitTypeWiki}}
198+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeWiki}}
199199
<a class="{{if .PageIsWiki}}active {{end}}item" href="{{.RepoLink}}/wiki">
200200
{{svg "octicon-book"}} {{ctx.Locale.Tr "repo.wiki"}}
201201
</a>
202202
{{end}}
203203

204-
{{if .Permission.CanRead $.UnitTypeExternalWiki}}
205-
<a class="item" href="{{(.Repository.MustGetUnit $.Context $.UnitTypeExternalWiki).ExternalWikiConfig.ExternalWikiURL}}" target="_blank" rel="noopener noreferrer">
204+
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeExternalWiki}}
205+
<a class="item" href="{{(.Repository.MustGetUnit $.Context ctx.Consts.RepoUnitTypeExternalWiki).ExternalWikiConfig.ExternalWikiURL}}" target="_blank" rel="noopener noreferrer">
206206
{{svg "octicon-link-external"}} {{ctx.Locale.Tr "repo.wiki"}}
207207
</a>
208208
{{end}}
209209

210-
{{if and (.Permission.CanReadAny $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) (not .IsEmptyRepo)}}
210+
{{if and (.Permission.CanReadAny ctx.Consts.RepoUnitTypePullRequests ctx.Consts.RepoUnitTypeIssues ctx.Consts.RepoUnitTypeReleases) (not .IsEmptyRepo)}}
211211
<a class="{{if .PageIsActivity}}active {{end}}item" href="{{.RepoLink}}/activity">
212212
{{svg "octicon-pulse"}} {{ctx.Locale.Tr "repo.activity"}}
213213
</a>

0 commit comments

Comments
 (0)