Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect LFS File Lock on UI #8719

Merged
merged 5 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2810,3 +2810,19 @@ func (repo *Repository) GetOriginalURLHostname() string {

return u.Host
}

// GetTreePathLock returns LSF lock for the treePath
func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) {
if setting.LFS.StartServer {
locks, err := GetLFSLockByRepoID(repo.ID)
if err != nil {
return nil, err
}
for _, lock := range locks {
if lock.Path == treePath {
return lock, nil
}
}
}
return nil, nil
}
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ editor.preview_changes = Preview Changes
editor.cannot_edit_lfs_files = LFS files cannot be edited in the web interface.
editor.cannot_edit_non_text_files = Binary files cannot be edited in the web interface.
editor.edit_this_file = Edit File
editor.this_file_locked = File is locked
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
editor.fork_before_edit = You must fork this repository to make or propose changes to this file.
editor.delete_this_file = Delete File
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ editor.edit_file=編輯文件
editor.preview_changes=預覽更改
editor.cannot_edit_non_text_files=網站介面不能編輯二進位檔案
editor.edit_this_file=編輯文件
editor.this_file_locked = 文件已被鎖定
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
editor.must_be_on_a_branch=你必須在一個分支或提出對此檔的更改。
editor.delete_this_file=刪除檔案
editor.file_delete_success=文件 %s 已刪除。
Expand Down
19 changes: 17 additions & 2 deletions routers/repo/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ func RefBlame(ctx *context.Context) {
log.Error("GetLatestCommitStatus: %v", err)
}

// Check LFS Lock
isLFSLock := false
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("GetTreePathLock", err)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
}
if lfsLock != nil && lfsLock.OwnerID != ctx.User.ID {
isLFSLock = true
}

// Get current entry user currently looking at.
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)
if err != nil {
Expand All @@ -119,8 +129,13 @@ func RefBlame(ctx *context.Context) {
ctx.Data["IsBlame"] = true

if ctx.Repo.CanEnableEditor() {
ctx.Data["CanDeleteFile"] = true
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
if isLFSLock {
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["CanDeleteFile"] = false
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
} else {
ctx.Data["CanDeleteFile"] = true
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
}
} else if !ctx.Repo.IsViewBranch {
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
Expand Down
31 changes: 27 additions & 4 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st

isTextFile := base.IsTextFile(buf)
isLFSFile := false
isLFSLock := false
ctx.Data["IsTextFile"] = isTextFile

//Check for LFS meta file
Expand Down Expand Up @@ -265,6 +266,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.Data["RawFileLink"] = fmt.Sprintf("%s%s.git/info/lfs/objects/%s/%s", setting.AppURL, ctx.Repo.Repository.FullName(), meta.Oid, filenameBase64)
}
}
lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath)
lafriks marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["LFSLock"] = lfsLock
if err != nil {
ctx.ServerError("GetTreePathLock", err)
blueworrybear marked this conversation as resolved.
Show resolved Hide resolved
}
if lfsLock != nil {
ctx.Data["LFSLockOwner"] = lfsLock.Owner.DisplayName()
ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked")
if lfsLock.OwnerID != ctx.User.ID {
isLFSLock = true
}
}

// Assume file is not editable first.
if isLFSFile {
Expand Down Expand Up @@ -329,8 +342,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}
if !isLFSFile {
if ctx.Repo.CanEnableEditor() {
ctx.Data["CanEditFile"] = true
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
if isLFSLock {
ctx.Data["CanEditFile"] = false
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
} else {
ctx.Data["CanEditFile"] = true
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
}
} else if !ctx.Repo.IsViewBranch {
ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
Expand Down Expand Up @@ -363,8 +381,13 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
}

if ctx.Repo.CanEnableEditor() {
ctx.Data["CanDeleteFile"] = true
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
if isLFSLock {
ctx.Data["CanDeleteFile"] = false
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.this_file_locked")
} else {
ctx.Data["CanDeleteFile"] = true
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
}
} else if !ctx.Repo.IsViewBranch {
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
} else if !ctx.Repo.CanWrite(models.UnitTypeCode) {
Expand Down
6 changes: 6 additions & 0 deletions templates/repo/view_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}
</div>
{{end}}
{{if .LFSLock}}
<div class="file-info-entry">
<i class="fa fa-lock poping up disabled" data-content="{{.LFSLockHint}}" data-position="bottom center" data-variation="tiny inverted"></i>
{{.LFSLockOwner}}
</div>
{{end}}
</div>
{{end}}
</div>
Expand Down