@@ -503,6 +503,23 @@ func (u *User) GetRepositoryIDs(units ...UnitType) ([]int64, error) {
503
503
return ids , sess .Where ("owner_id = ?" , u .ID ).Find (& ids )
504
504
}
505
505
506
+ // GetActiveRepositoryIDs returns non-archived repositories IDs where user owned and has unittypes
507
+ // Caller shall check that units is not globally disabled
508
+ func (u * User ) GetActiveRepositoryIDs (units ... UnitType ) ([]int64 , error ) {
509
+ var ids []int64
510
+
511
+ sess := x .Table ("repository" ).Cols ("repository.id" )
512
+
513
+ if len (units ) > 0 {
514
+ sess = sess .Join ("INNER" , "repo_unit" , "repository.id = repo_unit.repo_id" )
515
+ sess = sess .In ("repo_unit.type" , units )
516
+ }
517
+
518
+ sess .Where (builder.Eq {"is_archived" : false })
519
+
520
+ return ids , sess .Where ("owner_id = ?" , u .ID ).GroupBy ("repository.id" ).Find (& ids )
521
+ }
522
+
506
523
// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
507
524
// Caller shall check that units is not globally disabled
508
525
func (u * User ) GetOrgRepositoryIDs (units ... UnitType ) ([]int64 , error ) {
@@ -524,6 +541,28 @@ func (u *User) GetOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
524
541
return ids , nil
525
542
}
526
543
544
+ // GetActiveOrgRepositoryIDs returns non-archived repositories IDs where user's team owned and has unittypes
545
+ // Caller shall check that units is not globally disabled
546
+ func (u * User ) GetActiveOrgRepositoryIDs (units ... UnitType ) ([]int64 , error ) {
547
+ var ids []int64
548
+
549
+ if err := x .Table ("repository" ).
550
+ Cols ("repository.id" ).
551
+ Join ("INNER" , "team_user" , "repository.owner_id = team_user.org_id" ).
552
+ 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 ).
553
+ Where ("team_user.uid = ?" , u .ID ).
554
+ Where (builder.Eq {"is_archived" : false }).
555
+ GroupBy ("repository.id" ).Find (& ids ); err != nil {
556
+ return nil , err
557
+ }
558
+
559
+ if len (units ) > 0 {
560
+ return FilterOutRepoIdsWithoutUnitAccess (u , ids , units ... )
561
+ }
562
+
563
+ return ids , nil
564
+ }
565
+
527
566
// GetAccessRepoIDs returns all repositories IDs where user's or user is a team member organizations
528
567
// Caller shall check that units is not globally disabled
529
568
func (u * User ) GetAccessRepoIDs (units ... UnitType ) ([]int64 , error ) {
@@ -538,6 +577,20 @@ func (u *User) GetAccessRepoIDs(units ...UnitType) ([]int64, error) {
538
577
return append (ids , ids2 ... ), nil
539
578
}
540
579
580
+ // GetActiveAccessRepoIDs returns all non-archived repositories IDs where user's or user is a team member organizations
581
+ // Caller shall check that units is not globally disabled
582
+ func (u * User ) GetActiveAccessRepoIDs (units ... UnitType ) ([]int64 , error ) {
583
+ ids , err := u .GetActiveRepositoryIDs (units ... )
584
+ if err != nil {
585
+ return nil , err
586
+ }
587
+ ids2 , err := u .GetActiveOrgRepositoryIDs (units ... )
588
+ if err != nil {
589
+ return nil , err
590
+ }
591
+ return append (ids , ids2 ... ), nil
592
+ }
593
+
541
594
// GetMirrorRepositories returns mirror repositories that user owns, including private repositories.
542
595
func (u * User ) GetMirrorRepositories () ([]* Repository , error ) {
543
596
return GetUserMirrorRepositories (u .ID )
0 commit comments