forked from forgejo/forgejo
Issues overview should not show issues from archived repos (#13220)
* Add lots of comments to user.Issues() * Answered some questions from comments * fix typo in comment * Refac user.Issues(): add func repoIDs * Refac user.Issues(): add func userRepoIDs * Refac user.Issues(): add func issueIDsFromSearch * Refac user.Issues(): improve error handling * Refac user.Issues(): add inline documentation and move variable declarations closer to their usages * Refac user.Issues(): add func repoIDMap * Refac user.Issues(): cleanup * Refac: Separate Issues from Pulls during routing * fix typo in comment * Adapt Unittests to Refactoring * Issue13171: Issue and PR Overviews now ignore archived Repositories * changed some verbatim SQL conditions to builder.Eq * models/issue.go: use OptionalBool properly Co-authored-by: 6543 <6543@obermui.de> * Use IsArchived rather than ExcludeArchivedRepos * fixed broken test after merge * added nil check * Added Unit Test securing Issue 13171 fix * Improved IsArchived filtering in issue.GetUserIssueStats * Removed unused func * Added grouping to avoid returning duplicate repo IDs Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Gitea <gitea@fake.local> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
81467e6f35
commit
564030336d
14 changed files with 494 additions and 167 deletions
|
@ -503,6 +503,23 @@ func (u *User) GetRepositoryIDs(units ...UnitType) ([]int64, error) {
|
|||
return ids, sess.Where("owner_id = ?", u.ID).Find(&ids)
|
||||
}
|
||||
|
||||
// GetActiveRepositoryIDs returns non-archived repositories IDs where user owned and has unittypes
|
||||
// Caller shall check that units is not globally disabled
|
||||
func (u *User) GetActiveRepositoryIDs(units ...UnitType) ([]int64, error) {
|
||||
var ids []int64
|
||||
|
||||
sess := x.Table("repository").Cols("repository.id")
|
||||
|
||||
if len(units) > 0 {
|
||||
sess = sess.Join("INNER", "repo_unit", "repository.id = repo_unit.repo_id")
|
||||
sess = sess.In("repo_unit.type", units)
|
||||
}
|
||||
|
||||
sess.Where(builder.Eq{"is_archived": false})
|
||||
|
||||
return ids, sess.Where("owner_id = ?", u.ID).GroupBy("repository.id").Find(&ids)
|
||||
}
|
||||
|
||||
// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
|
||||
// Caller shall check that units is not globally disabled
|
||||
func (u *User) GetOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
|
||||
|
@ -524,6 +541,28 @@ func (u *User) GetOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
|
|||
return ids, nil
|
||||
}
|
||||
|
||||
// GetActiveOrgRepositoryIDs returns non-archived repositories IDs where user's team owned and has unittypes
|
||||
// Caller shall check that units is not globally disabled
|
||||
func (u *User) GetActiveOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
|
||||
var ids []int64
|
||||
|
||||
if err := x.Table("repository").
|
||||
Cols("repository.id").
|
||||
Join("INNER", "team_user", "repository.owner_id = team_user.org_id").
|
||||
Join("INNER", "team_repo", "(? != ? and repository.is_private != ?) OR (team_user.team_id = team_repo.team_id AND repository.id = team_repo.repo_id)", true, u.IsRestricted, true).
|
||||
Where("team_user.uid = ?", u.ID).
|
||||
Where(builder.Eq{"is_archived": false}).
|
||||
GroupBy("repository.id").Find(&ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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
|
||||
// Caller shall check that units is not globally disabled
|
||||
func (u *User) GetAccessRepoIDs(units ...UnitType) ([]int64, error) {
|
||||
|
@ -538,6 +577,20 @@ func (u *User) GetAccessRepoIDs(units ...UnitType) ([]int64, error) {
|
|||
return append(ids, ids2...), nil
|
||||
}
|
||||
|
||||
// GetActiveAccessRepoIDs returns all non-archived repositories IDs where user's or user is a team member organizations
|
||||
// Caller shall check that units is not globally disabled
|
||||
func (u *User) GetActiveAccessRepoIDs(units ...UnitType) ([]int64, error) {
|
||||
ids, err := u.GetActiveRepositoryIDs(units...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids2, err := u.GetActiveOrgRepositoryIDs(units...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append(ids, ids2...), nil
|
||||
}
|
||||
|
||||
// GetMirrorRepositories returns mirror repositories that user owns, including private repositories.
|
||||
func (u *User) GetMirrorRepositories() ([]*Repository, error) {
|
||||
return GetUserMirrorRepositories(u.ID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue