diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index ce0de3a..d73f3c7 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -22,13 +22,8 @@ self: IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator => get("/dashboard/repos")(usersOnly { - val userName = context.loginAccount.get.userName - - html.repos( - getGroupNames(userName), - getVisibleRepositories(None, withoutPhysicalInfo = true), - getUserRepositories(userName, withoutPhysicalInfo = true) - ) + val repos = getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) + html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos) }) get("/dashboard/issues")(usersOnly { @@ -93,7 +88,7 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(None, withoutPhysicalInfo = true) + getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) ) } @@ -118,7 +113,7 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(None, withoutPhysicalInfo = true) + getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) ) } diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index d7b3f5a..7770ccc 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -64,7 +64,7 @@ val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName) gitbucket.core.html.index( getRecentActivitiesByOwners(visibleOwnerSet), - getVisibleRepositories(None, withoutPhysicalInfo = true), + getVisibleRepositories(Some(account), withoutPhysicalInfo = true), showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken( account.userName ) diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 8b15a68..08f077d 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -371,6 +371,10 @@ .list } + /** + * Returns the list of repositories which are owned by the specified user. + * This list includes group repositories if the specified user is a member of the group. + */ def getUserRepositories(userName: String, withoutPhysicalInfo: Boolean = false)( implicit s: Session ): List[RepositoryInfo] = { @@ -388,29 +392,7 @@ } .sortBy(_.lastActivityDate desc) .list - .map { repository => - new RepositoryInfo( - if (withoutPhysicalInfo) { - new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName) - } else { - JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName) - }, - repository, - if (withoutPhysicalInfo) { - -1 - } else { - getForkedCount( - repository.originUserName.getOrElse(repository.userName), - repository.originRepositoryName.getOrElse(repository.repositoryName) - ) - }, - if (withoutPhysicalInfo) { - Nil - } else { - getRepositoryManagers(repository.userName, repository.repositoryName) - } - ) - } + .map(createRepositoryInfo(_, withoutPhysicalInfo)) } /** @@ -466,29 +448,33 @@ } .sortBy(_.lastActivityDate desc) .list - .map { repository => - new RepositoryInfo( - if (withoutPhysicalInfo) { - new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName) - } else { - JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName) - }, - repository, - if (withoutPhysicalInfo) { - -1 - } else { - getForkedCount( - repository.originUserName.getOrElse(repository.userName), - repository.originRepositoryName.getOrElse(repository.repositoryName) - ) - }, - if (withoutPhysicalInfo) { - Nil - } else { - getRepositoryManagers(repository.userName, repository.repositoryName) - } + .map(createRepositoryInfo(_, withoutPhysicalInfo)) + } + + private def createRepositoryInfo(repository: Repository, withoutPhysicalInfo: Boolean = false)( + implicit s: Session + ): RepositoryInfo = { + new RepositoryInfo( + if (withoutPhysicalInfo) { + new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName) + } else { + JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName) + }, + repository, + if (withoutPhysicalInfo) { + -1 + } else { + getForkedCount( + repository.originUserName.getOrElse(repository.userName), + repository.originRepositoryName.getOrElse(repository.repositoryName) ) + }, + if (withoutPhysicalInfo) { + Nil + } else { + getRepositoryManagers(repository.userName, repository.repositoryName) } + ) } /** diff --git a/src/main/twirl/gitbucket/core/dashboard/repos.scala.html b/src/main/twirl/gitbucket/core/dashboard/repos.scala.html index a3ac8c6..5a9b5a0 100644 --- a/src/main/twirl/gitbucket/core/dashboard/repos.scala.html +++ b/src/main/twirl/gitbucket/core/dashboard/repos.scala.html @@ -1,6 +1,6 @@ @(groups: List[String], - recentRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo], - userRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo])(implicit context: gitbucket.core.controller.Context) + visibleRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo], + recentRepositories: List[gitbucket.core.service.RepositoryService.RepositoryInfo])(implicit context: gitbucket.core.controller.Context) @import gitbucket.core.view.helpers @gitbucket.core.html.main("Repositories"){ @gitbucket.core.dashboard.html.sidebar(recentRepositories){ @@ -13,15 +13,15 @@
- @if(userRepositories.isEmpty){ + @if(visibleRepositories.isEmpty){ No repositories } else { - @userRepositories.map { repository => + @visibleRepositories.map { repository =>