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
|
@ -6,6 +6,7 @@ package git
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -21,11 +22,12 @@ import (
|
|||
|
||||
// LFSLock represents a git lfs lock of repository.
|
||||
type LFSLock struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX NOT NULL"`
|
||||
OwnerID int64 `xorm:"INDEX NOT NULL"`
|
||||
Path string `xorm:"TEXT"`
|
||||
Created time.Time `xorm:"created"`
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"INDEX NOT NULL"`
|
||||
OwnerID int64 `xorm:"INDEX NOT NULL"`
|
||||
Owner *user_model.User `xorm:"-"`
|
||||
Path string `xorm:"TEXT"`
|
||||
Created time.Time `xorm:"created"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -37,6 +39,35 @@ func (l *LFSLock) BeforeInsert() {
|
|||
l.Path = util.PathJoinRel(l.Path)
|
||||
}
|
||||
|
||||
// LoadAttributes loads attributes of the lock.
|
||||
func (l *LFSLock) LoadAttributes(ctx context.Context) error {
|
||||
// Load owner
|
||||
if err := l.LoadOwner(ctx); err != nil {
|
||||
return fmt.Errorf("load owner: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadOwner loads owner of the lock.
|
||||
func (l *LFSLock) LoadOwner(ctx context.Context) error {
|
||||
if l.Owner != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
owner, err := user_model.GetUserByID(ctx, l.OwnerID)
|
||||
if err != nil {
|
||||
if user_model.IsErrUserNotExist(err) {
|
||||
l.Owner = user_model.NewGhostUser()
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
l.Owner = owner
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateLFSLock creates a new lock.
|
||||
func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) {
|
||||
dbCtx, committer, err := db.TxContext(ctx)
|
||||
|
@ -94,7 +125,7 @@ func GetLFSLockByID(ctx context.Context, id int64) (*LFSLock, error) {
|
|||
}
|
||||
|
||||
// GetLFSLockByRepoID returns a list of locks of repository.
|
||||
func GetLFSLockByRepoID(ctx context.Context, repoID int64, page, pageSize int) ([]*LFSLock, error) {
|
||||
func GetLFSLockByRepoID(ctx context.Context, repoID int64, page, pageSize int) (LFSLockList, error) {
|
||||
e := db.GetEngine(ctx)
|
||||
if page >= 0 && pageSize > 0 {
|
||||
start := 0
|
||||
|
@ -103,7 +134,7 @@ func GetLFSLockByRepoID(ctx context.Context, repoID int64, page, pageSize int) (
|
|||
}
|
||||
e.Limit(pageSize, start)
|
||||
}
|
||||
lfsLocks := make([]*LFSLock, 0, pageSize)
|
||||
lfsLocks := make(LFSLockList, 0, pageSize)
|
||||
return lfsLocks, e.Find(&lfsLocks, &LFSLock{RepoID: repoID})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue