Use Name instead of DisplayName in LFS Lock (#21415)

Fixes #21268

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
KN4CK3R 2022-10-12 03:03:15 +02:00 committed by GitHub
parent e026459a2d
commit 4dc3b2ec57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View file

@ -412,7 +412,7 @@ func ToLFSLock(l *git_model.LFSLock) *api.LFSLock {
Path: l.Path, Path: l.Path,
LockedAt: l.Created.Round(time.Second), LockedAt: l.Created.Round(time.Second),
Owner: &api.LFSLockOwner{ Owner: &api.LFSLockOwner{
Name: u.DisplayName(), Name: u.Name,
}, },
} }
} }

View file

@ -455,7 +455,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.ServerError("GetTreePathLock", err) ctx.ServerError("GetTreePathLock", err)
return return
} }
ctx.Data["LFSLockOwner"] = u.DisplayName() ctx.Data["LFSLockOwner"] = u.Name
ctx.Data["LFSLockOwnerHomeLink"] = u.HomeLink() ctx.Data["LFSLockOwnerHomeLink"] = u.HomeLink()
ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked") ctx.Data["LFSLockHint"] = ctx.Tr("repo.editor.this_file_locked")
} }

View file

@ -112,6 +112,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
if len(test.addTime) > 0 { if len(test.addTime) > 0 {
var lfsLock api.LFSLockResponse var lfsLock api.LFSLockResponse
DecodeJSON(t, resp, &lfsLock) DecodeJSON(t, resp, &lfsLock)
assert.Equal(t, test.user.Name, lfsLock.Lock.Owner.Name)
assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second assert.EqualValues(t, lfsLock.Lock.LockedAt.Format(time.RFC3339), lfsLock.Lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second
for _, id := range test.addTime { for _, id := range test.addTime {
resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now()) resultsTests[id].locksTimes = append(resultsTests[id].locksTimes, time.Now())
@ -129,7 +130,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
DecodeJSON(t, resp, &lfsLocks) DecodeJSON(t, resp, &lfsLocks)
assert.Len(t, lfsLocks.Locks, test.totalCount) assert.Len(t, lfsLocks.Locks, test.totalCount)
for i, lock := range lfsLocks.Locks { for i, lock := range lfsLocks.Locks {
assert.EqualValues(t, test.locksOwners[i].DisplayName(), lock.Owner.Name) assert.EqualValues(t, test.locksOwners[i].Name, lock.Owner.Name)
assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 10*time.Second) assert.WithinDuration(t, test.locksTimes[i], lock.LockedAt, 10*time.Second)
assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second assert.EqualValues(t, lock.LockedAt.Format(time.RFC3339), lock.LockedAt.Format(time.RFC3339Nano)) // locked at should be rounded to second
} }
@ -143,7 +144,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
assert.Len(t, lfsLocksVerify.Ours, test.oursCount) assert.Len(t, lfsLocksVerify.Ours, test.oursCount)
assert.Len(t, lfsLocksVerify.Theirs, test.theirsCount) assert.Len(t, lfsLocksVerify.Theirs, test.theirsCount)
for _, lock := range lfsLocksVerify.Ours { for _, lock := range lfsLocksVerify.Ours {
assert.EqualValues(t, test.user.DisplayName(), lock.Owner.Name) assert.EqualValues(t, test.user.Name, lock.Owner.Name)
deleteTests = append(deleteTests, struct { deleteTests = append(deleteTests, struct {
user *user_model.User user *user_model.User
repo *repo_model.Repository repo *repo_model.Repository
@ -165,7 +166,7 @@ func TestAPILFSLocksLogged(t *testing.T) {
var lfsLockRep api.LFSLockResponse var lfsLockRep api.LFSLockResponse
DecodeJSON(t, resp, &lfsLockRep) DecodeJSON(t, resp, &lfsLockRep)
assert.Equal(t, test.lockID, lfsLockRep.Lock.ID) assert.Equal(t, test.lockID, lfsLockRep.Lock.ID)
assert.Equal(t, test.user.DisplayName(), lfsLockRep.Lock.Owner.Name) assert.Equal(t, test.user.Name, lfsLockRep.Lock.Owner.Name)
} }
// check that we don't have any lock // check that we don't have any lock