diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /models/lfs_lock.go | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
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 |