@@ -1239,7 +1239,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
1239
1239
}
1240
1240
}
1241
1241
1242
- func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) {
1242
+ func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) error {
1243
1243
if opts .Page >= 0 && opts .PageSize > 0 {
1244
1244
var start int
1245
1245
if opts .Page == 0 {
@@ -1249,10 +1249,10 @@ func (opts *IssuesOptions) setupSessionWithLimit(sess *xorm.Session) {
1249
1249
}
1250
1250
sess .Limit (opts .PageSize , start )
1251
1251
}
1252
- opts .setupSessionNoLimit (sess )
1252
+ return opts .setupSessionNoLimit (sess )
1253
1253
}
1254
1254
1255
- func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) {
1255
+ func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) error {
1256
1256
if len (opts .IssueIDs ) > 0 {
1257
1257
sess .In ("issue.id" , opts .IssueIDs )
1258
1258
}
@@ -1346,22 +1346,51 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
1346
1346
}
1347
1347
1348
1348
if opts .User != nil {
1349
- sess .And (
1350
- issuePullAccessibleRepoCond ("issue.repo_id" , opts .User .ID , opts .Org , opts .Team , opts .IsPull .IsTrue ()),
1351
- )
1349
+ repoCond , err := issuePullAccessibleRepoCond ("issue.repo_id" , opts .User .ID , opts .Org , opts .Team , opts .IsPull .IsTrue ())
1350
+ if err != nil {
1351
+ return err
1352
+ }
1353
+ sess .And (repoCond )
1354
+
1352
1355
}
1356
+ return nil
1353
1357
}
1354
1358
1355
1359
// issuePullAccessibleRepoCond userID must not be zero, this condition require join repository table
1356
- func issuePullAccessibleRepoCond (repoIDstr string , userID int64 , org * Organization , team * Team , isPull bool ) builder.Cond {
1360
+ func issuePullAccessibleRepoCond (repoIDstr string , userID int64 , org * Organization , team * Team , isPull bool ) ( builder.Cond , error ) {
1357
1361
cond := builder .NewCond ()
1358
1362
unitType := unit .TypeIssues
1359
1363
if isPull {
1360
1364
unitType = unit .TypePullRequests
1361
1365
}
1362
1366
if org != nil {
1363
1367
if team != nil {
1364
- cond = cond .And (teamUnitsRepoCond (repoIDstr , userID , org .ID , team .ID , unitType )) // special team member repos
1368
+ // If the current user is a admin, it doesn't necesarly mean
1369
+ // it has joined the team, but we still should return all repo's
1370
+ // of that team.
1371
+ isAdmin , err := org .IsOwnedBy (userID )
1372
+ if err != nil {
1373
+ return nil , err
1374
+ }
1375
+ if isAdmin {
1376
+ cond = cond .And (builder .In (repoIDstr ,
1377
+ builder .Select ("repo_id" ).From ("team_repo" ).Where (
1378
+ builder.Eq {
1379
+ "team_id" : team .ID ,
1380
+ }.And (
1381
+ builder .In (
1382
+ "team_id" , builder .Select ("team_id" ).From ("team_unit" ).Where (
1383
+ builder.Eq {
1384
+ "`team_unit`.org_id" : org .ID ,
1385
+ "`team_unit`.type" : unitType ,
1386
+ },
1387
+ ),
1388
+ ),
1389
+ ),
1390
+ )))
1391
+ } else {
1392
+ cond = cond .And (teamUnitsRepoCond (repoIDstr , userID , org .ID , team .ID , unitType )) // special team member repos
1393
+ }
1365
1394
} else {
1366
1395
cond = cond .And (
1367
1396
builder .Or (
@@ -1381,7 +1410,7 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *Organizati
1381
1410
),
1382
1411
)
1383
1412
}
1384
- return cond
1413
+ return cond , nil
1385
1414
}
1386
1415
1387
1416
func applyAssigneeCondition (sess * xorm.Session , assigneeID int64 ) * xorm.Session {
@@ -1414,7 +1443,9 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1414
1443
1415
1444
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1416
1445
1417
- opts .setupSessionNoLimit (sess )
1446
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1447
+ return nil , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1448
+ }
1418
1449
1419
1450
countsSlice := make ([]* struct {
1420
1451
RepoID int64
@@ -1441,7 +1472,9 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
1441
1472
1442
1473
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1443
1474
1444
- opts .setupSessionNoLimit (sess )
1475
+ if err := opts .setupSessionWithLimit (sess ); err != nil {
1476
+ return nil , fmt .Errorf ("setupSessionWithLimit: %v" , err )
1477
+ }
1445
1478
1446
1479
accessCond := accessibleRepositoryCondition (user )
1447
1480
if err := sess .Where (accessCond ).
@@ -1459,7 +1492,9 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
1459
1492
e := db .GetEngine (db .DefaultContext )
1460
1493
1461
1494
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1462
- opts .setupSessionWithLimit (sess )
1495
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1496
+ return nil , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1497
+ }
1463
1498
sortIssuesSession (sess , opts .SortType , opts .PriorityRepoID )
1464
1499
1465
1500
issues := make ([]* Issue , 0 , opts .ListOptions .PageSize )
@@ -1484,7 +1519,9 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
1484
1519
1485
1520
sess := e .Select ("COUNT(issue.id) AS count" ).Table ("issue" )
1486
1521
sess .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1487
- opts .setupSessionNoLimit (sess )
1522
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1523
+ return 0 , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1524
+ }
1488
1525
if err := sess .Find (& countsSlice ); err != nil {
1489
1526
return 0 , fmt .Errorf ("unable to CountIssues: %w" , err )
1490
1527
}
@@ -1717,7 +1754,11 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
1717
1754
}
1718
1755
1719
1756
if opts .UserID > 0 {
1720
- cond = cond .And (issuePullAccessibleRepoCond ("issue.repo_id" , opts .UserID , opts .Org , opts .Team , opts .IsPull ))
1757
+ repoCond , err := issuePullAccessibleRepoCond ("issue.repo_id" , opts .UserID , opts .Org , opts .Team , opts .IsPull )
1758
+ if err != nil {
1759
+ return nil , err
1760
+ }
1761
+ cond = cond .And (repoCond )
1721
1762
}
1722
1763
1723
1764
sess := func (cond builder.Cond ) * xorm.Session {
0 commit comments