diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index 9ef21f1..d397719 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -43,7 +43,7 @@ withoutPhysicalInfo = true, limit = context.settings.basicBehavior.limitVisibleRepositories ) - html.repos(getGroupNames(loginAccount.userName), repos, repos, isNewsFeedEnabled()) + html.repos(getGroupNames(loginAccount.userName), repos, repos, isNewsFeedEnabled) } }) @@ -132,7 +132,7 @@ withoutPhysicalInfo = true, limit = context.settings.basicBehavior.limitVisibleRepositories ), - isNewsFeedEnabled() + isNewsFeedEnabled ) } @@ -175,7 +175,7 @@ withoutPhysicalInfo = true, limit = context.settings.basicBehavior.limitVisibleRepositories ), - isNewsFeedEnabled() + isNewsFeedEnabled ) } diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index a3ccf4e..ebfab22 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -67,21 +67,25 @@ context.loginAccount .map { account => val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName) - if (!isNewsFeedEnabled()) { + if (!isNewsFeedEnabled) { redirect("/dashboard/repos") } else { + val repos = getVisibleRepositories( + Some(account), + None, + withoutPhysicalInfo = true, + limit = false + ) + gitbucket.core.html.index( - activities = getRecentActivitiesByOwners(visibleOwnerSet), - recentRepositories = getVisibleRepositories( - Some(account), - None, - withoutPhysicalInfo = true, - limit = context.settings.basicBehavior.limitVisibleRepositories - ), + activities = getRecentActivitiesByRepos(repos.map(x => (x.owner, x.name)).toSet), + recentRepositories = if (context.settings.basicBehavior.limitVisibleRepositories) { + repos.filter(x => x.owner == account.userName) + } else repos, showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken( account.userName ), - enableNewsFeed = isNewsFeedEnabled() + enableNewsFeed = isNewsFeedEnabled ) } } @@ -90,7 +94,7 @@ activities = getRecentPublicActivities(), recentRepositories = getVisibleRepositories(None, withoutPhysicalInfo = true), showBannerToCreatePersonalAccessToken = false, - enableNewsFeed = isNewsFeedEnabled() + enableNewsFeed = isNewsFeedEnabled ) } } @@ -167,16 +171,16 @@ } get("/signout") { - context.settings.oidc.map { oidc => + context.settings.oidc.foreach { oidc => session.get(Keys.Session.OidcSessionContext).foreach { case context: OidcSessionContext => val redirectURI = new URI(baseUrl) val authenticationRequest = createOIDLogoutRequest(oidc.issuer, oidc.clientID, redirectURI, context.token) - session.invalidate + session.invalidate() redirect(authenticationRequest.toURI.toString) } } - session.invalidate + session.invalidate() if (isDevFeatureEnabled(DevFeatures.KeepSession)) { deleteLoginAccountFromLocalFile() } @@ -228,7 +232,7 @@ org.json4s.jackson.Serialization.write( Map( "options" -> ( - getAllUsers(false) + getAllUsers(includeRemoved = false) .withFilter { t => (user, group) match { case (true, true) => true @@ -275,8 +279,8 @@ target.toLowerCase match { case "issues" => gitbucket.core.search.html.issues( - if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, false) else Nil, - false, + if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, pullRequest = false) else Nil, + pullRequest = false, query, page, repository @@ -284,8 +288,8 @@ case "pulls" => gitbucket.core.search.html.issues( - if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, true) else Nil, - true, + if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, pullRequest = true) else Nil, + pullRequest = true, query, page, repository @@ -320,15 +324,15 @@ ) val repositories = { - context.settings.basicBehavior.limitVisibleRepositories match { - case true => - getVisibleRepositories( - context.loginAccount, - None, - withoutPhysicalInfo = true, - limit = false - ) - case false => visibleRepositories + if (context.settings.basicBehavior.limitVisibleRepositories) { + getVisibleRepositories( + context.loginAccount, + None, + withoutPhysicalInfo = true, + limit = false + ) + } else { + visibleRepositories } }.filter { repository => repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0 diff --git a/src/main/scala/gitbucket/core/service/ActivityService.scala b/src/main/scala/gitbucket/core/service/ActivityService.scala index 58243d4..aac61d6 100644 --- a/src/main/scala/gitbucket/core/service/ActivityService.scala +++ b/src/main/scala/gitbucket/core/service/ActivityService.scala @@ -12,7 +12,6 @@ import gitbucket.core.controller.Context import gitbucket.core.util.ConfigUtil import org.apache.commons.io.input.ReversedLinesFileReader - import ActivityService._ import scala.collection.mutable.ListBuffer @@ -28,40 +27,52 @@ } } - def getActivitiesByUser(activityUserName: String, isPublic: Boolean)(implicit context: Context): List[Activity] = { - if (!isNewsFeedEnabled() || !ActivityLog.exists()) { - List.empty - } else { - val list = new ListBuffer[Activity] - Using.resource(new ReversedLinesFileReader(ActivityLog, StandardCharsets.UTF_8)) { reader => - var json: String = null - while (list.length < 50 && { json = reader.readLine(); json } != null) { - val activity = read[Activity](json) - if (activity.activityUserName == activityUserName) { - if (isPublic == false) { - list += activity - } else { - if (!getRepositoryInfoFromCache(activity.userName, activity.repositoryName).forall(_.isPrivate)) { - list += activity - } - } - } - } - } - list.toList + def getActivitiesByUser(activityUserName: String, publicOnly: Boolean)(implicit context: Context): List[Activity] = { + getActivities(includePublic = false) { activity => + if (activity.activityUserName == activityUserName) { + !publicOnly || isPublicActivity(activity) + } else false } } def getRecentPublicActivities()(implicit context: Context): List[Activity] = { - if (!isNewsFeedEnabled() || !ActivityLog.exists()) { + getActivities(includePublic = true) { _ => + false + } + } + + def getRecentActivitiesByRepos(repos: Set[(String, String)])(implicit context: Context): List[Activity] = { + getActivities(includePublic = true) { activity => + repos.exists { + case (userName, repositoryName) => + activity.userName == userName && activity.repositoryName == repositoryName + } + } + } + + private def getActivities( + includePublic: Boolean + )(filter: Activity => Boolean)(implicit context: Context): List[Activity] = { + if (!isNewsFeedEnabled || !ActivityLog.exists()) { List.empty } else { val list = new ListBuffer[Activity] - Using.resource(new ReversedLinesFileReader(ActivityLog, StandardCharsets.UTF_8)) { reader => + Using.resource( + ReversedLinesFileReader + .builder() + .setFile(ActivityLog) + .setCharset(StandardCharsets.UTF_8) + .get() + ) { reader => var json: String = null - while (list.length < 50 && { json = reader.readLine(); json } != null) { + while (list.length < 50 && { + json = reader.readLine(); + json + } != null) { val activity = read[Activity](json) - if (!getRepositoryInfoFromCache(activity.userName, activity.repositoryName).forall(_.isPrivate)) { + if (filter(activity)) { + list += activity + } else if (includePublic && isPublicActivity(activity)) { list += activity } } @@ -70,24 +81,8 @@ } } - def getRecentActivitiesByOwners(owners: Set[String])(implicit context: Context): List[Activity] = { - if (!isNewsFeedEnabled() || !ActivityLog.exists()) { - List.empty - } else { - val list = new ListBuffer[Activity] - Using.resource(new ReversedLinesFileReader(ActivityLog, StandardCharsets.UTF_8)) { reader => - var json: String = null - while (list.length < 50 && { json = reader.readLine(); json } != null) { - val activity = read[Activity](json) - if (owners.contains(activity.userName)) { - list += activity - } else if (!getRepositoryInfoFromCache(activity.userName, activity.repositoryName).forall(_.isPrivate)) { - list += activity - } - } - } - list.toList - } + private def isPublicActivity(activity: Activity)(implicit context: Context): Boolean = { + !getRepositoryInfoFromCache(activity.userName, activity.repositoryName).forall(_.isPrivate) } def recordActivity[T <: { def toActivity: Activity }](info: T): Unit = { @@ -97,6 +92,6 @@ } object ActivityService { - def isNewsFeedEnabled(): Boolean = + def isNewsFeedEnabled: Boolean = !ConfigUtil.getConfigValue[Boolean]("gitbucket.disableNewsFeed").getOrElse(false) }