Skip to content

Commit 88210d2

Browse files
committed
add disable download source configuration
1 parent e5ef7c2 commit 88210d2

File tree

6 files changed

+17
-1
lines changed

6 files changed

+17
-1
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ ROUTER = console
878878
;; Allow deletion of unadopted repositories
879879
;ALLOW_DELETION_OF_UNADOPTED_REPOSITORIES = false
880880

881+
;; Dont' allow download source tar files from UI
882+
;DISABLED_DOWNLOAD_SOURCE = false
883+
881884
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
882885
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
883886
;[repository.editor]

modules/setting/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
DefaultBranch string
4949
AllowAdoptionOfUnadoptedRepositories bool
5050
AllowDeleteOfUnadoptedRepositories bool
51+
DisabledDownloadSource bool
5152

5253
// Repository editor settings
5354
Editor struct {

routers/web/repo/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
7878
// Disable the showCreateNewBranch form in the dropdown on this page.
7979
ctx.Data["CanCreateBranch"] = false
8080
ctx.Data["HideBranchesInDropdown"] = true
81+
ctx.Data["DisabledDownloadSource"] = setting.Repository.DisabledDownloadSource
8182

8283
if isTagList {
8384
ctx.Data["Title"] = ctx.Tr("repo.release.tags")

routers/web/web.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ func RegisterRoutes(m *web.Route) {
289289
}
290290
}
291291

292+
dlSourceEnabled := func(ctx *context.Context) {
293+
if setting.Repository.DisabledDownloadSource {
294+
ctx.Error(http.StatusNotFound)
295+
return
296+
}
297+
}
298+
292299
// FIXME: not all routes need go through same middleware.
293300
// Especially some AJAX requests, we can reduce middleware number to improve performance.
294301
// Routers.
@@ -1104,7 +1111,7 @@ func RegisterRoutes(m *web.Route) {
11041111
m.Group("/archive", func() {
11051112
m.Get("/*", repo.Download)
11061113
m.Post("/*", repo.InitiateDownload)
1107-
}, repo.MustBeNotEmpty, reqRepoCodeReader)
1114+
}, repo.MustBeNotEmpty, dlSourceEnabled, reqRepoCodeReader)
11081115

11091116
m.Group("/branches", func() {
11101117
m.Get("", repo.Branches)

templates/mail/release.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@
3131
<br>
3232
{{.locale.Tr "mail.release.downloads"}}
3333
<ul>
34+
{{if not .DisabledDownloadSource}}
3435
<li>
3536
<a href="{{.Release.Repo.Link}}/archive/{{.Release.TagName | PathEscapeSegments}}.zip" rel="nofollow"><strong>{{.locale.Tr "mail.release.download.zip"}}</strong></a>
3637
</li>
3738
<li>
3839
<a href="{{.Release.Repo.Link}}/archive/{{.Release.TagName | PathEscapeSegments}}.tar.gz" rel="nofollow"><strong>{{.locale.Tr "mail.release.download.targz"}}</strong></a>
3940
</li>
41+
{{end}}
4042
{{if .Release.Attachments}}
4143
{{range .Release.Attachments}}
4244
<li>

templates/repo/home.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
{{if eq $n 0}}
125125
<div class="ui action tiny input" id="clone-panel">
126126
{{template "repo/clone_buttons" .}}
127+
{{if not .DisabledDownloadSource}}
127128
<button id="download-btn" class="ui basic jump dropdown icon button tooltip" data-content="{{.locale.Tr "repo.download_archive"}}" data-position="top right">
128129
{{svg "octicon-download"}}
129130
<div class="menu">
@@ -133,6 +134,7 @@
133134
<a class="item" href="vscode://vscode.git/clone?url={{$.RepoCloneLink.HTTPS}}">{{svg "gitea-vscode" 16 "mr-3"}}{{.locale.Tr "repo.clone_in_vsc"}}</a>
134135
</div>
135136
</button>
137+
{{end}}
136138
</div>
137139
{{end}}
138140
</div>

0 commit comments

Comments
 (0)