@@ -1241,7 +1241,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
1241
1241
}
1242
1242
}
1243
1243
1244
- func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) {
1244
+ func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) error {
1245
1245
if opts .Page >= 0 && opts .PageSize > 0 {
1246
1246
var start int
1247
1247
if opts .Page == 0 {
@@ -1251,10 +1251,10 @@ func (opts *IssuesOptions) setupSessionWithLimit(sess *xorm.Session) {
1251
1251
}
1252
1252
sess .Limit (opts .PageSize , start )
1253
1253
}
1254
- opts .setupSessionNoLimit (sess )
1254
+ return opts .setupSessionNoLimit (sess )
1255
1255
}
1256
1256
1257
- func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) {
1257
+ func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) error {
1258
1258
if len (opts .IssueIDs ) > 0 {
1259
1259
sess .In ("issue.id" , opts .IssueIDs )
1260
1260
}
@@ -1348,22 +1348,50 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
1348
1348
}
1349
1349
1350
1350
if opts .User != nil {
1351
- sess .And (
1352
- issuePullAccessibleRepoCond ("issue.repo_id" , opts .User .ID , opts .Org , opts .Team , opts .IsPull .IsTrue ()),
1353
- )
1351
+ repoCond , err := issuePullAccessibleRepoCond ("issue.repo_id" , opts .User .ID , opts .Org , opts .Team , opts .IsPull .IsTrue ())
1352
+ if err != nil {
1353
+ return err
1354
+ }
1355
+ sess .And (repoCond )
1354
1356
}
1357
+ return nil
1355
1358
}
1356
1359
1357
1360
// issuePullAccessibleRepoCond userID must not be zero, this condition require join repository table
1358
- func issuePullAccessibleRepoCond (repoIDstr string , userID int64 , org * organization.Organization , team * organization.Team , isPull bool ) builder.Cond {
1361
+ func issuePullAccessibleRepoCond (repoIDstr string , userID int64 , org * organization.Organization , team * organization.Team , isPull bool ) ( builder.Cond , error ) {
1359
1362
cond := builder .NewCond ()
1360
1363
unitType := unit .TypeIssues
1361
1364
if isPull {
1362
1365
unitType = unit .TypePullRequests
1363
1366
}
1364
1367
if org != nil {
1365
1368
if team != nil {
1366
- cond = cond .And (teamUnitsRepoCond (repoIDstr , userID , org .ID , team .ID , unitType )) // special team member repos
1369
+ // If the current user is a admin, it doesn't necesarly mean
1370
+ // it has joined the team, but we still should return all repo's
1371
+ // of that team.
1372
+ isAdmin , err := org .IsOwnedBy (userID )
1373
+ if err != nil {
1374
+ return nil , err
1375
+ }
1376
+ if isAdmin {
1377
+ cond = cond .And (builder .In (repoIDstr ,
1378
+ builder .Select ("repo_id" ).From ("team_repo" ).Where (
1379
+ builder.Eq {
1380
+ "team_id" : team .ID ,
1381
+ }.And (
1382
+ builder .In (
1383
+ "team_id" , builder .Select ("team_id" ).From ("team_unit" ).Where (
1384
+ builder.Eq {
1385
+ "`team_unit`.org_id" : org .ID ,
1386
+ "`team_unit`.type" : unitType ,
1387
+ },
1388
+ ),
1389
+ ),
1390
+ ),
1391
+ )))
1392
+ } else {
1393
+ cond = cond .And (teamUnitsRepoCond (repoIDstr , userID , org .ID , team .ID , unitType )) // special team member repos
1394
+ }
1367
1395
} else {
1368
1396
cond = cond .And (
1369
1397
builder .Or (
@@ -1383,7 +1411,7 @@ func issuePullAccessibleRepoCond(repoIDstr string, userID int64, org *organizati
1383
1411
),
1384
1412
)
1385
1413
}
1386
- return cond
1414
+ return cond , nil
1387
1415
}
1388
1416
1389
1417
func applyAssigneeCondition (sess * xorm.Session , assigneeID int64 ) * xorm.Session {
@@ -1416,7 +1444,9 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1416
1444
1417
1445
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1418
1446
1419
- opts .setupSessionNoLimit (sess )
1447
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1448
+ return nil , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1449
+ }
1420
1450
1421
1451
countsSlice := make ([]* struct {
1422
1452
RepoID int64
@@ -1443,7 +1473,9 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
1443
1473
1444
1474
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1445
1475
1446
- opts .setupSessionNoLimit (sess )
1476
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1477
+ return nil , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1478
+ }
1447
1479
1448
1480
accessCond := accessibleRepositoryCondition (user )
1449
1481
if err := sess .Where (accessCond ).
@@ -1461,7 +1493,9 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
1461
1493
e := db .GetEngine (db .DefaultContext )
1462
1494
1463
1495
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1464
- opts .setupSessionWithLimit (sess )
1496
+ if err := opts .setupSessionWithLimit (sess ); err != nil {
1497
+ return nil , fmt .Errorf ("setupSessionWithLimit: %v" , err )
1498
+ }
1465
1499
sortIssuesSession (sess , opts .SortType , opts .PriorityRepoID )
1466
1500
1467
1501
issues := make ([]* Issue , 0 , opts .ListOptions .PageSize )
@@ -1482,7 +1516,10 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
1482
1516
1483
1517
sess := e .Select ("COUNT(issue.id) AS count" ).Table ("issue" )
1484
1518
sess .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1485
- opts .setupSessionNoLimit (sess )
1519
+ if err := opts .setupSessionNoLimit (sess ); err != nil {
1520
+ return 0 , fmt .Errorf ("setupSessionNoLimit: %v" , err )
1521
+ }
1522
+
1486
1523
return sess .Count ()
1487
1524
}
1488
1525
@@ -1709,7 +1746,11 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
1709
1746
}
1710
1747
1711
1748
if opts .UserID > 0 {
1712
- cond = cond .And (issuePullAccessibleRepoCond ("issue.repo_id" , opts .UserID , opts .Org , opts .Team , opts .IsPull ))
1749
+ repoCond , err := issuePullAccessibleRepoCond ("issue.repo_id" , opts .UserID , opts .Org , opts .Team , opts .IsPull )
1750
+ if err != nil {
1751
+ return nil , err
1752
+ }
1753
+ cond = cond .And (repoCond )
1713
1754
}
1714
1755
1715
1756
sess := func (cond builder.Cond ) * xorm.Session {
0 commit comments