mirror of
https://github.com/go-gitea/gitea
synced 2025-07-16 07:18:37 +00:00
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user