mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Fix access issues on milestone and issue overview pages. (#9603)
* Fix access issues on milestone and issue overview pages. * Fix filter algorithm
This commit is contained in:
parent
8b24073713
commit
03d59bcd1d
3 changed files with 65 additions and 54 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -638,19 +638,20 @@ func (u *User) GetRepositoryIDs(units ...UnitType) ([]int64, error) {
|
|||
func (u *User) GetOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
|
||||
var ids []int64
|
||||
|
||||
sess := x.Table("repository").
|
||||
if err := x.Table("repository").
|
||||
Cols("repository.id").
|
||||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
|
||||
Join("INNER", "team_repo", "repository.is_private != ? OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true)
|
||||
|
||||
if len(units) > 0 {
|
||||
sess = sess.Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id")
|
||||
sess = sess.In("team_unit.type", units)
|
||||
Join("INNER", "team_repo", "repository.is_private != ? OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true).
|
||||
Where("team_user.uid = ?", u.ID).
|
||||
GroupBy("repository.id").Find(&ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ids, sess.
|
||||
Where("team_user.uid = ?", u.ID).
|
||||
GroupBy("repository.id").Find(&ids)
|
||||
if len(units) > 0 {
|
||||
return FilterOutRepoIdsWithoutUnitAccess(u, ids, units...)
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetAccessRepoIDs returns all repositories IDs where user's or user is a team member organizations
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue