Skip to content

Commit 3eb0f14

Browse files
committed
Improvements
1 parent 9eea24f commit 3eb0f14

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

routers/web/repo/view_file.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -285,56 +285,44 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
285285
}
286286
}
287287

288-
prepareToRenderEditButton(ctx, fInfo.isLFSFile, isRepresentableAsText, lfsLock)
289-
prepareToRenderDeleteButton(ctx, lfsLock)
288+
prepareToRenderButtons(ctx, fInfo.isLFSFile, isRepresentableAsText, lfsLock)
290289
}
291290

292-
func prepareToRenderEditButton(ctx *context.Context, isLFSFile, isRepresentableAsText bool, lfsLock *git_model.LFSLock) {
293-
if ctx.Repo.Repository.IsArchived {
291+
func prepareToRenderButtons(ctx *context.Context, isLFSFile, isRepresentableAsText bool, lfsLock *git_model.LFSLock) {
292+
// archived or mirror repository, the buttons should not be shown
293+
if ctx.Repo.Repository.IsArchived || !ctx.Repo.Repository.CanEnableEditor() {
294294
return
295295
}
296+
296297
if isLFSFile {
297298
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
298300
return
299301
} else if !isRepresentableAsText {
300302
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
303+
// TODO: we should not allow delete LFS files, but we need to check if the file is locked
301304
return
302305
}
303306

307+
// for non-LFS representableAsText files
304308
if !ctx.Repo.RefFullName.IsBranch() {
305309
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")
306311
} else {
307312
canWriteToBranch := ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName)
308313
if !canWriteToBranch {
309314
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
310-
} else if ctx.Repo.Repository.CanEnableEditor() {
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.
311318
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
312319
ctx.Data["CanEditFile"] = false
313320
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
314-
} else {
315-
ctx.Data["CanEditFile"] = true
316-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
317-
}
318-
}
319-
}
320-
}
321-
322-
func prepareToRenderDeleteButton(ctx *context.Context, lfsLock *git_model.LFSLock) {
323-
if ctx.Repo.Repository.IsArchived {
324-
return
325-
}
326-
327-
if !ctx.Repo.RefFullName.IsBranch() {
328-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
329-
} else {
330-
canWriteToBranch := ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.BranchName)
331-
if !canWriteToBranch {
332-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
333-
} else if ctx.Repo.Repository.CanEnableEditor() {
334-
if lfsLock != nil && lfsLock.OwnerID != ctx.Doer.ID {
335321
ctx.Data["CanDeleteFile"] = false
336322
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
337323
} else {
324+
ctx.Data["CanEditFile"] = true
325+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
338326
ctx.Data["CanDeleteFile"] = true
339327
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
340328
}

0 commit comments

Comments
 (0)