Skip to content

Commit 7ed79b7

Browse files
GiteaBotwolfogre
andauthored
Hide code links on release page if user cannot read code (#29064) (#29066)
Backport #29064 by @wolfogre On the release list page, if the user doesn't have the permission to read code, the code links will lead to 404 pages or api errors: <img width="1297" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/a74fbc63-6dd6-43c6-853c-28acdbfdcb4e"> After this PR: <img width="1297" alt="image" src="https://github.com/go-gitea/gitea/assets/9418365/a626373d-c2df-40a9-8fed-1b12ff6bc56f"> And this PR also removed some dead code. After #23465, the tag list page has an independent template, and all `IsTag` in the release list template are always false. Co-authored-by: Jason Song <i@wolfogre.com>
1 parent b9b2ae2 commit 7ed79b7

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

templates/repo/release/list.tmpl

+5-24
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
{{range $idx, $release := .Releases}}
99
<li class="ui grid">
1010
<div class="ui four wide column meta">
11-
<a class="muted" href="{{if not .Sha1}}#{{else}}{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}}</a>
12-
{{if .Sha1}}
11+
<a class="muted" href="{{if not (and .Sha1 ($.Permission.CanRead $.UnitTypeCode))}}#{{else}}{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}{{end}}" rel="nofollow">{{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}}</a>
12+
{{if and .Sha1 ($.Permission.CanRead $.UnitTypeCode)}}
1313
<a class="muted gt-mono" href="{{$.RepoLink}}/src/commit/{{.Sha1}}" rel="nofollow">{{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}}</a>
1414
{{template "repo/branch_dropdown" dict "root" $ "release" .}}
1515
{{end}}
@@ -22,36 +22,18 @@
2222
<span class="ui yellow label">{{ctx.Locale.Tr "repo.release.draft"}}</span>
2323
{{else if .IsPrerelease}}
2424
<span class="ui orange label">{{ctx.Locale.Tr "repo.release.prerelease"}}</span>
25-
{{else if not .IsTag}}
25+
{{else}}
2626
<span class="ui green label">{{ctx.Locale.Tr "repo.release.stable"}}</span>
2727
{{end}}
2828
</h4>
2929
<div>
30-
{{if and $.CanCreateRelease (not .IsTag)}}
30+
{{if $.CanCreateRelease}}
3131
<a class="muted" data-tooltip-content="{{ctx.Locale.Tr "repo.release.edit"}}" href="{{$.RepoLink}}/releases/edit/{{.TagName | PathEscapeSegments}}" rel="nofollow">
3232
{{svg "octicon-pencil"}}
3333
</a>
3434
{{end}}
3535
</div>
3636
</div>
37-
{{if .IsTag}}
38-
<p class="text grey">
39-
{{if gt .Publisher.ID 0}}
40-
<span class="author">
41-
{{ctx.AvatarUtils.Avatar .Publisher 20 "gt-mr-2"}}
42-
<a href="{{.Publisher.HomeLink}}">{{.Publisher.Name}}</a>
43-
</span>
44-
<span class="released">
45-
{{ctx.Locale.Tr "repo.tagged_this"}}
46-
</span>
47-
{{if .CreatedUnix}}
48-
<span class="time">{{TimeSinceUnix .CreatedUnix ctx.Locale}}</span>
49-
{{end}}
50-
|
51-
{{end}}
52-
<span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}...{{.TargetBehind | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{ctx.Locale.Tr "repo.tag.ahead.target" .TargetBehind}}</span>
53-
</p>
54-
{{else}}
5537
<p class="text grey">
5638
<span class="author">
5739
{{if .OriginalAuthor}}
@@ -69,11 +51,10 @@
6951
{{if .CreatedUnix}}
7052
<span class="time">{{TimeSinceUnix .CreatedUnix ctx.Locale}}</span>
7153
{{end}}
72-
{{if not .IsDraft}}
54+
{{if and (not .IsDraft) ($.Permission.CanRead $.UnitTypeCode)}}
7355
| <span class="ahead"><a href="{{$.RepoLink}}/compare/{{.TagName | PathEscapeSegments}}...{{.TargetBehind | PathEscapeSegments}}">{{ctx.Locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}}</a> {{ctx.Locale.Tr "repo.release.ahead.target" .TargetBehind}}</span>
7456
{{end}}
7557
</p>
76-
{{end}}
7758
<div class="markup desc">
7859
{{Str2html .Note}}
7960
</div>

0 commit comments

Comments
 (0)