diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index a67e294..5355bc1 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -27,7 +27,12 @@ self: IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator => get("/dashboard/repos")(usersOnly { - val repos = getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) + val repos = getVisibleRepositories( + context.loginAccount, + None, + withoutPhysicalInfo = true, + limit = context.settings.limitVisibleRepositories + ) html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos) }) @@ -93,7 +98,12 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) + getVisibleRepositories( + context.loginAccount, + None, + withoutPhysicalInfo = true, + limit = context.settings.limitVisibleRepositories + ) ) } @@ -118,7 +128,12 @@ }, filter, getGroupNames(userName), - getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true) + getVisibleRepositories( + context.loginAccount, + None, + withoutPhysicalInfo = true, + limit = context.settings.limitVisibleRepositories + ) ) } diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index dd80b47..a416792 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -65,7 +65,12 @@ val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName) gitbucket.core.html.index( getRecentActivitiesByOwners(visibleOwnerSet), - getVisibleRepositories(Some(account), withoutPhysicalInfo = true), + getVisibleRepositories( + Some(account), + None, + withoutPhysicalInfo = true, + limit = context.settings.limitVisibleRepositories + ), showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken( account.userName ) @@ -279,7 +284,12 @@ get("/search") { val query = params.getOrElse("query", "").trim.toLowerCase val visibleRepositories = - getVisibleRepositories(context.loginAccount, repositoryUserName = None, withoutPhysicalInfo = true) + getVisibleRepositories( + context.loginAccount, + None, + withoutPhysicalInfo = true, + limit = context.settings.limitVisibleRepositories + ) val repositories = visibleRepositories.filter { repository => repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0 } diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index ebb06dc..b105aa0 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -42,6 +42,7 @@ "gravatar" -> trim(label("Gravatar", boolean())), "notification" -> trim(label("Notification", boolean())), "activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))), + "limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())), "ssh" -> mapping( "enabled" -> trim(label("SSH access", boolean())), "host" -> trim(label("SSH host", optional(text()))), diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 3081952..2e3d881 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -459,6 +459,7 @@ /** * Returns the list of visible repositories for the specified user. * If repositoryUserName is given then filters results by repository owner. + * This function is for plugin compatibility. * * @param loginAccount the logged in account * @param repositoryUserName the repository owner (if None then returns all repositories which are visible for logged in user) @@ -470,23 +471,42 @@ loginAccount: Option[Account], repositoryUserName: Option[String] = None, withoutPhysicalInfo: Boolean = false + )(implicit s: Session): List[RepositoryInfo] = + getVisibleRepositories(loginAccount, repositoryUserName, withoutPhysicalInfo, false) + + /** + * Returns the list of visible repositories for the specified user. + * If repositoryUserName is given then filters results by repository owner. + * + * @param loginAccount the logged in account + * @param repositoryUserName the repository owner (if None then returns all repositories which are visible for logged in user) + * @param withoutPhysicalInfo if true then the result does not include physical repository information such as commit count, + * branches and tags + * @param limit if true then result will include only repositories associated with the login account. + * @return the repository information which is sorted in descending order of lastActivityDate. + */ + def getVisibleRepositories( + loginAccount: Option[Account], + repositoryUserName: Option[String], + withoutPhysicalInfo: Boolean, + limit: Boolean )(implicit s: Session): List[RepositoryInfo] = { (loginAccount match { // for Administrators - case Some(x) if (x.isAdmin) => + case Some(x) if (x.isAdmin && !limit) => Repositories .join(Accounts) .on(_.userName === _.userName) .filter { case (t1, t2) => t2.removed === false.bind } .map { case (t1, t2) => t1 } // for Normal Users - case Some(x) if (!x.isAdmin) => + case Some(x) if (!x.isAdmin || limit) => Repositories .join(Accounts) .on(_.userName === _.userName) .filter { case (t1, t2) => - (t2.removed === false.bind) && ((t1.isPrivate === false.bind) || (t1.userName === x.userName) || + (t2.removed === false.bind) && ((t1.isPrivate === false.bind && !limit.bind) || (t1.userName === x.userName) || (t1.userName in GroupMembers.filter(_.userName === x.userName.bind).map(_.groupName)) || (Collaborators.filter { t3 => t3.byRepository(t1.userName, t1.repositoryName) && diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index 2f7dbc2..0b40426 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -24,6 +24,7 @@ props.setProperty(Gravatar, settings.gravatar.toString) props.setProperty(Notification, settings.notification.toString) settings.activityLogLimit.foreach(x => props.setProperty(ActivityLogLimit, x.toString)) + props.setProperty(LimitVisibleRepositories, settings.limitVisibleRepositories.toString) props.setProperty(SshEnabled, settings.ssh.enabled.toString) settings.ssh.sshHost.foreach(x => props.setProperty(SshHost, x.trim)) settings.ssh.sshPort.foreach(x => props.setProperty(SshPort, x.toString)) @@ -99,6 +100,7 @@ getValue(props, Gravatar, false), getValue(props, Notification, false), getOptionValue[Int](props, ActivityLogLimit, None), + getValue(props, LimitVisibleRepositories, false), Ssh( getValue(props, SshEnabled, false), getOptionValue[String](props, SshHost, None).map(_.trim), @@ -180,6 +182,7 @@ gravatar: Boolean, notification: Boolean, activityLogLimit: Option[Int], + limitVisibleRepositories: Boolean, ssh: Ssh, useSMTP: Boolean, smtp: Option[Smtp], @@ -283,6 +286,7 @@ private val Gravatar = "gravatar" private val Notification = "notification" private val ActivityLogLimit = "activity_log_limit" + private val LimitVisibleRepositories = "limitVisibleRepositories" private val SshEnabled = "ssh" private val SshHost = "ssh.host" private val SshPort = "ssh.port" diff --git a/src/main/twirl/gitbucket/core/admin/settings_system.scala.html b/src/main/twirl/gitbucket/core/admin/settings_system.scala.html index 1c98de0..b90e16b 100644 --- a/src/main/twirl/gitbucket/core/admin/settings_system.scala.html +++ b/src/main/twirl/gitbucket/core/admin/settings_system.scala.html @@ -199,6 +199,21 @@ + + + +