mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-05 14:36:05 +02:00
Show activities of all visible repositories (#3336)
This commit is contained in:
@@ -43,7 +43,7 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
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 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
),
|
||||
isNewsFeedEnabled()
|
||||
isNewsFeedEnabled
|
||||
)
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
),
|
||||
isNewsFeedEnabled()
|
||||
isNewsFeedEnabled
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -67,21 +67,25 @@ trait IndexControllerBase extends ControllerBase {
|
||||
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 @@ trait IndexControllerBase extends ControllerBase {
|
||||
activities = getRecentPublicActivities(),
|
||||
recentRepositories = getVisibleRepositories(None, withoutPhysicalInfo = true),
|
||||
showBannerToCreatePersonalAccessToken = false,
|
||||
enableNewsFeed = isNewsFeedEnabled()
|
||||
enableNewsFeed = isNewsFeedEnabled
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -167,16 +171,16 @@ trait IndexControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
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 @@ trait IndexControllerBase extends ControllerBase {
|
||||
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 @@ trait IndexControllerBase extends ControllerBase {
|
||||
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 @@ trait IndexControllerBase extends ControllerBase {
|
||||
|
||||
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 @@ trait IndexControllerBase extends ControllerBase {
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
@@ -12,7 +12,6 @@ import java.nio.charset.StandardCharsets
|
||||
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 @@ trait ActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ trait ActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ trait ActivityService {
|
||||
}
|
||||
|
||||
object ActivityService {
|
||||
def isNewsFeedEnabled(): Boolean =
|
||||
def isNewsFeedEnabled: Boolean =
|
||||
!ConfigUtil.getConfigValue[Boolean]("gitbucket.disableNewsFeed").getOrElse(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user