From a01777fd21eebf85c630e28befb3366b1c169ec0 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 6 Feb 2024 19:57:25 +0800 Subject: [PATCH] [gitea] Hide code links on release page if user cannot read code (#29064) 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: image After this PR: image 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. (cherry picked from commit f9072dbf3c558ba5d4365b551d95936a52e4c94d) --- templates/repo/release/list.tmpl | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index ccea14c4e2..fb2fce2950 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -8,8 +8,8 @@ {{range $idx, $release := .Releases}}
  • - {{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}} - {{if .Sha1}} + {{svg "octicon-tag" 16 "gt-mr-2"}}{{.TagName}} + {{if and .Sha1 ($.Permission.CanRead $.UnitTypeCode)}} {{svg "octicon-git-commit" 16 "gt-mr-2"}}{{ShortSha .Sha1}} {{template "repo/branch_dropdown" dict "root" $ "release" .}} {{end}} @@ -22,36 +22,18 @@ {{ctx.Locale.Tr "repo.release.draft"}} {{else if .IsPrerelease}} {{ctx.Locale.Tr "repo.release.prerelease"}} - {{else if not .IsTag}} + {{else}} {{ctx.Locale.Tr "repo.release.stable"}} {{end}}
    - {{if and $.CanCreateRelease (not .IsTag)}} + {{if $.CanCreateRelease}} {{svg "octicon-pencil"}} {{end}}
    - {{if .IsTag}} -

    - {{if gt .Publisher.ID 0}} - - {{ctx.AvatarUtils.Avatar .Publisher 20 "gt-mr-2"}} - {{.Publisher.Name}} - - - {{ctx.Locale.Tr "repo.tagged_this"}} - - {{if .CreatedUnix}} - {{TimeSinceUnix .CreatedUnix ctx.Locale}} - {{end}} - | - {{end}} - {{ctx.Locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}} {{ctx.Locale.Tr "repo.tag.ahead.target" .TargetBehind}} -

    - {{else}}

    {{if .OriginalAuthor}} @@ -69,11 +51,10 @@ {{if .CreatedUnix}} {{TimeSinceUnix .CreatedUnix ctx.Locale}} {{end}} - {{if not .IsDraft}} + {{if and (not .IsDraft) ($.Permission.CanRead $.UnitTypeCode)}} | {{ctx.Locale.Tr "repo.release.ahead.commits" .NumCommitsBehind | Str2html}} {{ctx.Locale.Tr "repo.release.ahead.target" .TargetBehind}} {{end}}

    - {{end}}
    {{Str2html .Note}}