mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
The method of RepositoryService was cleaned up.
This commit is contained in:
@@ -58,7 +58,7 @@ trait AccountControllerBase extends AccountManagementControllerBase with FlashMa
|
|||||||
case _ =>
|
case _ =>
|
||||||
_root_.account.html.repositories(account,
|
_root_.account.html.repositories(account,
|
||||||
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
||||||
getVisibleRepositories(userName, baseUrl, context.loginAccount.map(_.userName)))
|
getVisibleRepositories(context.loginAccount, baseUrl, Some(userName)))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
session.put(sessionKey, condition)
|
session.put(sessionKey, condition)
|
||||||
|
|
||||||
val repositories = getAccessibleRepositories(context.loginAccount, baseUrl)
|
val repositories = getUserRepositories(context.loginAccount.get.userName, baseUrl)
|
||||||
//
|
//
|
||||||
dashboard.html.issues(
|
dashboard.html.issues(
|
||||||
issues.html.listparts(Nil, 0, 0, 0, condition),
|
issues.html.listparts(Nil, 0, 0, 0, condition),
|
||||||
|
|||||||
@@ -16,19 +16,22 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
val loginAccount = context.loginAccount
|
val loginAccount = context.loginAccount
|
||||||
|
|
||||||
html.index(getRecentActivities(),
|
html.index(getRecentActivities(),
|
||||||
getAccessibleRepositories(loginAccount, baseUrl),
|
getVisibleRepositories(loginAccount, baseUrl),
|
||||||
loadSystemSettings(),
|
loadSystemSettings(),
|
||||||
loginAccount.map{ account => getRepositoryNamesOfUser(account.userName) }.getOrElse(Nil)
|
loginAccount.map{ account => getUserRepositories(account.userName, baseUrl) }.getOrElse(Nil)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON API for collaborator completion.
|
* JSON API for collaborator completion.
|
||||||
|
*
|
||||||
|
* TODO Move to other controller?
|
||||||
*/
|
*/
|
||||||
// TODO Move to other controller?
|
|
||||||
get("/_user/proposals")(usersOnly {
|
get("/_user/proposals")(usersOnly {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
org.json4s.jackson.Serialization.write(Map("options" -> getAllUsers.filter(!_.isGroupAccount).map(_.userName).toArray))
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map("options" -> getAllUsers.filter(!_.isGroupAccount).map(_.userName).toArray)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,39 +53,6 @@ trait RepositoryService { self: AccountService =>
|
|||||||
def getRepositoryNamesOfUser(userName: String): List[String] =
|
def getRepositoryNamesOfUser(userName: String): List[String] =
|
||||||
Query(Repositories) filter(_.userName is userName.bind) map (_.repositoryName) list
|
Query(Repositories) filter(_.userName is userName.bind) map (_.repositoryName) list
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of specified user's repositories information.
|
|
||||||
*
|
|
||||||
* @param userName the user name
|
|
||||||
* @param baseUrl the base url of this application
|
|
||||||
* @param loginUserName the logged in user name
|
|
||||||
* @return the list of repository information which is sorted in descending order of lastActivityDate.
|
|
||||||
*/
|
|
||||||
def getVisibleRepositories(userName: String, baseUrl: String, loginUserName: Option[String]): List[RepositoryInfo] = {
|
|
||||||
val q1 = Repositories
|
|
||||||
.filter { t => t.userName is userName.bind }
|
|
||||||
.map { r => r }
|
|
||||||
|
|
||||||
val q2 = Collaborators
|
|
||||||
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
|
||||||
.filter{ case (t1, t2) => t1.collaboratorName is userName.bind}
|
|
||||||
.map { case (t1, t2) => t2 }
|
|
||||||
|
|
||||||
def visibleFor(t: Repositories.type, loginUserName: Option[String]) = {
|
|
||||||
loginUserName match {
|
|
||||||
case Some(x) => (t.isPrivate is false.bind) || (
|
|
||||||
(t.isPrivate is true.bind) && ((t.userName is x.bind) || (Collaborators.filter { c =>
|
|
||||||
c.byRepository(t.userName, t.repositoryName) && (c.collaboratorName is x.bind)
|
|
||||||
}.exists)))
|
|
||||||
case None => (t.isPrivate is false.bind)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
q1.union(q2).filter(visibleFor(_, loginUserName)).sortBy(_.lastActivityDate desc).list map { repository =>
|
|
||||||
new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified repository information.
|
* Returns the specified repository information.
|
||||||
*
|
*
|
||||||
@@ -101,29 +68,46 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of accessible repositories information for the specified account user.
|
* Returns the list of specified user's repositories.
|
||||||
*
|
* It contains own repositories and collaboration repositories.
|
||||||
* @param account the account
|
|
||||||
* @param baseUrl the base url of this application
|
|
||||||
* @return the repository informations which is sorted in descending order of lastActivityDate.
|
|
||||||
*/
|
*/
|
||||||
def getAccessibleRepositories(account: Option[Account], baseUrl: String): List[RepositoryInfo] = {
|
def getUserRepositories(userName: String, baseUrl: String): List[RepositoryInfo] = {
|
||||||
|
Query(Repositories).filter { t1 =>
|
||||||
def newRepositoryInfo(repository: Repository): RepositoryInfo = {
|
(t1.userName is userName.bind) ||
|
||||||
|
(Query(Collaborators).filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName is userName.bind)} exists)
|
||||||
|
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
||||||
new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
|
new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(account match {
|
/**
|
||||||
|
* 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 baseUrl the base url of this application
|
||||||
|
* @param repositoryUserName the repository owner (if None then returns all repositories which are visible for logged in user)
|
||||||
|
* @return the repository information which is sorted in descending order of lastActivityDate.
|
||||||
|
*/
|
||||||
|
def getVisibleRepositories(loginAccount: Option[Account], baseUrl: String, repositoryUserName: Option[String] = None): List[RepositoryInfo] = {
|
||||||
|
|
||||||
|
val query = loginAccount match {
|
||||||
// for Administrators
|
// for Administrators
|
||||||
case Some(x) if(x.isAdmin) => Query(Repositories)
|
case Some(x) if(x.isAdmin) => Query(Repositories)
|
||||||
// for Normal Users
|
// for Normal Users
|
||||||
case Some(x) if(!x.isAdmin) =>
|
case Some(x) if(!x.isAdmin) =>
|
||||||
Query(Repositories) filter { t => (t.isPrivate is false.bind) ||
|
Query(Repositories) filter { t => (t.isPrivate is false.bind) ||
|
||||||
(Query(Collaborators).filter(t2 => t2.byRepository(t.userName, t.repositoryName) && (t2.collaboratorName is x.userName.bind)) exists)
|
(Query(Collaborators).filter { t2 => t2.byRepository(t.userName, t.repositoryName) && (t2.collaboratorName is x.userName.bind)} exists)
|
||||||
}
|
}
|
||||||
// for Guests
|
// for Guests
|
||||||
case None => Query(Repositories) filter(_.isPrivate is false.bind)
|
case None => Query(Repositories) filter(_.isPrivate is false.bind)
|
||||||
}).sortBy(_.lastActivityDate desc).list.map(newRepositoryInfo _)
|
}
|
||||||
|
|
||||||
|
val filtered = repositoryUserName.map { userName => query.filter(_.userName is userName.bind) } getOrElse query
|
||||||
|
|
||||||
|
filtered.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
||||||
|
new RepositoryInfo(JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl), repository)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@(activities: List[model.Activity],
|
@(activities: List[model.Activity],
|
||||||
repositories: List[service.RepositoryService.RepositoryInfo],
|
recentRepositories: List[service.RepositoryService.RepositoryInfo],
|
||||||
systemSettings: service.SystemSettingsService.SystemSettings,
|
systemSettings: service.SystemSettingsService.SystemSettings,
|
||||||
userRepositories: List[String])(implicit context: app.Context)
|
userRepositories: List[service.RepositoryService.RepositoryInfo])(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@main("GitBucket"){
|
@main("GitBucket"){
|
||||||
@@ -28,9 +28,15 @@
|
|||||||
<td>No repositories</td>
|
<td>No repositories</td>
|
||||||
</tr>
|
</tr>
|
||||||
} else {
|
} else {
|
||||||
@userRepositories.map { repositoryName =>
|
@userRepositories.map { repository =>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="@path/@loginAccount.get.userName/@repositoryName"><strong>@repositoryName</strong></a></td>
|
<td>
|
||||||
|
@if(repository.owner == loginAccount.get.userName){
|
||||||
|
<a href="@url(repository)"><strong>@repository.name</strong></a>
|
||||||
|
} else {
|
||||||
|
<a href="@url(repository)">@repository.owner/<strong>@repository.name</strong></a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,12 +49,12 @@
|
|||||||
Recent updated repositories
|
Recent updated repositories
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
@if(repositories.isEmpty){
|
@if(recentRepositories.isEmpty){
|
||||||
<tr>
|
<tr>
|
||||||
<td>No repositories</td>
|
<td>No repositories</td>
|
||||||
</tr>
|
</tr>
|
||||||
} else {
|
} else {
|
||||||
@repositories.map { repository =>
|
@recentRepositories.map { repository =>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a href="@url(repository)">@repository.owner/<strong>@repository.name</strong></a>
|
<a href="@url(repository)">@repository.owner/<strong>@repository.name</strong></a>
|
||||||
|
|||||||
Reference in New Issue
Block a user