diff options
Diffstat (limited to 'models/lfs_lock.go')
-rw-r--r-- | models/lfs_lock.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/models/lfs_lock.go b/models/lfs_lock.go index 943699290f..15513ea1dd 100644 --- a/models/lfs_lock.go +++ b/models/lfs_lock.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "xorm.io/xorm" @@ -22,7 +23,6 @@ type LFSLock struct { ID int64 `xorm:"pk autoincr"` Repo *Repository `xorm:"-"` RepoID int64 `xorm:"INDEX NOT NULL"` - Owner *User `xorm:"-"` OwnerID int64 `xorm:"INDEX NOT NULL"` Path string `xorm:"TEXT"` Created time.Time `xorm:"created"` @@ -34,7 +34,6 @@ func init() { // BeforeInsert is invoked from XORM before inserting an object of this type. func (l *LFSLock) BeforeInsert() { - l.OwnerID = l.Owner.ID l.RepoID = l.Repo.ID l.Path = cleanPath(l.Path) } @@ -42,10 +41,6 @@ func (l *LFSLock) BeforeInsert() { // AfterLoad is invoked from XORM after setting the values of all fields of this object. func (l *LFSLock) AfterLoad(session *xorm.Session) { var err error - l.Owner, err = getUserByID(session, l.OwnerID) - if err != nil { - log.Error("LFS lock AfterLoad failed OwnerId[%d] not found: %v", l.OwnerID, err) - } l.Repo, err = getRepositoryByID(session, l.RepoID) if err != nil { log.Error("LFS lock AfterLoad failed RepoId[%d] not found: %v", l.RepoID, err) @@ -58,7 +53,7 @@ func cleanPath(p string) string { // CreateLFSLock creates a new lock. func CreateLFSLock(lock *LFSLock) (*LFSLock, error) { - err := CheckLFSAccessForRepo(lock.Owner, lock.Repo, AccessModeWrite) + err := CheckLFSAccessForRepo(lock.OwnerID, lock.Repo, AccessModeWrite) if err != nil { return nil, err } @@ -123,13 +118,13 @@ func CountLFSLockByRepoID(repoID int64) (int64, error) { } // DeleteLFSLockByID deletes a lock by given ID. -func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) { +func DeleteLFSLockByID(id int64, u *user_model.User, force bool) (*LFSLock, error) { lock, err := GetLFSLockByID(id) if err != nil { return nil, err } - err = CheckLFSAccessForRepo(u, lock.Repo, AccessModeWrite) + err = CheckLFSAccessForRepo(u.ID, lock.Repo, AccessModeWrite) if err != nil { return nil, err } @@ -143,10 +138,14 @@ func DeleteLFSLockByID(id int64, u *User, force bool) (*LFSLock, error) { } // CheckLFSAccessForRepo check needed access mode base on action -func CheckLFSAccessForRepo(u *User, repo *Repository, mode AccessMode) error { - if u == nil { +func CheckLFSAccessForRepo(ownerID int64, repo *Repository, mode AccessMode) error { + if ownerID == 0 { return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode} } + u, err := user_model.GetUserByID(ownerID) + if err != nil { + return err + } perm, err := GetUserRepoPermission(repo, u) if err != nil { return err |