Skip to content

Commit a5758b9

Browse files
committed
update go-gitea#8687 respect file locking
1 parent 70fa80d commit a5758b9

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

models/repo.go

+16
Original file line numberDiff line numberDiff line change
@@ -2810,3 +2810,19 @@ func (repo *Repository) GetOriginalURLHostname() string {
28102810

28112811
return u.Host
28122812
}
2813+
2814+
// GetTreePathLock returns LSF lock for the treePath
2815+
func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) {
2816+
if setting.LFS.StartServer {
2817+
locks, err := GetLFSLockByRepoID(repo.ID)
2818+
if err != nil {
2819+
return nil, err
2820+
}
2821+
for _, lock := range locks {
2822+
if lock.Path == treePath {
2823+
return lock, nil
2824+
}
2825+
}
2826+
}
2827+
return nil, nil
2828+
}

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ editor.preview_changes = Preview Changes
703703
editor.cannot_edit_lfs_files = LFS files cannot be edited in the web interface.
704704
editor.cannot_edit_non_text_files = Binary files cannot be edited in the web interface.
705705
editor.edit_this_file = Edit File
706+
editor.this_file_locked = File is locked
706707
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
707708
editor.fork_before_edit = You must fork this repository to make or propose changes to this file.
708709
editor.delete_this_file = Delete File

options/locale/locale_zh-TW.ini

+1
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ editor.edit_file=編輯文件
526526
editor.preview_changes=預覽更改
527527
editor.cannot_edit_non_text_files=網站介面不能編輯二進位檔案
528528
editor.edit_this_file=編輯文件
529+
editor.this_file_locked = 文件已被鎖定
529530
editor.must_be_on_a_branch=你必須在一個分支或提出對此檔的更改。
530531
editor.delete_this_file=刪除檔案
531532
editor.file_delete_success=文件 %s 已刪除。

routers/repo/blame.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ func RefBlame(ctx *context.Context) {
9494
log.Error("GetLatestCommitStatus: %v", err)
9595
}
9696

97+
// Check LFS Lock
98+
isLFSLock := false
99+
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
100+
if err != nil {
101+
ctx.ServerError("GetTreePathLock", err)
102+
}
103+
if lfsLock != nil && lfsLock.OwnerID != ctx.User.ID {
104+
isLFSLock = true
105+
}
106+
97107
// Get current entry user currently looking at.
98108
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
99109
if err != nil {
@@ -119,8 +129,13 @@ func RefBlame(ctx *context.Context) {
119129
ctx.Data["IsBlame"] = true
120130

121131
if ctx.Repo.CanEnableEditor() {
122-
ctx.Data["CanDeleteFile"] = true
123-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
132+
if isLFSLock {
133+
ctx.Data["CanDeleteFile"] = false
134+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
135+
} else {
136+
ctx.Data["CanDeleteFile"] = true
137+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
138+
}
124139
} else if !ctx.Repo.IsViewBranch {
125140
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
126141
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {

routers/repo/view.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
223223

224224
isTextFile := base.IsTextFile(buf)
225225
isLFSFile := false
226+
isLFSLock := false
226227
ctx.Data["IsTextFile"] = isTextFile
227228

228229
//Check for LFS meta file
@@ -265,6 +266,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
265266
ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
266267
}
267268
}
269+
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
270+
if err != nil {
271+
ctx.ServerError("GetTreePathLock", err)
272+
}
273+
if lfsLock != nil && lfsLock.OwnerID != ctx.User.ID {
274+
isLFSLock = true
275+
}
268276

269277
// Assume file is not editable first.
270278
if isLFSFile {
@@ -329,8 +337,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
329337
}
330338
if !isLFSFile {
331339
if ctx.Repo.CanEnableEditor() {
332-
ctx.Data["CanEditFile"] = true
333-
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
340+
if isLFSLock {
341+
ctx.Data["CanEditFile"] = false
342+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
343+
} else {
344+
ctx.Data["CanEditFile"] = true
345+
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
346+
}
334347
} else if !ctx.Repo.IsViewBranch {
335348
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
336349
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
@@ -363,8 +376,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
363376
}
364377

365378
if ctx.Repo.CanEnableEditor() {
366-
ctx.Data["CanDeleteFile"] = true
367-
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
379+
if isLFSLock {
380+
ctx.Data["CanDeleteFile"] = false
381+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
382+
} else {
383+
ctx.Data["CanDeleteFile"] = true
384+
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
385+
}
368386
} else if !ctx.Repo.IsViewBranch {
369387
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
370388
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {

0 commit comments

Comments
 (0)