Skip to content

Commit 170d6b6

Browse files
committed
Disable new/edit/delete button when not signed in
Also related tweaks for consistency: * Hide new file button when repository is archived or mirrored, matching edit and delete buttons * Show readme edit button also when not editable, and disable it, to match the other edit button.
1 parent f2fc205 commit 170d6b6

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ editor.this_file_locked = File is locked
13361336
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
13371337
editor.delete_this_file = Delete File
13381338
editor.must_have_write_access = You must have write access to make or propose changes to this file.
1339+
editor.must_be_signed_in = You must be signed in to make or propose changes.
13391340
editor.file_delete_success = File "%s" has been deleted.
13401341
editor.name_your_file = Name your file…
13411342
editor.filename_help = Add a directory by typing its name followed by a slash ('/'). Remove a directory by typing backspace at the beginning of the input field.

routers/web/repo/view_file.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,10 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
245245
}
246246
if !fInfo.isLFSFile {
247247
if ctx.Repo.CanEnableEditor() {
248-
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
248+
if !ctx.IsSigned {
249+
ctx.Data["CanEditFile"] = false
250+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_signed_in")
251+
} else if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
249252
ctx.Data["CanEditFile"] = false
250253
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
251254
} else {
@@ -306,7 +309,10 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
306309
}
307310

308311
if ctx.Repo.CanEnableEditor() {
309-
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
312+
if !ctx.IsSigned {
313+
ctx.Data["CanDeleteFile"] = false
314+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_signed_in")
315+
} else if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
310316
ctx.Data["CanDeleteFile"] = false
311317
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
312318
} else {

routers/web/repo/view_readme.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,13 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
214214

215215
if !fInfo.isLFSFile {
216216
if ctx.Repo.CanEnableEditor() {
217-
ctx.Data["CanEditReadmeFile"] = true
217+
if !ctx.IsSigned {
218+
ctx.Data["CanEditReadmeFile"] = false
219+
ctx.Data["EditReadmeFileTooltip"] = ctx.Tr("repo.editor.must_be_signed_in")
220+
} else {
221+
ctx.Data["CanEditReadmeFile"] = true
222+
ctx.Data["EditReadmeFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
223+
}
218224
}
219225
}
220226
}

templates/repo/view_content.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
<a href="{{.Repository.Link}}/find/{{.RefTypeNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
4242
{{end}}
4343

44-
{{if and .RefFullName.IsBranch (not .IsViewFile)}}
45-
<button class="ui dropdown basic compact jump button"{{if not .Repository.CanEnableEditor}} disabled{{end}}>
44+
{{if and .RefFullName.IsBranch (not .IsViewFile) .Repository.CanEnableEditor}}
45+
<button class="ui dropdown basic compact jump button"
46+
{{if not .IsSigned}} disabled data-tooltip-content="{{ctx.Locale.Tr "repo.editor.must_be_signed_in"}}"{{end}}>
4647
{{ctx.Locale.Tr "repo.editor.add_file"}}
4748
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
4849
<div class="menu">

templates/repo/view_file.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@
7777
<button class="ui mini basic button unescape-button tw-mr-1 tw-hidden">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
7878
<button class="ui mini basic button escape-button tw-mr-1">{{ctx.Locale.Tr "repo.escape_control_characters"}}</button>
7979
{{end}}
80-
{{if and .ReadmeInList .CanEditReadmeFile}}
81-
<a class="btn-octicon" data-tooltip-content="{{ctx.Locale.Tr "repo.editor.edit_this_file"}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .FileTreePath}}">{{svg "octicon-pencil"}}</a>
80+
{{if and .ReadmeInList .Repository.CanEnableEditor}}
81+
{{if .CanEditReadmeFile}}
82+
<a class="btn-octicon" data-tooltip-content="{{.EditReadmeFileTooltip}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .FileTreePath}}">{{svg "octicon-pencil"}}</a>
83+
{{else}}
84+
<span class="btn-octicon disabled" data-tooltip-content="{{.EditReadmeFileTooltip}}">{{svg "octicon-pencil"}}</span>
85+
{{end}}
8286
{{end}}
8387
</div>
8488
</h4>

0 commit comments

Comments
 (0)