feat: restrict repository file browsing and commit history to authenticated users via conditional template blocks

This commit is contained in:
2024-12-23 01:10:53 +00:00
parent 99e5421464
commit 837faafd6b
7 changed files with 437 additions and 84 deletions
+4 -1
View File
@@ -1,7 +1,9 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
{{template "repo/header" .}}
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
{{template "base/alert" .}}
@@ -68,7 +70,8 @@
{{ end }}
{{$isHomepage := (eq $n 0)}}
<div class="repo-button-row" data-is-homepage="{{$isHomepage}}">
<div style="{{ if not .IsSigned }}display:none;{{ end }}" class="repo-button-row" data-is-homepage="{{$isHomepage}}">
<div class="repo-button-row-left">
{{template "repo/branch_dropdown" dict "root" . "ContainerClasses" "tw-mr-1"}}
{{if and .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
+3 -3
View File
@@ -12,7 +12,7 @@
</div>
{{end}}
{{if not .ReadmeInList}}
{{if and (not .ReadmeInList) (.IsSigned) }}
<div id="repo-file-commit-box" class="ui segment list-header tw-mb-4 tw-flex tw-justify-between">
<div class="latest-commit">
{{template "repo/latest_commit" .}}
@@ -40,14 +40,14 @@
{{end}}
</div>
{{ end }}
<div class="file-header-right file-actions tw-flex tw-items-center tw-flex-wrap">
<div style="{{ if (not .IsSigned) }}display:none !important;{{end}}" class="file-header-right file-actions tw-flex tw-items-center tw-flex-wrap">
{{if .HasSourceRenderedToggle}}
<div class="ui compact icon buttons">
<a href="?display=source" class="ui mini basic button {{if .IsDisplayingSource}}active{{end}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_source"}}">{{svg "octicon-code" 15}}</a>
<a href="{{$.Link}}" class="ui mini basic button {{if .IsDisplayingRendered}}active{{end}}" data-tooltip-content="{{ctx.Locale.Tr "repo.file_view_rendered"}}">{{svg "octicon-file" 15}}</a>
</div>
{{end}}
{{if and (not .ReadmeInList) (not .IsSigned )}}
{{if and (not .ReadmeInList) (.IsSigned )}}
<div class="ui buttons tw-mr-1">
<a class="ui mini basic button" href="{{$.RawFileLink}}">{{ctx.Locale.Tr "repo.file_raw"}}</a>
{{if not .IsViewCommit}}
+15 -5
View File
@@ -1,9 +1,12 @@
{{if and (not .IsSigned) .ReadmeExist (or .IsMarkup .IsPlainText)}}
{{template "repo/view_file" .}}
{{end}}
<table id="repo-files-table" class="ui single line table tw-mt-0" {{if .HasFilesWithoutLatestCommit}}hx-indicator="tr.notready td.message span" hx-trigger="load" hx-swap="morph" hx-post="{{.LastCommitLoaderURL}}"{{end}}>
<table id="repo-files-table" class="{{ if .IsSigned}}ui {{end}}single line table tw-mt-0" {{if .HasFilesWithoutLatestCommit}}hx-indicator="tr.notready td.message span" hx-trigger="load" hx-swap="morph" hx-post="{{.LastCommitLoaderURL}}"{{end}}>
{{ if .IsSigned }}
<thead>
<tr class="commit-list">
<th class="tw-overflow-hidden" colspan="2">
<div class="tw-flex">
<div class="latest-commit">
@@ -11,9 +14,11 @@
</div>
</div>
</th>
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When ctx.Locale}}{{end}}{{end}}</th>
<th style="min-width:100px;" class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When ctx.Locale}}{{end}}{{end}}</th>
</tr>
</thead>
{{ end }}
<tbody>
{{if .HasParentPath}}
<tr class="has-parent">
@@ -56,17 +61,22 @@
{{end}}
</span>
</td>
<td class="message nine wide">
<td class="message nine wide">
<span class="truncate">
{{if $commit}}
{{ if $.IsSigned }}
{{if $commit}}
{{$commitLink := printf "%s/commit/%s" $.RepoLink (PathEscape $commit.ID.String)}}
{{RenderCommitMessageLinkSubject $.Context $commit.Message $commitLink ($.Repository.ComposeMetas ctx)}}
{{else}}
<div class="ui active tiny slow centered inline"></div>
{{end}}
{{ end }}
</span>
</td>
<td class="text right age three wide">{{if $commit}}{{TimeSince $commit.Committer.When ctx.Locale}}{{end}}</td>
<td style="min-width:100px;" class="text right age three wide">{{if and $.IsSigned $commit}}{{TimeSince $commit.Committer.When ctx.Locale}}{{end}}</td>
</tr>
{{end}}
</tbody>