diff options
author | Benno <blueworrybear@gmail.com> | 2019-10-30 05:32:21 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-10-29 23:32:21 +0200 |
commit | 7bb817e6d19f21ccb16c6ba1eecd0e89fd052322 (patch) | |
tree | e31718968ed52f5f481fa11ccf9859215a37e261 /routers/repo | |
parent | e7fbc551ab7b743761f90997864ed8c11e4f9c39 (diff) | |
download | gitea-7bb817e6d19f21ccb16c6ba1eecd0e89fd052322.tar.gz gitea-7bb817e6d19f21ccb16c6ba1eecd0e89fd052322.zip |
Respect LFS File Lock on UI (#8719)
* update #8687 respect file locking
* upate #8687 Add LFS locker information
* update #8719 enhance coding style and return error
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/blame.go | 15 | ||||
-rw-r--r-- | routers/repo/view.go | 29 |
2 files changed, 38 insertions, 6 deletions
diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 5578942a9f..f5a2a548e3 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -119,8 +119,19 @@ 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") + // Check LFS Lock + lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath) + if err != nil { + ctx.ServerError("GetTreePathLock", err) + return + } + if lfsLock != nil && lfsLock.OwnerID != ctx.User.ID { + 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) { diff --git a/routers/repo/view.go b/routers/repo/view.go index da6d426de4..8730523d89 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -265,6 +265,17 @@ 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) } } + // Check LFS Lock + lfsLock, err := ctx.Repo.Repository.GetTreePathLock(ctx.Repo.TreePath) + ctx.Data["LFSLock"] = lfsLock + if err != nil { + ctx.ServerError("GetTreePathLock", err) + return + } + if lfsLock != nil { + ctx.Data["LFSLockOwner"] = lfsLock.Owner.DisplayName() + ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked") + } // Assume file is not editable first. if isLFSFile { @@ -334,8 +345,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 lfsLock != nil && lfsLock.OwnerID != ctx.User.ID { + 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) { @@ -368,8 +384,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 lfsLock != nil && lfsLock.OwnerID != ctx.User.ID { + 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) { |