Skip to content

Commit b605505

Browse files
committed
improvements
1 parent bf74f51 commit b605505

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

routers/web/repo/view_file.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -294,38 +294,40 @@ func prepareToRenderButtons(ctx *context.Context, isLFSFile, isRepresentableAsTe
294294
return
295295
}
296296

297+
// The buttons should not be shown if it's not a branch
298+
if !ctx.Repo.RefFullName.IsBranch() {
299+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
300+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
301+
return
302+
}
303+
297304
if isLFSFile {
298305
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_lfs_files")
299-
// TODO: we should not allow delete LFS files, but we need to check if the file is locked
300-
return
301306
} else if !isRepresentableAsText {
302307
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
303-
// TODO: delete file tooltip?
304-
return
305308
}
306309

307-
// for non-LFS representableAsText files
308-
if !ctx.Repo.RefFullName.IsBranch() {
309-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
310-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
311-
} else {
312-
canWriteToBranch := ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName)
313-
if !canWriteToBranch {
310+
if !ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName) {
311+
if !isLFSFile { // lfs file cannot be edited after fork
314312
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
315-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
316-
} else {
317-
// FIXME: since isLFSFile is false, why we still need to check lfsLock? Leave the legacy code here for now.
318-
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
319-
ctx.Data["CanEditFile"] = false
320-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
321-
ctx.Data["CanDeleteFile"] = false
322-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
323-
} else {
324-
ctx.Data["CanEditFile"] = true
325-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
326-
ctx.Data["CanDeleteFile"] = true
327-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
328-
}
329313
}
314+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
315+
return
316+
}
317+
318+
// it's a lfs file and the user is not the owner of the lock
319+
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
320+
ctx.Data["CanEditFile"] = false
321+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
322+
ctx.Data["CanDeleteFile"] = false
323+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
324+
return
325+
}
326+
327+
if !isLFSFile { // lfs file cannot be edited
328+
ctx.Data["CanEditFile"] = true
329+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
330330
}
331+
ctx.Data["CanDeleteFile"] = true
332+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
331333
}

0 commit comments

Comments
 (0)