diff options
author | 赵智超 <1012112796@qq.com> | 2020-09-16 07:49:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-15 19:49:34 -0400 |
commit | ec5677b7a2f56e124eaaa53291e21d6260354c12 (patch) | |
tree | c2b51f68e6a21301c4d497419d06d627172448ec /models/repo.go | |
parent | 07995e23018b5aa3906884f3c80ea5181250121e (diff) | |
download | gitea-ec5677b7a2f56e124eaaa53291e21d6260354c12.tar.gz gitea-ec5677b7a2f56e124eaaa53291e21d6260354c12.zip |
Simplify CheckUnitUser logic (#12854)
if check one user's unit in different repos, it's not necessary to
get user data every time.
Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/models/repo.go b/models/repo.go index d9b6576976..2bbc74f439 100644 --- a/models/repo.go +++ b/models/repo.go @@ -425,20 +425,17 @@ func (repo *Repository) getUnits(e Engine) (err error) { } // CheckUnitUser check whether user could visit the unit of this repository -func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool { - return repo.checkUnitUser(x, userID, isAdmin, unitType) +func (repo *Repository) CheckUnitUser(user *User, unitType UnitType) bool { + return repo.checkUnitUser(x, user, unitType) } -func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool { - if isAdmin { +func (repo *Repository) checkUnitUser(e Engine, user *User, unitType UnitType) bool { + if user.IsAdmin { return true } - user, err := getUserByID(e, userID) - if err != nil { - return false - } perm, err := getUserRepoPermission(e, repo, user) if err != nil { + log.Error("getUserRepoPermission(): %v", err) return false } |