mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 22:00:39 +00:00
Show lock owner instead of repo owner on LFS setting page (#31788)
Fix #31784. Before: <img width="1648" alt="image" src="https://github.com/user-attachments/assets/03f32545-4a85-42ed-bafc-2b193a5d8023"> After: <img width="1653" alt="image" src="https://github.com/user-attachments/assets/e5bcaf93-49cb-421f-aac1-5122bc488b02"> (cherry picked from commit 0470646d46f90c20f40fde718be6ef8d8c84ee2c)
This commit is contained in:
parent
4760c5029d
commit
7f1db1df3e
5 changed files with 162 additions and 10 deletions
54
models/git/lfs_lock_list.go
Normal file
54
models/git/lfs_lock_list.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package git
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
)
|
||||
|
||||
// LFSLockList is a list of LFSLock
|
||||
type LFSLockList []*LFSLock
|
||||
|
||||
// LoadAttributes loads the attributes for the given locks
|
||||
func (locks LFSLockList) LoadAttributes(ctx context.Context) error {
|
||||
if len(locks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := locks.LoadOwner(ctx); err != nil {
|
||||
return fmt.Errorf("load owner: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOwner loads the owner of the locks
|
||||
func (locks LFSLockList) LoadOwner(ctx context.Context) error {
|
||||
if len(locks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
usersIDs := container.FilterSlice(locks, func(lock *LFSLock) (int64, bool) {
|
||||
return lock.OwnerID, true
|
||||
})
|
||||
users := make(map[int64]*user_model.User, len(usersIDs))
|
||||
if err := db.GetEngine(ctx).
|
||||
In("id", usersIDs).
|
||||
Find(&users); err != nil {
|
||||
return fmt.Errorf("find users: %w", err)
|
||||
}
|
||||
for _, v := range locks {
|
||||
v.Owner = users[v.OwnerID]
|
||||
if v.Owner == nil { // not exist
|
||||
v.Owner = user_model.NewGhostUser()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue