@@ -1343,6 +1343,48 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
13431343 }
13441344}
13451345
1346+ // teamUnitsRepoCond returns query condition for those repo id in the special org team with special units access
1347+ func teamUnitsRepoCond (id string , userID , orgID , teamID int64 , units ... unit.Type ) builder.Cond {
1348+ return builder .In (id ,
1349+ builder .Select ("repo_id" ).From ("team_repo" ).Where (
1350+ builder.Eq {
1351+ "team_id" : teamID ,
1352+ }.And (
1353+ builder .Or (
1354+ // Check if the user is member of the team.
1355+ builder .In (
1356+ "team_id" , builder .Select ("team_id" ).From ("team_user" ).Where (
1357+ builder.Eq {
1358+ "uid" : userID ,
1359+ },
1360+ ),
1361+ ),
1362+ // Check if the user is in the owner team of the organisation.
1363+ builder .Exists (builder .Select ("team_id" ).From ("team_user" ).
1364+ Where (builder.Eq {
1365+ "org_id" : orgID ,
1366+ "team_id" : builder .Select ("id" ).From ("team" ).Where (
1367+ builder.Eq {
1368+ "org_id" : orgID ,
1369+ "lower_name" : strings .ToLower (organization .OwnerTeamName ),
1370+ }),
1371+ "uid" : userID ,
1372+ }),
1373+ ),
1374+ )).And (
1375+ builder .In (
1376+ "team_id" , builder .Select ("team_id" ).From ("team_unit" ).Where (
1377+ builder.Eq {
1378+ "`team_unit`.org_id" : orgID ,
1379+ }.And (
1380+ builder .In ("`team_unit`.type" , units ),
1381+ ),
1382+ ),
1383+ ),
1384+ ),
1385+ ))
1386+ }
1387+
13461388// issuePullAccessibleRepoCond userID must not be zero, this condition require join repository table
13471389func issuePullAccessibleRepoCond (repoIDstr string , userID int64 , org * organization.Organization , team * organization.Team , isPull bool ) builder.Cond {
13481390 cond := builder .NewCond ()
@@ -1356,19 +1398,19 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
13561398 } else {
13571399 cond = cond .And (
13581400 builder .Or (
1359- userOrgUnitRepoCond (repoIDstr , userID , org .ID , unitType ), // team member repos
1360- userOrgPublicUnitRepoCond (userID , org .ID ), // user org public non-member repos, TODO: check repo has issues
1401+ repo_model . UserOrgUnitRepoCond (repoIDstr , userID , org .ID , unitType ), // team member repos
1402+ repo_model . UserOrgPublicUnitRepoCond (userID , org .ID ), // user org public non-member repos, TODO: check repo has issues
13611403 ),
13621404 )
13631405 }
13641406 } else {
13651407 cond = cond .And (
13661408 builder .Or (
1367- userOwnedRepoCond (userID ), // owned repos
1368- userCollaborationRepoCond (repoIDstr , userID ), // collaboration repos
1369- userAssignedRepoCond (repoIDstr , userID ), // user has been assigned accessible public repos
1370- userMentionedRepoCond (repoIDstr , userID ), // user has been mentioned accessible public repos
1371- userCreateIssueRepoCond (repoIDstr , userID , isPull ), // user has created issue/pr accessible public repos
1409+ repo_model . UserOwnedRepoCond (userID ), // owned repos
1410+ repo_model . UserCollaborationRepoCond (repoIDstr , userID ), // collaboration repos
1411+ repo_model . UserAssignedRepoCond (repoIDstr , userID ), // user has been assigned accessible public repos
1412+ repo_model . UserMentionedRepoCond (repoIDstr , userID ), // user has been mentioned accessible public repos
1413+ repo_model . UserCreateIssueRepoCond (repoIDstr , userID , isPull ), // user has created issue/pr accessible public repos
13721414 ),
13731415 )
13741416 }
@@ -1434,7 +1476,7 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
14341476
14351477 opts .setupSessionNoLimit (sess )
14361478
1437- accessCond := accessibleRepositoryCondition (user )
1479+ accessCond := repo_model . AccessibleRepositoryCondition (user )
14381480 if err := sess .Where (accessCond ).
14391481 Distinct ("issue.repo_id" ).
14401482 Table ("issue" ).
0 commit comments