Highlight signed tags like signed commits

This makes signed tags show a badge in the tag list similar to signed
commits in the commit list, and a more verbose block when viewing a
single tag. Works for both GPG and SSH signed tags.

Fixes #1316.

Work sponsored by @glts.

Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
Gergely Nagy 2024-03-04 19:13:29 +01:00
parent cd19564acc
commit 432ff7d767
No known key found for this signature in database
6 changed files with 186 additions and 2 deletions

View file

@ -60,6 +60,7 @@
<div class="markup desc">
{{$release.RenderedNote}}
</div>
{{template "repo/tag/verification_line" (dict "ctxData" $ "release" $release)}}
<div class="divider"></div>
<details class="download" {{if eq $idx 0}}open{{end}}>
<summary class="tw-my-4">

View file

@ -16,12 +16,13 @@
{{range $idx, $release := .Releases}}
<tr>
<td class="tag">
<h3 class="release-tag-name tw-mb-2">
<h3 class="release-tag-name tw-mb-2 tw-flex">
{{if $canReadReleases}}
<a class="tw-flex tw-items-center" href="{{$.RepoLink}}/releases/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
{{else}}
<a class="tw-flex tw-items-center" href="{{$.RepoLink}}/src/tag/{{.TagName | PathEscapeSegments}}" rel="nofollow">{{.TagName}}</a>
{{end}}
{{template "repo/tag/verification_box" (dict "ctxData" $ "release" $release)}}
</h3>
<div class="download tw-flex tw-items-center">
{{if $.Permission.CanRead $.UnitTypeCode}}

View file

@ -0,0 +1,27 @@
{{$v := call .ctxData.VerifyTag .release}}
{{if call .ctxData.HasSignature $v}}
{{$class := "isSigned"}}
{{$href := ""}}
{{if $v.Verified}}
{{$href = $v.SigningUser.HomeLink}}
{{$class = (print $class " isVerified")}}
{{else}}
{{$class = (print $class " isWarning")}}
{{end}}
<a {{if $href}}href="{{$href}}"{{end}} class="ui label tw-ml-2 {{$class}}">
{{if $v.Verified}}
<div title="{{$v.Reason}}">
{{if ne $v.SigningUser.ID 0}}
{{svg "gitea-lock"}}
{{ctx.AvatarUtils.Avatar $v.SigningUser 28 "signature"}}
{{else}}
<span title="{{ctx.Locale.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog"}}</span>
{{ctx.AvatarUtils.AvatarByEmail $v.Verification.SigningEmail "" 28 "signature"}}
{{end}}
</div>
{{else}}
<span title="{{ctx.Locale.Tr $v.Reason}}">{{svg "gitea-unlock"}}</span>
{{end}}
</a>
{{end}}

View file

@ -0,0 +1,80 @@
{{$v := call .ctxData.VerifyTag .release}}
{{if call .ctxData.HasSignature $v}}
{{$class := "isSigned"}}
{{$href := ""}}
{{if $v.Verified}}
{{$href = $v.SigningUser.HomeLink}}
{{$class = (print $class " isVerified")}}
{{else}}
{{$class = (print $class " isWarning")}}
{{end}}
<div class="ui bottom attached message tw-text-left tw-flex tw-content-center tw-justify-between tag-signature-row tw-flex-wrap tw-mb-0 {{$class}}">
<div class="tw-flex tw-content-center">
{{if $v.Verified}}
{{if ne $v.SigningUser.ID 0}}
{{svg "gitea-lock" 16 "tw-mr-2"}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by"}}</span>
{{ctx.AvatarUtils.Avatar $v.SigningUser 28 "tw-mr-2"}}
<a href="{{$v.SigningUser.HomeLink}}"><strong>{{$v.SigningUser.GetDisplayName}}</strong></a>
{{else}}
<span title="{{ctx.Locale.Tr "gpg.default_key"}}">{{svg "gitea-lock-cog" 16 "tw-mr-2"}}</span>
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.signed_by"}}:</span>
{{ctx.AvatarUtils.AvatarByEmail $v.SigningEmail "" 28 "tw-mr-2"}}
<strong>{{$v.SigningUser.GetDisplayName}}</strong>
{{end}}
{{else}}
{{svg "gitea-unlock" 16 "tw-mr-2"}}
<span class="ui text">{{ctx.Locale.Tr $v.Reason}}</span>
{{end}}
</div>
<div class="tw-flex tw-content-center">
{{if $v.Verified}}
{{if ne $v.SigningUser.ID 0}}
{{svg "octicon-verified" 16 "tw-mr-2"}}
{{if $v.SigningSSHKey}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
{{$v.SigningSSHKey.Fingerprint}}
{{else}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
{{$v.SigningKey.PaddedKeyID}}
{{end}}
{{else}}
{{svg "octicon-unverified" 16 "tw-mr-2"}}
{{if $v.SigningSSHKey}}
<span class="ui text tw-mr-2" data-tooltip-content="{{ctx.Locale.Tr "gpg.default_key"}}">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
{{$v.SigningSSHKey.Fingerprint}}
{{else}}
<span class="ui text tw-mr-2" data-tooltip-content="{{ctx.Locale.Tr "gpg.default_key"}}">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
{{$v.SigningKey.PaddedKeyID}}
{{end}}
{{end}}
{{else if $v.Warning}}
{{svg "octicon-unverified" 16 "tw-mr-2"}}
{{if $v.SigningSSHKey}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
{{$v.SigningSSHKey.Fingerprint}}
{{else}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
{{$v.SigningKey.PaddedKeyID}}
{{end}}
{{else}}
{{if $v.SigningKey}}
{{if ne $v.SigningKey.KeyID ""}}
{{svg "octicon-verified" 16 "tw-mr-2"}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.gpg_key_id"}}:</span>
{{$v.SigningKey.PaddedKeyID}}
{{end}}
{{end}}
{{if $v.SigningSSHKey}}
{{if ne $v.SigningSSHKey.Fingerprint ""}}
{{svg "octicon-verified" 16 "tw-mr-2"}}
<span class="ui text tw-mr-2">{{ctx.Locale.Tr "repo.commits.ssh_key_fingerprint"}}:</span>
{{$v.SigningSSHKey.Fingerprint}}
{{end}}
{{end}}
{{end}}
</div>
</div>
{{end}}