@@ -140,13 +140,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
140140 ctx .Data ["LFSLockHint" ] = ctx .Tr ("repo.editor.this_file_locked" )
141141 }
142142
143- // Assume file is not editable first.
144- if fInfo .isLFSFile {
145- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.cannot_edit_lfs_files" )
146- } else if ! isRepresentableAsText {
147- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.cannot_edit_non_text_files" )
148- }
149-
150143 // read all needed attributes which will be used later
151144 // there should be no performance different between reading 2 or 4 here
152145 attrsMap , err := attribute .CheckAttributes (ctx , ctx .Repo .GitRepo , ctx .Repo .CommitID , attribute.CheckAttributeOpts {
@@ -243,21 +236,6 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
243236 ctx .Data ["FileContent" ] = fileContent
244237 ctx .Data ["LineEscapeStatus" ] = statuses
245238 }
246- if ! fInfo .isLFSFile {
247- if ctx .Repo .CanEnableEditor (ctx , ctx .Doer ) {
248- if lfsLock != nil && lfsLock .OwnerID != ctx .Doer .ID {
249- ctx .Data ["CanEditFile" ] = false
250- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.this_file_locked" )
251- } else {
252- ctx .Data ["CanEditFile" ] = true
253- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.edit_this_file" )
254- }
255- } else if ! ctx .Repo .RefFullName .IsBranch () {
256- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.must_be_on_a_branch" )
257- } else if ! ctx .Repo .CanWriteToBranch (ctx , ctx .Doer , ctx .Repo .BranchName ) {
258- ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.fork_before_edit" )
259- }
260- }
261239
262240 case fInfo .st .IsPDF ():
263241 ctx .Data ["IsPDFFile" ] = true
@@ -307,17 +285,59 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
307285 }
308286 }
309287
310- if ctx .Repo .CanEnableEditor (ctx , ctx .Doer ) {
311- if lfsLock != nil && lfsLock .OwnerID != ctx .Doer .ID {
312- ctx .Data ["CanDeleteFile" ] = false
313- ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.this_file_locked" )
314- } else {
315- ctx .Data ["CanDeleteFile" ] = true
316- ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.delete_this_file" )
288+ prepareToRenderEditButton (ctx , fInfo .isLFSFile , isRepresentableAsText , lfsLock )
289+ prepareToRenderDeleteButton (ctx , lfsLock )
290+ }
291+
292+ func prepareToRenderEditButton (ctx * context.Context , isLFSFile , isRepresentableAsText bool , lfsLock * git_model.LFSLock ) {
293+ if ctx .Repo .Repository .IsArchived {
294+ return
295+ }
296+ if isLFSFile {
297+ ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.cannot_edit_lfs_files" )
298+ return
299+ } else if ! isRepresentableAsText {
300+ ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.cannot_edit_non_text_files" )
301+ return
302+ }
303+
304+ if ! ctx .Repo .RefFullName .IsBranch () {
305+ ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.must_be_on_a_branch" )
306+ } else {
307+ canWriteToBranch := ctx .Repo .CanWriteToBranch (ctx , ctx .Doer , ctx .Repo .BranchName )
308+ if ! canWriteToBranch {
309+ ctx .Data ["EditFileTooltip" ] = ctx .Tr ("repo.editor.fork_before_edit" )
310+ } else if ctx .Repo .Repository .CanEnableEditor () {
311+ if lfsLock != nil && lfsLock .OwnerID != ctx .Doer .ID {
312+ ctx .Data ["CanEditFile" ] = false
313+ 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+ }
317318 }
318- } else if ! ctx .Repo .RefFullName .IsBranch () {
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 () {
319328 ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.must_be_on_a_branch" )
320- } else if ! ctx .Repo .CanWriteToBranch (ctx , ctx .Doer , ctx .Repo .BranchName ) {
321- ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.must_have_write_access" )
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 {
335+ ctx .Data ["CanDeleteFile" ] = false
336+ ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.this_file_locked" )
337+ } else {
338+ ctx .Data ["CanDeleteFile" ] = true
339+ ctx .Data ["DeleteFileTooltip" ] = ctx .Tr ("repo.editor.delete_this_file" )
340+ }
341+ }
322342 }
323343}
0 commit comments