diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2020-01-05 02:23:29 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-04 20:23:29 -0500 |
commit | 03d59bcd1dc775b6b8e52136dff1ba508838db2d (patch) | |
tree | b56863f88397cf65569bbcf07acb3ec1d7a49986 /models/repo_permission.go | |
parent | 8b2407371365fc123fc368bfd46b15f55ba8ae6a (diff) | |
download | gitea-03d59bcd1dc775b6b8e52136dff1ba508838db2d.tar.gz gitea-03d59bcd1dc775b6b8e52136dff1ba508838db2d.zip |
Fix access issues on milestone and issue overview pages. (#9603)
* Fix access issues on milestone and issue overview pages.
* Fix filter algorithm
Diffstat (limited to 'models/repo_permission.go')
-rw-r--r-- | models/repo_permission.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/models/repo_permission.go b/models/repo_permission.go index 782b195629..79d7dd012b 100644 --- a/models/repo_permission.go +++ b/models/repo_permission.go @@ -369,3 +369,23 @@ func hasAccess(e Engine, userID int64, repo *Repository) (bool, error) { func HasAccess(userID int64, repo *Repository) (bool, error) { return hasAccess(x, userID, repo) } + +// FilterOutRepoIdsWithoutUnitAccess filter out repos where user has no access to repositories +func FilterOutRepoIdsWithoutUnitAccess(u *User, repoIDs []int64, units ...UnitType) ([]int64, error) { + i := 0 + for _, rID := range repoIDs { + repo, err := GetRepositoryByID(rID) + if err != nil { + return nil, err + } + perm, err := GetUserRepoPermission(repo, u) + if err != nil { + return nil, err + } + if perm.CanReadAny(units...) { + repoIDs[i] = rID + i++ + } + } + return repoIDs[:i], nil +} |