@ -403,27 +403,26 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// - Count Issues by repo
// - Count Issues by repo
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
isPullList := unitType == unit . TypePullRequests
opts := & models . IssuesOptions {
IsPull : util . OptionalBoolOf ( isPullList ) ,
SortType : sortType ,
IsArchived : util . OptionalBoolFalse ,
}
// Get repository IDs where User/Org/Team has access.
// Get repository IDs where User/Org/Team has access.
var team * models . Team
var team * models . Team
var org * models . Organization
if ctx . Org != nil {
if ctx . Org != nil {
org = ctx . Org . Organization
team = ctx . Org . Team
team = ctx . Org . Team
}
}
userRepoIDs , err := getActiveUserRepoIDs ( ctxUser , team , unitType )
if err != nil {
isPullList := unitType == unit . TypePullRequests
ctx . ServerError ( "userRepoIDs" , err )
opts := & models . IssuesOptions {
return
IsPull : util . OptionalBoolOf ( isPullList ) ,
SortType : sortType ,
IsArchived : util . OptionalBoolFalse ,
Org : org ,
Team : team ,
User : ctx . User ,
}
}
switch filterMode {
switch filterMode {
case models . FilterModeAll :
case models . FilterModeAll :
opts . RepoIDs = userRepoIDs
case models . FilterModeAssign :
case models . FilterModeAssign :
opts . AssigneeID = ctx . User . ID
opts . AssigneeID = ctx . User . ID
case models . FilterModeCreate :
case models . FilterModeCreate :
@ -434,10 +433,6 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
opts . ReviewRequestedID = ctx . User . ID
opts . ReviewRequestedID = ctx . User . ID
}
}
if ctxUser . IsOrganization ( ) {
opts . RepoIDs = userRepoIDs
}
// keyword holds the search term entered into the search field.
// keyword holds the search term entered into the search field.
keyword := strings . Trim ( ctx . FormString ( "q" ) , " " )
keyword := strings . Trim ( ctx . FormString ( "q" ) , " " )
ctx . Data [ "Keyword" ] = keyword
ctx . Data [ "Keyword" ] = keyword
@ -524,28 +519,26 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// ----------------------------------
// ----------------------------------
// showReposMap maps repository IDs to their Repository pointers.
// showReposMap maps repository IDs to their Repository pointers.
showReposMap , err := repoIDMap ( ctxUser , issueCountByRepo , unitType )
showReposMap , err := loadRepoByIDs ( ctxUser , issueCountByRepo , unitType )
if err != nil {
if err != nil {
if repo_model . IsErrRepoNotExist ( err ) {
if repo_model . IsErrRepoNotExist ( err ) {
ctx . NotFound ( "GetRepositoryByID" , err )
ctx . NotFound ( "GetRepositoryByID" , err )
return
return
}
}
ctx . ServerError ( "repoIDMap " , err )
ctx . ServerError ( "loadRepoByIDs " , err )
return
return
}
}
// a RepositoryList
// a RepositoryList
showRepos := models . RepositoryListOfMap ( showReposMap )
showRepos := models . RepositoryListOfMap ( showReposMap )
sort . Sort ( showRepos )
sort . Sort ( showRepos )
if err = showRepos . LoadAttributes ( ) ; err != nil {
ctx . ServerError ( "LoadAttributes" , err )
return
}
// maps pull request IDs to their CommitStatus. Will be posted to ctx.Data.
// maps pull request IDs to their CommitStatus. Will be posted to ctx.Data.
for _ , issue := range issues {
for _ , issue := range issues {
if issue . Repo == nil {
issue . Repo = showReposMap [ issue . RepoID ]
issue . Repo = showReposMap [ issue . RepoID ]
}
}
}
commitStatus , err := pull_service . GetIssuesLastCommitStatus ( issues )
commitStatus , err := pull_service . GetIssuesLastCommitStatus ( issues )
if err != nil {
if err != nil {
@ -556,86 +549,39 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// -------------------------------
// -------------------------------
// Fill stats to post to ctx.Data.
// Fill stats to post to ctx.Data.
// -------------------------------
// -------------------------------
var issueStats * models . IssueStats
userIssueStatsOpts := models . UserIssueStatsOptions {
UserID : ctx . User . ID ,
UserRepoIDs : userRepoIDs ,
FilterMode : filterMode ,
IsPull : isPullList ,
IsClosed : isShowClosed ,
IsArchived : util . OptionalBoolFalse ,
LabelIDs : opts . LabelIDs ,
}
if len ( repoIDs ) > 0 {
userIssueStatsOpts . UserRepoIDs = repoIDs
}
if ctxUser . IsOrganization ( ) {
userIssueStatsOpts . RepoIDs = userRepoIDs
}
userIssueStats , err := models . GetUserIssueStats ( userIssueStatsOpts )
if err != nil {
ctx . ServerError ( "GetUserIssueStats User" , err )
return
}
var shownIssueStats * models . IssueStats
if ! forceEmpty {
if ! forceEmpty {
statsOpts := models . UserIssueStatsOptions {
statsOpts := models . UserIssueStatsOptions {
UserID : ctx . User . ID ,
UserID : ctx . User . ID ,
UserRepoIDs : userRepoIDs ,
FilterMode : filterMode ,
FilterMode : filterMode ,
IsPull : isPullList ,
IsPull : isPullList ,
IsClosed : isShowClosed ,
IsClosed : isShowClosed ,
IssueIDs : issueIDsFromSearch ,
IssueIDs : issueIDsFromSearch ,
IsArchived : util . OptionalBoolFalse ,
IsArchived : util . OptionalBoolFalse ,
LabelIDs : opts . LabelIDs ,
LabelIDs : opts . LabelIDs ,
Org : org ,
Team : team ,
}
}
if len ( repoIDs ) > 0 {
if len ( repoIDs ) > 0 {
statsOpts . RepoIDs = repoIDs
statsOpts . RepoIDs = repoIDs
} else if ctxUser . IsOrganization ( ) {
statsOpts . RepoIDs = userRepoIDs
}
}
shownI ssueStats, err = models . GetUserIssueStats ( statsOpts )
issueStats , err = models . GetUserIssueStats ( statsOpts )
if err != nil {
if err != nil {
ctx . ServerError ( "GetUserIssueStats Shown" , err )
ctx . ServerError ( "GetUserIssueStats Shown" , err )
return
return
}
}
} else {
} else {
shownIssueStats = & models . IssueStats { }
issueStats = & models . IssueStats { }
}
var allIssueStats * models . IssueStats
if ! forceEmpty {
allIssueStatsOpts := models . UserIssueStatsOptions {
UserID : ctx . User . ID ,
UserRepoIDs : userRepoIDs ,
FilterMode : filterMode ,
IsPull : isPullList ,
IsClosed : isShowClosed ,
IssueIDs : issueIDsFromSearch ,
IsArchived : util . OptionalBoolFalse ,
LabelIDs : opts . LabelIDs ,
}
if ctxUser . IsOrganization ( ) {
allIssueStatsOpts . RepoIDs = userRepoIDs
}
allIssueStats , err = models . GetUserIssueStats ( allIssueStatsOpts )
if err != nil {
ctx . ServerError ( "GetUserIssueStats All" , err )
return
}
} else {
allIssueStats = & models . IssueStats { }
}
}
// Will be posted to ctx.Data.
// Will be posted to ctx.Data.
var shownIssues int
var shownIssues int
if ! isShowClosed {
if ! isShowClosed {
shownIssues = int ( shownI ssueStats. OpenCount )
shownIssues = int ( issueStats . OpenCount )
ctx . Data [ "TotalIssueCount" ] = int ( allIssueStats . OpenCount )
ctx . Data [ "TotalIssueCount" ] = shownIssues
} else {
} else {
shownIssues = int ( shownI ssueStats. ClosedCount )
shownIssues = int ( issueStats . ClosedCount )
ctx . Data [ "TotalIssueCount" ] = int ( allIssueStats . ClosedCount )
ctx . Data [ "TotalIssueCount" ] = shownIssues
}
}
ctx . Data [ "IsShowClosed" ] = isShowClosed
ctx . Data [ "IsShowClosed" ] = isShowClosed
@ -671,8 +617,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
ctx . Data [ "CommitStatus" ] = commitStatus
ctx . Data [ "CommitStatus" ] = commitStatus
ctx . Data [ "Repos" ] = showRepos
ctx . Data [ "Repos" ] = showRepos
ctx . Data [ "Counts" ] = issueCountByRepo
ctx . Data [ "Counts" ] = issueCountByRepo
ctx . Data [ "IssueStats" ] = userIssueStats
ctx . Data [ "IssueStats" ] = issueStats
ctx . Data [ "ShownIssueStats" ] = shownIssueStats
ctx . Data [ "ViewType" ] = viewType
ctx . Data [ "ViewType" ] = viewType
ctx . Data [ "SortType" ] = sortType
ctx . Data [ "SortType" ] = sortType
ctx . Data [ "RepoIDs" ] = repoIDs
ctx . Data [ "RepoIDs" ] = repoIDs
@ -730,56 +675,6 @@ func getRepoIDs(reposQuery string) []int64 {
return repoIDs
return repoIDs
}
}
func getActiveUserRepoIDs ( ctxUser * user_model . User , team * models . Team , unitType unit . Type ) ( [ ] int64 , error ) {
var userRepoIDs [ ] int64
var err error
if ctxUser . IsOrganization ( ) {
userRepoIDs , err = getActiveTeamOrOrgRepoIds ( ctxUser , team , unitType )
if err != nil {
return nil , fmt . Errorf ( "orgRepoIds: %v" , err )
}
} else {
userRepoIDs , err = models . GetActiveAccessRepoIDs ( ctxUser , unitType )
if err != nil {
return nil , fmt . Errorf ( "ctxUser.GetAccessRepoIDs: %v" , err )
}
}
if len ( userRepoIDs ) == 0 {
userRepoIDs = [ ] int64 { - 1 }
}
return userRepoIDs , nil
}
// getActiveTeamOrOrgRepoIds gets RepoIDs for ctxUser as Organization.
// Should be called if and only if ctxUser.IsOrganization == true.
func getActiveTeamOrOrgRepoIds ( ctxUser * user_model . User , team * models . Team , unitType unit . Type ) ( [ ] int64 , error ) {
var orgRepoIDs [ ] int64
var err error
var env models . AccessibleReposEnvironment
if team != nil {
env = models . OrgFromUser ( ctxUser ) . AccessibleTeamReposEnv ( team )
} else {
env , err = models . OrgFromUser ( ctxUser ) . AccessibleReposEnv ( ctxUser . ID )
if err != nil {
return nil , fmt . Errorf ( "AccessibleReposEnv: %v" , err )
}
}
orgRepoIDs , err = env . RepoIDs ( 1 , ctxUser . NumRepos )
if err != nil {
return nil , fmt . Errorf ( "env.RepoIDs: %v" , err )
}
orgRepoIDs , err = models . FilterOutRepoIdsWithoutUnitAccess ( ctxUser , orgRepoIDs , unitType )
if err != nil {
return nil , fmt . Errorf ( "FilterOutRepoIdsWithoutUnitAccess: %v" , err )
}
return orgRepoIDs , nil
}
func issueIDsFromSearch ( ctxUser * user_model . User , keyword string , opts * models . IssuesOptions ) ( [ ] int64 , error ) {
func issueIDsFromSearch ( ctxUser * user_model . User , keyword string , opts * models . IssuesOptions ) ( [ ] int64 , error ) {
if len ( keyword ) == 0 {
if len ( keyword ) == 0 {
return [ ] int64 { } , nil
return [ ] int64 { } , nil
@ -797,33 +692,27 @@ func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.I
return issueIDsFromSearch , nil
return issueIDsFromSearch , nil
}
}
func repoIDMap ( ctxUser * user_model . User , issueCountByRepo map [ int64 ] int64 , unitType unit . Type ) ( map [ int64 ] * repo_model . Repository , error ) {
func loadRepoByIDs ( ctxUser * user_model . User , issueCountByRepo map [ int64 ] int64 , unitType unit . Type ) ( map [ int64 ] * repo_model . Repository , error ) {
repoByID := make ( map [ int64 ] * repo_model . Repository , len ( issueCountByRepo ) )
var totalRes = make ( map [ int64 ] * repo_model . Repository , len ( issueCountByRepo ) )
var repoIDs = make ( [ ] int64 , 0 , 500 )
for id := range issueCountByRepo {
for id := range issueCountByRepo {
if id <= 0 {
if id <= 0 {
continue
continue
}
}
if _ , ok := repoByID [ id ] ; ! ok {
repoIDs = append ( repoIDs , id )
repo , err := repo_model . GetRepositoryByID ( id )
if len ( repoIDs ) == 500 {
if repo_model . IsErrRepoNotExist ( err ) {
if err := repo_model . FindReposMapByIDs ( repoIDs , totalRes ) ; err != nil {
return nil , err
return nil , err
} else if err != nil {
return nil , fmt . Errorf ( "GetRepositoryByID: [%d]%v" , id , err )
}
}
repoByID [ id ] = repo
repoIDs = repoIDs [ : 0 ]
}
}
repo := repoByID [ id ]
// Check if user has access to given repository.
perm , err := models . GetUserRepoPermission ( repo , ctxUser )
if err != nil {
return nil , fmt . Errorf ( "GetUserRepoPermission: [%d]%v" , id , err )
}
}
if ! perm . CanRead ( unitType ) {
if len ( repoIDs ) > 0 {
log . Debug ( "User created Issues in Repository which they no longer have access to: [%d]" , id )
if err := repo_model . FindReposMapByIDs ( repoIDs , totalRes ) ; err != nil {
return nil , err
}
}
}
}
return repoByID , nil
return totalRes , nil
}
}
// ShowSSHKeys output all the ssh keys of user by uid
// ShowSSHKeys output all the ssh keys of user by uid