]> source.dussan.org Git - gitea.git/commitdiff
Respect LFS File Lock on UI (#8719)
authorBenno <blueworrybear@gmail.com>
Tue, 29 Oct 2019 21:32:21 +0000 (05:32 +0800)
committerLauris BH <lauris@nix.lv>
Tue, 29 Oct 2019 21:32:21 +0000 (23:32 +0200)
* update #8687 respect file locking

* upate #8687 Add LFS locker information

* update #8719 enhance coding style and return error

models/repo.go
options/locale/locale_en-US.ini
routers/repo/blame.go
routers/repo/view.go
templates/repo/view_file.tmpl

index ac3443f8953b4f252d64f11161564d50bf79745d..7945cb309d3417c9de655ebde833bf7c1271a854 100644 (file)
@@ -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
+}
index 4210ed1212a808ad3c717306119c87ca2bec8ada..4d1af69db53f70ed3d81c8639fa6012ebc7736ff 100644 (file)
@@ -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
index 5578942a9f1a504588b860c238de6510f87cf988..f5a2a548e3604df68d2d0c6b1d598ff0eb0b1cfc 100644 (file)
@@ -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) {
index da6d426de422cf599c96e1c96599634a3914eb0b..8730523d891e066632feaecb6ea4cfc947807462 100644 (file)
@@ -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) {
index 616ca256502ecc44739ccdfc637807001ee3ffd5..f95076272ec38d015172ecdb6c4c0c089d3b8dcf 100644 (file)
                                                        {{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>
+                                                       <a href="{{AppSubUrl}}/{{.LFSLock.Owner.Name}}">{{.LFSLockOwner}}</a>
+                                               </div>
+                                       {{end}}
                                </div>
                        {{end}}
                </div>